Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
OmgImAlexis authored Sep 28, 2017
2 parents 03b73ab + 6259131 commit 43a9e24
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ From version 2.0 the second parameter is an object with several options. As a ba

* **options.label** {Boolean}<br>If true it will show the label (LOG | INFO | WARN | ERROR)<br>**Default**: true

* **options.include** {Array}<br>An array containing the methods to include in the patch<br>**Default**: ['log', 'info', 'warn', 'error', 'dir', 'assert']
* **options.labelPrefix** {String}<br>A custom prefix for the label.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "["

* **options.labelSuffix** {String}<br>A custom suffix for the label.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "]"

* **options.include** {Array}<br>An array containing the methods to include in the patch<br>**Default**: ["log", "info", "warn", "error", "dir", "assert"]

* **options.exclude** {Array}<br>An array containing the methods to exclude in the patch<br>**Default**: [] \(none)

Expand All @@ -58,7 +62,10 @@ From version 2.0 the second parameter is an object with several options. As a ba
* **options.colors.label** {String/Array<String>/Function} <br>**Default:** []

* **options.colors.metadata** {String/Array<String>/Function} <br>**Default:** []

* **options.datePrefix** {String}<br>A custom prefix for the datestamp.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "["

* **options.dateSuffix** {String}<br>A custom suffix for the datestamp.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "]"
Note: To combine colors, bgColors and style, set them as an array like this:
```js
...
Expand Down Expand Up @@ -253,6 +260,22 @@ console.log('Metadata applied.');
```
Result:
```console
[18:10:30.875] [LOG] [14503936] Metadata applied.
```
[18:10:30.875] [LOG] [14503936] Metadata applied.
<a name="custom-pre-and-suffixes"></a>
### Custom prefix and suffix example
If you don't want to use the default brackets, you can also define your own custom pre- and suffixes like so:
require('console-stamp')(console, {
datePrefix: '####',
dateSuffix: '####',
labelPrefix: '{',
labelSuffix: '}'
});
console.log('Custom pre- and suffixed log');
Result:
####Fri Sep 15 2017 16:58:29#### {LOG} Custom pre- and suffixed log
4 changes: 4 additions & 0 deletions defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"disable": [],
"level": "log",
"extend": {},
"datePrefix": "[",
"dateSuffix": "]",
"label": true,
"labelPrefix": "[",
"labelSuffix": "]",
"colors": {
"stamp":[],
"label":[],
Expand Down
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ module.exports = function ( con, options, prefix_metadata ) {

con[f] = function () {

var prefix = colorTheme.stamp( "[" + dateFormat( pattern ) + "]" ) + " ";
var prefix = colorTheme.stamp( options.datePrefix + dateFormat( pattern ) + options.dateSuffix ) + " ";
var args = slice.call( arguments );

// Add label if flag is set
if ( options.label ) {
prefix += colorTheme.label( "[" + f.toUpperCase() + "]" ) + " ".substr( f.length );
prefix += colorTheme.label( options.labelPrefix + f.toUpperCase() + options.labelSuffix ) + " ".substr( f.length );
}

// Add metadata if any
Expand Down

0 comments on commit 43a9e24

Please sign in to comment.