From 9eccd8de0ea3048cc3fcf34e8877757355f42e6f Mon Sep 17 00:00:00 2001 From: acarstoiu Date: Thu, 11 Dec 2014 16:21:53 +0200 Subject: [PATCH 1/3] Standard err serializer: better support for caused errors I've made some tiny changes that make the default `err` serializer support a wider range of caused errors, namely also those that have a `cause` property. I have also changed a little bit the connecting message in the full error stack to integrate better with the default stack trace formatter. Thank you. --- lib/bunyan.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/bunyan.js b/lib/bunyan.js index 2c997ae5..5ef7756b 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -985,7 +985,7 @@ Logger.stdSerializers.res = function res(res) { /* * This function dumps long stack traces for exceptions having a cause() - * method. The error classes from + * method or a cause property. The error classes from * [verror](https://github.com/davepacheco/node-verror) and * [restify v2.0](https://github.com/mcavage/node-restify) are examples. * @@ -995,10 +995,16 @@ Logger.stdSerializers.res = function res(res) { function getFullErrorStack(ex) { var ret = ex.stack || ex.toString(); - if (ex.cause && typeof (ex.cause) === 'function') { - var cex = ex.cause(); + if (ex.cause) { + var cex; + if (typeof (ex.cause) === 'function') { + cex = ex.cause(); + } + if (typeof (ex.cause) === 'object') { + cex = ex.cause; + } if (cex) { - ret += '\nCaused by: ' + getFullErrorStack(cex); + ret += '\ncaused by ' + getFullErrorStack(cex); } } return (ret); From ccf045d6aa7c4747dd05f46d44f565e26cdaa513 Mon Sep 17 00:00:00 2001 From: acarstoiu Date: Wed, 25 Feb 2015 19:43:51 +0200 Subject: [PATCH 2/3] Tiny improvement. --- lib/bunyan.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/bunyan.js b/lib/bunyan.js index 5ef7756b..c8ef154c 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -995,17 +995,16 @@ Logger.stdSerializers.res = function res(res) { function getFullErrorStack(ex) { var ret = ex.stack || ex.toString(); - if (ex.cause) { - var cex; - if (typeof (ex.cause) === 'function') { + var cex; + switch (typeof ex.cause) { + case 'function': cex = ex.cause(); - } - if (typeof (ex.cause) === 'object') { + break; + case 'object': cex = ex.cause; - } - if (cex) { - ret += '\ncaused by ' + getFullErrorStack(cex); - } + } + if (cex) { + ret += '\ncaused by ' + getFullErrorStack(cex); } return (ret); } From 8ba3c79ab0e4ad8c1b84ae14a958252067360e66 Mon Sep 17 00:00:00 2001 From: acarstoiu Date: Thu, 5 Mar 2015 19:38:40 +0200 Subject: [PATCH 3/3] A child logger should have the opportunity to use a different name. --- lib/bunyan.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/bunyan.js b/lib/bunyan.js index c8ef154c..6b432391 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -272,15 +272,8 @@ function Logger(options, _childOptions, _childSimple) { if (!options) { throw new TypeError('options (object) is required'); } - if (!parent) { - if (!options.name) { - throw new TypeError('options.name (string) is required'); - } - } else { - if (options.name) { - throw new TypeError( - 'invalid options.name: child cannot set logger name'); - } + if (!parent && !options.name) { + throw new TypeError('options.name (string) is required'); } if (options.stream && options.streams) { throw new TypeError('cannot mix "streams" and "stream" options');