From e0809e14733e2e7caa56ea5ef9db7174911b64c3 Mon Sep 17 00:00:00 2001 From: Nuno Sousa Date: Wed, 22 Mar 2017 17:01:54 +0000 Subject: [PATCH 1/3] Add configurable `simple` option for child loggers --- src/index.js | 15 +++++++-------- test/index_test.js | 6 ++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 42bb7e1..0daa6fa 100755 --- a/src/index.js +++ b/src/index.js @@ -22,15 +22,14 @@ const level = bunyan.FATAL + 1; * Export `debugnyan`. */ -export default function debugnyan(name, options, config) { +export default function debugnyan(name, options, { + prefix = 'sub', + simple = true, + suffix = 'component' +} = {}) { const components = name.split(':'); const [root] = components; - config = Object.assign({ - prefix: 'sub', - suffix: 'component' - }, config); - if (!loggers[root]) { loggers[root] = bunyan.createLogger(Object.assign({}, options, { level, name: root })); } @@ -49,11 +48,11 @@ export default function debugnyan(name, options, config) { } options = Object.assign({}, options, { - [`${config.prefix.repeat(i - 1)}${config.suffix}`]: current, + [`${prefix.repeat(i - 1)}${suffix}`]: current, level }); - child = next.child(options, true); + child = next.child(options, simple); loggers[childName] = child; } diff --git a/test/index_test.js b/test/index_test.js index 434405e..c02f6e1 100755 --- a/test/index_test.js +++ b/test/index_test.js @@ -66,6 +66,12 @@ describe('debugnyan', () => { logger.fields.component.should.equal('bar'); }); + it('should accept the `simple` option', () => { + const logger = debugnyan('foo:biz', {}, { simple: false }); + + logger.should.not.have.property('_isSimpleChild'); + }); + it('should be on the debug level if `DEBUG` matches logger name', () => { debug.enable('foo:bar'); From 421f5aad8d79787aa14e5a15168f8f12fd513a3d Mon Sep 17 00:00:00 2001 From: Nuno Sousa Date: Wed, 22 Mar 2017 18:13:53 +0000 Subject: [PATCH 2/3] Update minimum node engine version to 6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index abef293..b6e00e8 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "should": "^11.1.0" }, "engines": { - "node": ">=4" + "node": ">=6" }, "nyc": { "include": [ From c0ba04f41e0b2f8e93dc7d7cb177360dad5bee3e Mon Sep 17 00:00:00 2001 From: Nuno Sousa Date: Wed, 22 Mar 2017 19:05:34 +0000 Subject: [PATCH 3/3] Add `simple` option documentation to README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 0155137..5190cb1 100755 --- a/README.md +++ b/README.md @@ -58,6 +58,12 @@ The `prefix` and `suffix` for each component is also customizable: var logger = require('debugnyan')('foo', {}, { suffix: 'module' }); ``` +When creating a _child_ logger you may also override the default `simple` behavior: + +```js +var logger = require('debugnyan')('foo:bar', {}, { simple: false }); +``` + ## Tests ```