Comparing version 1.1.3 to 1.2.0
@@ -56,4 +56,11 @@ /* | ||
append(logger, meta, formatters, callback) { | ||
let data = Array.isArray(meta) ? meta.slice() : | ||
(typeof meta === 'object' ? merge({}, meta) : meta); | ||
let data; | ||
if (Array.isArray(meta)) | ||
data = meta.slice(); | ||
else if (typeof meta === 'object') { | ||
data = merge({}, meta); | ||
if (meta instanceof Error) | ||
Object.setPrototypeOf(data, Object.getPrototypeOf(meta)); | ||
} else data = meta; | ||
if (formatters) { | ||
@@ -60,0 +67,0 @@ formatters = Array.isArray(formatters) ? formatters : [formatters]; |
@@ -58,3 +58,3 @@ /* | ||
return output; | ||
if (!meta.timestamp) | ||
if (!output.timestamp) | ||
output.timestamp = new Date(); | ||
@@ -169,3 +169,3 @@ if (format && output.timestamp instanceof Date) | ||
function wordWrap(arg1) { | ||
const defaultWrap = wordwrap(parseInt(arg1, 10) || 80); | ||
const defaultWrap = arg1 !== 0 && wordwrap(parseInt(arg1, 10) || 80); | ||
let wrapFns; | ||
@@ -190,2 +190,3 @@ if (typeof arg1 === 'object') { | ||
return function wordWrap(meta, output) { | ||
if (arg1 === 0) return output; | ||
if (typeof output !== 'object') | ||
@@ -241,9 +242,10 @@ return defaultWrap(String(output)); | ||
* [timestamp][level][label]message | ||
* @param {{string: string|Null|Function}} [fields] | ||
* @param {Object} [options] | ||
* @param {{string: string|Null|Function}} [options.fields] | ||
* @param {Boolean} [options.strict=false] | ||
* @param {Boolean} [options.printErrorStack=false] | ||
* @return {Function} | ||
*/ | ||
function print(fields, options = {}) { | ||
fields = fields || { | ||
function print(options = {}) { | ||
const fields = options.fields || { | ||
timestamp: '[%s]', | ||
@@ -268,6 +270,12 @@ level: '[%s]', | ||
if (!options.strict) { | ||
const o = merge({}, output, {filter: (_, n) => !fields.hasOwnProperty(n)}); | ||
const o = merge({}, output, { | ||
filter: (_, n) => !(fields.hasOwnProperty(n) || | ||
(meta instanceof Error && n === 'stack')) | ||
}); | ||
if (Object.keys(o).length) | ||
result += '\n' + JSON.stringify(o); | ||
} | ||
if (options.printErrorStack && meta instanceof Error && meta.stack) { | ||
result += '\n' + meta.stack.substring(meta.stack.search(/\bat\b/g)); | ||
} | ||
return result.trim(); | ||
@@ -298,13 +306,25 @@ }; | ||
* | ||
* @param {Object} [options] | ||
* @param {String} [options.timestamp='YYYY-MM-DD HH:mm:ss'] "timestamp" formatter options | ||
* @param {Object} [options.colorize] "colorize" formatter options | ||
* @param {Array<String>} [options.upperCase=['level']] "upperCase" formatter options | ||
* @param {Object} [options.print] "print" formatter options | ||
* @param {*} [options.wordWrap=160] "wordWrap" formatter options | ||
* @param {*} [options.indent] "indent" formatter options | ||
* @return {Function} | ||
*/ | ||
function printConsole() { | ||
const funcs = [ | ||
timestamp('YYYY-MM-DD HH:mm:ss'), | ||
colorize(), | ||
upperCase('level'), | ||
print(), | ||
wordWrap(160), | ||
indent() | ||
]; | ||
function printConsole(options = {}) { | ||
const funcs = []; | ||
if (options.timestamp !== false) | ||
funcs.push(timestamp(options.timestamp || 'YYYY-MM-DD HH:mm:ss')); | ||
if (options.colorize !== false) | ||
funcs.push(colorize(options.colorize)); | ||
if (options.upperCase !== false) | ||
funcs.push(upperCase(...(options.upperCase || ['level']))); | ||
funcs.push(print(options.print)); | ||
if (options.wordWrap !== false) | ||
funcs.push(wordWrap(options.wordWrap || 160)); | ||
if (options.indent !== false) | ||
funcs.push(indent(options.indent)); | ||
return function printConsole(meta, output, ...args) { | ||
@@ -321,17 +341,13 @@ for (const fn of funcs) { | ||
* | ||
* @param {Object} [options] | ||
* @param {String} [options.timestamp='YYYY-MM-DD HH:mm:ss'] "timestamp" formatter options | ||
* @param {Array<String>} [options.upperCase=['level']] "upperCase" formatter options | ||
* @param {Object} [options.print] "print" formatter options | ||
* @param {*} [options.wordWrap=0] "wordWrap" formatter options | ||
* @param {*} [options.indent] "indent" formatter options | ||
* @return {Function} | ||
*/ | ||
function printFile() { | ||
const funcs = [ | ||
timestamp('YYYY-MM-DD HH:mm:ss'), | ||
upperCase('level'), | ||
print(), | ||
indent() | ||
]; | ||
return function printFile(meta, output, ...args) { | ||
for (const fn of funcs) { | ||
output = fn(meta, output, ...args); | ||
} | ||
return output; | ||
}; | ||
function printFile(options = {}) { | ||
options.colorize = false; | ||
return printConsole(options); | ||
} | ||
@@ -338,0 +354,0 @@ |
@@ -30,3 +30,3 @@ /* | ||
/** | ||
* @param {Object} [options] | ||
* @param {Object} [options] An object representing options | ||
* @param {Object} [options.defaultMeta] An object representing default meta-data of each log | ||
@@ -271,2 +271,4 @@ * @param {string} [options.label] A string representing default label value of each log | ||
merge(meta, message, {adjunct: true}); | ||
if (message instanceof Error) | ||
Object.setPrototypeOf(meta, Object.getPrototypeOf(message)); | ||
} else meta.message = util.format(message, ...args); | ||
@@ -273,0 +275,0 @@ if (this.defaultMeta) |
{ | ||
"name": "hixtory", | ||
"description": "Most flexible and fast logging library for NodeJS", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"author": "Panates Ltd.", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
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
58985
1466