Comparing version 0.13.5 to 0.14.0
# bunyan Changelog | ||
## bunyan 0.14.0 | ||
- [pull #41] Safe `JSON.stringify`ing of emitted log records to avoid blowing | ||
up on circular objects (by Isaac Schlueter). | ||
## bunyan 0.13.5 | ||
@@ -4,0 +10,0 @@ |
@@ -7,3 +7,3 @@ /* | ||
var VERSION = '0.13.5'; | ||
var VERSION = '0.14.0'; | ||
@@ -73,3 +73,3 @@ // Bunyan log format version. This becomes the 'v' field on all log records. | ||
case '%d': return Number(args[i++]); | ||
case '%j': return JSON.stringify(args[i++]); | ||
case '%j': return JSON.stringify(args[i++], safeCycles()); | ||
case '%%': return '%'; | ||
@@ -677,20 +677,3 @@ default: | ||
if (this.haveNonRawStreams) { | ||
try { | ||
str = JSON.stringify(obj) + '\n'; | ||
} catch (e) { | ||
var src = ((obj.src && obj.src.file) ? obj.src : getCaller3Info()); | ||
var emsg = format('bunyan: ERROR: could not stringify log record from ' | ||
+ '%s:%d: %s', src.file, src.line, e); | ||
var eobj = objCopy(rec[0]); | ||
eobj.bunyanMsg = emsg; | ||
eobj.msg = obj.msg; | ||
eobj.time = obj.time; | ||
eobj.v = LOG_VERSION; | ||
_warn(emsg, src.file, src.line); | ||
try { | ||
str = JSON.stringify(eobj) + '\n'; | ||
} catch (e2) { | ||
str = JSON.stringify({bunyanMsg: emsg}); | ||
} | ||
} | ||
str = JSON.stringify(obj, safeCycles()) + '\n'; | ||
} | ||
@@ -1028,2 +1011,17 @@ | ||
// A JSON stringifier that handles cycles safely. | ||
// Usage: JSON.stringify(obj, safeCycles()) | ||
function safeCycles() { | ||
var seen = []; | ||
return function(key, val) { | ||
if (!val || typeof val !== 'object') { | ||
return val; | ||
} | ||
if (seen.indexOf(val) !== -1) { | ||
return '[Circular]'; | ||
} | ||
seen.push(val); | ||
return val; | ||
}; | ||
} | ||
@@ -1030,0 +1028,0 @@ /** |
{ | ||
"name": "bunyan", | ||
"version": "0.13.5", | ||
"version": "0.14.0", | ||
"description": "a JSON Logger library for node.js services", | ||
@@ -5,0 +5,0 @@ "author": "Trent Mick <trentm@gmail.com> (http://trentm.com)", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
301406
49
2369