From 6259131a2a655305f42b90fb54bde951d0e651f0 Mon Sep 17 00:00:00 2001 From: Fkscorpion Date: Fri, 15 Sep 2017 17:26:41 +0200 Subject: [PATCH] Added options to alter pre- and suffixes for date stamps and labels --- README.md | 24 ++++++++++++++++++++++++ defaults.json | 4 ++++ main.js | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73750f1..c352285 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,10 @@ From version 2.0 the second parameter is an object with several options. As a ba * **options.label** {Boolean}
If true it will show the label (LOG | INFO | WARN | ERROR)
**Default**: true +* **options.labelPrefix** {String}
A custom prefix for the label.
For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)
**Default:** "[" + +* **options.labelSuffix** {String}
A custom suffix for the label.
For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)
**Default:** "]" + * **options.include** {Array}
An array containing the methods to include in the patch
**Default**: ["log", "info", "warn", "error", "dir", "assert"] * **options.exclude** {Array}
An array containing the methods to exclude in the patch
**Default**: [] \(none) @@ -56,7 +60,10 @@ From version 2.0 the second parameter is an object with several options. As a ba * **options.colors.label** {String/Array/Function}
**Default:** [] * **options.colors.metadata** {String/Array/Function}
**Default:** [] + +* **options.datePrefix** {String}
A custom prefix for the datestamp.
For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)
**Default:** "[" +* **options.dateSuffix** {String}
A custom suffix for the datestamp.
For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)
**Default:** "]" Note: To combine colors, bgColors and style, set them as an array like this: ... @@ -251,3 +258,20 @@ Result: Result: [18:10:30.875] [LOG] [14503936] Metadata applied. + + +### 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 diff --git a/defaults.json b/defaults.json index 87cca63..156ceca 100644 --- a/defaults.json +++ b/defaults.json @@ -5,7 +5,11 @@ "disable": [], "level": "log", "extend": {}, + "datePrefix": "[", + "dateSuffix": "]", "label": true, + "labelPrefix": "[", + "labelSuffix": "]", "colors": { "stamp":[], "label":[], diff --git a/main.js b/main.js index 0ab7180..ac3b93a 100644 --- a/main.js +++ b/main.js @@ -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