egg-logger
Advanced tools
Comparing version 1.7.0 to 1.7.1
1.7.1 / 2018-07-09 | ||
================== | ||
**fixes** | ||
* [[`b80560b`](http://github.com/eggjs/egg-logger/commit/b80560b1906ff667db24345029ac8951622ebe59)] - fix: use circular-json to format error properties (#26) (Yiyu He <<dead_horse@qq.com>>) | ||
1.7.0 / 2018-06-21 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -9,2 +9,3 @@ 'use strict'; | ||
const levels = require('./level'); | ||
const circularJSON = require('circular-json'); | ||
@@ -158,3 +159,36 @@ const hostname = os.hostname(); | ||
function inspect(key, value) { | ||
return `${key}: ${util.inspect(value, { breakLength: Infinity })}`; | ||
return `${key}: ${formatObject(value)}`; | ||
} | ||
function formatString(str) { | ||
if (str.length > 10000) { | ||
return `${str.substr(0, 10000)}...(${str.length})`; | ||
} | ||
return str; | ||
} | ||
function formatBuffer(buf) { | ||
const tail = buf.data.length > 50 ? ` ...(${buf.data.length}) ` : ''; | ||
const bufStr = buf.data.slice(0, 50).map(i => { | ||
i = i.toString(16); | ||
if (i.length === 1) i = `0${i}`; | ||
return i; | ||
}).join(' '); | ||
return `<Buffer ${bufStr}${tail}>`; | ||
} | ||
function formatObject(obj) { | ||
try { | ||
return circularJSON.stringify(obj, (key, v) => { | ||
if (typeof v === 'string') return formatString(v); | ||
if (v && v.type === 'Buffer' && Array.isArray(v.data)) { | ||
return formatBuffer(v); | ||
} | ||
if (v instanceof RegExp) return util.inspect(v); | ||
return v; | ||
}); | ||
} catch (_) { | ||
/* istanbul ignore next */ | ||
return String(obj); | ||
} | ||
} |
{ | ||
"name": "egg-logger", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "egg logger", | ||
@@ -8,2 +8,3 @@ "main": "index.js", | ||
"chalk": "^1.1.3", | ||
"circular-json": "^0.5.4", | ||
"debug": "^2.6.2", | ||
@@ -10,0 +11,0 @@ "depd": "^1.1.0", |
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
43224
1154
7
+ Addedcircular-json@^0.5.4
+ Addedcircular-json@0.5.9(transitive)