egg-logger
Advanced tools
Comparing version 3.3.1 to 3.4.0
@@ -22,2 +22,3 @@ 'use strict'; | ||
formatter: utils.consoleFormatter, | ||
maxCauseChainLength: this.options.maxCauseChainLength, | ||
})); | ||
@@ -30,2 +31,3 @@ } | ||
level: process.env.NODE_CONSOLE_LOGGRE_LEVEL || (process.env.NODE_ENV === 'production' ? 'INFO' : 'WARN'), | ||
maxCauseChainLength: 10, | ||
}; | ||
@@ -32,0 +34,0 @@ } |
@@ -55,2 +55,3 @@ const path = require('path'); | ||
dateISOFormat: this.options.dateISOFormat, | ||
maxCauseChainLength: this.options.maxCauseChainLength, | ||
}); | ||
@@ -70,2 +71,3 @@ this.set('file', fileTransport); | ||
dateISOFormat: this.options.dateISOFormat, | ||
maxCauseChainLength: this.options.maxCauseChainLength, | ||
}); | ||
@@ -83,2 +85,3 @@ this.set('jsonFile', jsonFileTransport); | ||
dateISOFormat: this.options.dateISOFormat, | ||
maxCauseChainLength: this.options.maxCauseChainLength, | ||
}); | ||
@@ -123,2 +126,3 @@ this.set('console', consoleTransport); | ||
jsonFile: '', | ||
maxCauseChainLength: 10, | ||
}; | ||
@@ -125,0 +129,0 @@ } |
@@ -27,2 +27,3 @@ 'use strict'; | ||
* - {AsyncLocalStorage} [localStorage] - AsyncLocalStorage instance to get current ctx | ||
* - {number} [maxCauseChainLength] | ||
*/ | ||
@@ -29,0 +30,0 @@ constructor(options) { |
@@ -115,2 +115,3 @@ 'use strict'; | ||
* - {Function} [paddingMessageFormatter] | ||
* - {number} [maxCauseChainLength] | ||
* @return {String|Buffer} formatted log string buffer | ||
@@ -138,3 +139,3 @@ */ | ||
if (args[0] instanceof Error) { | ||
message = formatError(args[0]); | ||
message = formatError(args[0], options); | ||
} else { | ||
@@ -194,7 +195,9 @@ message = util.format.apply(util, args); | ||
function formatError(err) { | ||
if (FrameworkBaseError.isFrameworkError(err)) { | ||
return FrameworkErrorFormater.format(err); | ||
} | ||
function errorToString(err, options, causeLength) { | ||
options = options || {}; | ||
const maxCauseChainLength = options.maxCauseChainLength || 10; | ||
causeLength = causeLength || 0; | ||
if (causeLength > maxCauseChainLength) return 'too long cause chain'; | ||
if (err.name === 'Error' && typeof err.code === 'string') { | ||
@@ -210,8 +213,29 @@ err.name = err.code + err.name; | ||
const errStack = err.stack || 'no_stack'; | ||
const errProperties = Object.keys(err).map(key => inspect(key, err[key])).join('\n'); | ||
return util.format('nodejs.%s: %s\n%s\n%s\npid: %s\nhostname: %s\n', | ||
if (err.cause) { | ||
const causeMsg = errorToString(err.cause, options, causeLength + 1); | ||
return util.format('nodejs.%s: %s\n%s\n%s\ncause:\n\n%s', | ||
err.name, | ||
err.message, | ||
errStack.substring(errStack.indexOf('\n') + 1), | ||
errProperties, | ||
causeMsg | ||
); | ||
} | ||
return util.format('nodejs.%s: %s\n%s\n%s', | ||
err.name, | ||
err.message, | ||
errStack.substring(errStack.indexOf('\n') + 1), | ||
errProperties, | ||
errProperties | ||
); | ||
} | ||
function formatError(err, options, causeLength) { | ||
if (FrameworkBaseError.isFrameworkError(err)) { | ||
return FrameworkErrorFormater.format(err); | ||
} | ||
const msg = errorToString(err, options, causeLength); | ||
return util.format('%s\npid: %s\nhostname: %s\n', | ||
msg, | ||
process.pid, | ||
@@ -218,0 +242,0 @@ hostname |
{ | ||
"name": "egg-logger", | ||
"version": "3.3.1", | ||
"version": "3.4.0", | ||
"description": "egg logger", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
55067
1373