From 8b2363e4876932c1d351ea499aadf167328b495e Mon Sep 17 00:00:00 2001 From: "Robert K. Bell" Date: Wed, 9 Aug 2017 16:27:28 +1000 Subject: [PATCH 1/3] fix: streams can be named as documented in --- types/bunyan/bunyan-tests.ts | 11 ++++++++++- types/bunyan/index.d.ts | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/types/bunyan/bunyan-tests.ts b/types/bunyan/bunyan-tests.ts index 657a59c3a8..cecd9e1bd5 100644 --- a/types/bunyan/bunyan-tests.ts +++ b/types/bunyan/bunyan-tests.ts @@ -29,7 +29,8 @@ let options: Logger.LoggerOptions = { streams: [{ type: 'stream', stream: process.stdout, - level: Logger.TRACE + level: Logger.TRACE, + name: 'foo' }, { type: 'file', path: '/tmp/test.log', @@ -69,6 +70,14 @@ log.addSerializers( } ); +let levels: number[] = log.levels(); +level = log.levels(0); +log.levels('foo'); + +log.levels(0, Logger.INFO); +log.levels(0, 'info'); +log.levels('foo', Logger.WARN); + let child = log.child({ name: 'child' }); child.reopenFileStreams(); log.addStream({ path: '/dev/null' }); diff --git a/types/bunyan/index.d.ts b/types/bunyan/index.d.ts index bc1dca298d..40623baf05 100644 --- a/types/bunyan/index.d.ts +++ b/types/bunyan/index.d.ts @@ -228,6 +228,7 @@ declare namespace Logger { closeOnExit?: boolean; period?: string; count?: number; + name?: string; } interface LoggerOptions { From d86388c8c9e994f2d7c4f08dd90a1945a4a276ed Mon Sep 17 00:00:00 2001 From: "Robert K. Bell" Date: Wed, 9 Aug 2017 17:46:36 +1000 Subject: [PATCH 2/3] =?UTF-8?q?fixes:=20premature=20close,=20file=20handle?= =?UTF-8?q?s,=20raw=20streams=20=E2=86=92=20stderr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - premature close: don't close the ringBuffer until we're done logging - file handles: calling child.reopenFileStreams() invalidates the fd - raw streams → stderr: app dies the moment bunyan pushes a raw log to stderr --- types/bunyan/bunyan-tests.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/types/bunyan/bunyan-tests.ts b/types/bunyan/bunyan-tests.ts index cecd9e1bd5..f18bb68a1d 100644 --- a/types/bunyan/bunyan-tests.ts +++ b/types/bunyan/bunyan-tests.ts @@ -5,9 +5,6 @@ let ringBufferOptions: Logger.RingBufferOptions = { }; let ringBuffer: Logger.RingBuffer = new Logger.RingBuffer(ringBufferOptions); ringBuffer.write("hello"); -ringBuffer.end(); -ringBuffer.destroy(); -ringBuffer.destroySoon(); let level: number; level = Logger.resolveLevel("trace"); @@ -46,7 +43,7 @@ let options: Logger.LoggerOptions = { }, { type: 'raw', stream: process.stderr, - level: Logger.WARN + level: Logger.FATAL + 1, // disabled, as stderr explodes when given raw streams }, { type: 'raw', stream: ringBuffer, @@ -78,16 +75,6 @@ log.levels(0, Logger.INFO); log.levels(0, 'info'); log.levels('foo', Logger.WARN); -let child = log.child({ name: 'child' }); -child.reopenFileStreams(); -log.addStream({ path: '/dev/null' }); -child.level(Logger.DEBUG); -child.level('debug'); -child.levels(0, Logger.ERROR); -child.levels(0, 'error'); -child.levels('stream1', Logger.FATAL); -child.levels('stream1', 'fatal'); - let buffer = new Buffer(0); let error = new Error(''); let object = { @@ -138,3 +125,17 @@ class MyLogger extends Logger { super(options); } } + +let child = log.child({ widget_type: 'wuzzle' }); +child.reopenFileStreams(); +log.addStream({ path: '/dev/null' }); +child.level(Logger.DEBUG); +child.level('debug'); +child.levels(0, Logger.ERROR); +child.levels(0, 'error'); +child.levels('foo', Logger.FATAL); +child.levels('foo', 'fatal'); + +ringBuffer.end(); +ringBuffer.destroy(); +ringBuffer.destroySoon(); From f5e563cc92a2300bc77c552d4a41161f9f156fd8 Mon Sep 17 00:00:00 2001 From: "Robert K. Bell" Date: Thu, 10 Aug 2017 11:13:48 +1000 Subject: [PATCH 3/3] fix: typo --- types/bunyan/bunyan-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/bunyan/bunyan-tests.ts b/types/bunyan/bunyan-tests.ts index dec2d4d525..48c9a6c809 100644 --- a/types/bunyan/bunyan-tests.ts +++ b/types/bunyan/bunyan-tests.ts @@ -121,7 +121,7 @@ recursive.whats['huh'] = recursive; JSON.stringify(recursive, Logger.safeCycles()); class MyLogger extends Logger { - constructor() {sales@powertec.com.au + constructor() { super(options); } }