Comparing version 2.1.0 to 2.2.0
@@ -13,2 +13,3 @@ export declare type LogMethod = (msg: string | Error, meta?: object | Error) => ILogger; | ||
export declare const makeLogger: (options?: ILoggerOptions) => ILogger; | ||
export declare const wrapLogger: <T extends object = object>(logger: ILogger, baseMeta: T) => ILogger; | ||
export declare const wipeSensitiveData: (meta: any) => any; |
@@ -24,12 +24,12 @@ 'use strict' | ||
var isDevelopment = environment === 'development' | ||
var getMetaFromError = function(e) { | ||
return __assign({ level: 'error', message: e.message, callstack: e.stack }, e) | ||
} | ||
var errorFormat = winston_1.format(function(info) { | ||
if (info instanceof Error) { | ||
return __assign({ message: info.message, callstack: info.stack }, info) | ||
return getMetaFromError(info) | ||
} | ||
if (info && info.message instanceof Error) { | ||
var err = info.message | ||
return __assign( | ||
{ message: info.message ? info.message : err.message, callstack: err.stack }, | ||
info | ||
) | ||
return __assign({}, getMetaFromError(err), info) | ||
} | ||
@@ -42,6 +42,3 @@ if ( | ||
var err = info[triple_beam_1.SPLAT][0] | ||
return __assign( | ||
{ message: info.message ? info.message : err.message, callstack: err.stack }, | ||
info | ||
) | ||
return __assign({}, getMetaFromError(err), info) | ||
} | ||
@@ -94,2 +91,43 @@ return info | ||
} | ||
exports.wrapLogger = function(logger, baseMeta) { | ||
var log = function(level, msg, meta) { | ||
if (msg instanceof Error && !meta) { | ||
var error = msg | ||
logger[level](error.message, __assign({}, getMetaFromError(error), baseMeta)) | ||
return wrappedLogger | ||
} | ||
// just a strange case | ||
if (msg instanceof Error && meta instanceof Error) { | ||
var error1 = msg | ||
var error2 = meta | ||
logger[level]( | ||
error1.message, | ||
__assign({}, getMetaFromError(error1), getMetaFromError(error2), baseMeta) | ||
) | ||
return wrappedLogger | ||
} | ||
if (meta && meta instanceof Error) { | ||
var error = meta | ||
logger[level](msg ? msg : error.message, __assign({}, getMetaFromError(error), baseMeta)) | ||
return wrappedLogger | ||
} | ||
logger[level](msg, meta ? __assign({}, meta, baseMeta) : baseMeta) | ||
return wrappedLogger | ||
} | ||
var wrappedLogger = { | ||
error: function(msg, meta) { | ||
return log('error', msg, meta) | ||
}, | ||
warn: function(msg, meta) { | ||
return log('warn', msg, meta) | ||
}, | ||
info: function(msg, meta) { | ||
return log('info', msg, meta) | ||
}, | ||
debug: function(msg, meta) { | ||
return log('debug', msg, meta) | ||
} | ||
} | ||
return wrappedLogger | ||
} | ||
exports.wipeSensitiveData = function(meta) { | ||
@@ -96,0 +134,0 @@ return meta |
{ | ||
"name": "loggerism", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Yet another logger abstraction", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
10105
148