Comparing version 2.3.4 to 2.3.5
export declare const getMetaFromError: (e: Error) => { | ||
name: string; | ||
message: string; | ||
stack?: string; | ||
callstack: string; | ||
stack?: string | undefined; | ||
callstack: string | undefined; | ||
}; |
@@ -1,2 +0,1 @@ | ||
export declare const errorFormat: import("logform").FormatWrap; | ||
export declare const customFormat: import("logform").Format; |
'use strict' | ||
var __assign = | ||
(this && this.__assign) || | ||
function() { | ||
__assign = | ||
Object.assign || | ||
function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i] | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p] | ||
} | ||
return t | ||
} | ||
return __assign.apply(this, arguments) | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }) | ||
var triple_beam_1 = require('triple-beam') | ||
var winston_1 = require('winston') | ||
var env_1 = require('./env') | ||
var error_1 = require('./error') | ||
exports.errorFormat = winston_1.format(function(info) { | ||
if (info && info.message instanceof Error) { | ||
var err = info.message | ||
return __assign({}, error_1.getMetaFromError(err), info) | ||
} | ||
if ( | ||
info && | ||
Array.isArray(info[triple_beam_1.SPLAT]) && | ||
info[triple_beam_1.SPLAT][0] instanceof Error | ||
) { | ||
var err = info[triple_beam_1.SPLAT][0] | ||
return __assign({}, error_1.getMetaFromError(err), info) | ||
} | ||
return info | ||
}) | ||
exports.customFormat = env_1.isDevelopment | ||
? winston_1.format.combine( | ||
exports.errorFormat(), | ||
winston_1.format.metadata(), | ||
@@ -52,7 +20,3 @@ winston_1.format.timestamp(), | ||
) | ||
: winston_1.format.combine( | ||
winston_1.format.timestamp(), | ||
exports.errorFormat(), | ||
winston_1.format.logstash() | ||
) | ||
: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.logstash()) | ||
//# sourceMappingURL=format.js.map |
export { ILogger, ILoggerOptions, LogMethod, makeLogger, wipeSensitiveData } from './logger'; | ||
export { IWrappedLogger, WrappedLogMethod, wrapLogger } from './wrap'; | ||
export { wrapLogger } from './wrap'; | ||
export { ILogger as IWrappedLogger, LogMethod as WrappedLogMethod } from './logger'; |
@@ -1,7 +0,7 @@ | ||
export declare type LogMethod = (msg: string | Error, meta?: object | Error) => ILogger; | ||
export interface ILogger { | ||
error: LogMethod; | ||
warn: LogMethod; | ||
info: LogMethod; | ||
debug: LogMethod; | ||
export declare type LogMethod<T extends object = object> = (msg: string | Error, meta?: T | Error) => ILogger<T>; | ||
export interface ILogger<T extends object = object> { | ||
error: LogMethod<T>; | ||
warn: LogMethod<T>; | ||
info: LogMethod<T>; | ||
debug: LogMethod<T>; | ||
} | ||
@@ -12,3 +12,3 @@ export interface ILoggerOptions { | ||
} | ||
export declare const makeLogger: (options?: ILoggerOptions) => ILogger; | ||
export declare const makeLogger: <T extends object = object>(options?: ILoggerOptions) => ILogger<T>; | ||
export declare const wipeSensitiveData: (meta: any) => any; |
@@ -5,2 +5,3 @@ 'use strict' | ||
var env_1 = require('./env') | ||
var error_1 = require('./error') | ||
var format_1 = require('./format') | ||
@@ -12,9 +13,9 @@ exports.makeLogger = function(options) { | ||
options.logLevel = options.logLevel ? options.logLevel : defaultOptions.logLevel | ||
options.wipeSensitiveData = options.wipeSensitiveData | ||
var wipeSensitiveDataFun = options.wipeSensitiveData | ||
? options.wipeSensitiveData | ||
: defaultOptions.wipeSensitiveData | ||
var wipeSensitiveDataFormat = winston_1.format(function(meta) { | ||
return options.wipeSensitiveData(meta) | ||
return wipeSensitiveDataFun(meta) | ||
}) | ||
return winston_1.createLogger({ | ||
var logger = winston_1.createLogger({ | ||
level: options.logLevel, | ||
@@ -31,2 +32,27 @@ exitOnError: false, | ||
}) | ||
var wrappedLogger = { | ||
log: function(level, msg, meta) { | ||
if (msg instanceof Error) { | ||
logger[level](msg.name, error_1.getMetaFromError(msg)) | ||
} else if (meta instanceof Error) { | ||
logger[level](msg, error_1.getMetaFromError(meta)) | ||
} else { | ||
logger[level](msg, meta) | ||
} | ||
return wrappedLogger | ||
}, | ||
error: function(msg, meta) { | ||
return wrappedLogger.log('error', msg, meta) | ||
}, | ||
warn: function(msg, meta) { | ||
return wrappedLogger.log('warn', msg, meta) | ||
}, | ||
info: function(msg, meta) { | ||
return wrappedLogger.log('info', msg, meta) | ||
}, | ||
debug: function(msg, meta) { | ||
return wrappedLogger.log('debug', msg, meta) | ||
} | ||
} | ||
return wrappedLogger | ||
} | ||
@@ -33,0 +59,0 @@ exports.wipeSensitiveData = function(meta) { |
@@ -1,9 +0,2 @@ | ||
import { ILogger } from '.'; | ||
export declare type WrappedLogMethod<T extends object = object> = (msg: string | Error, meta?: T | Error) => IWrappedLogger<T>; | ||
export interface IWrappedLogger<T extends object = object> extends ILogger { | ||
error: WrappedLogMethod<T>; | ||
warn: WrappedLogMethod<T>; | ||
info: WrappedLogMethod<T>; | ||
debug: WrappedLogMethod<T>; | ||
} | ||
export declare const wrapLogger: <T extends object = object>(logger: ILogger | IWrappedLogger<T>, baseMeta: T, convertMeta?: (m: T) => object) => IWrappedLogger<T>; | ||
import { ILogger } from './logger'; | ||
export declare const wrapLogger: <TBase extends object = object, T extends object = object>(logger: ILogger<TBase>, baseMeta: Partial<T>, convertMeta?: ((m: Partial<T>) => TBase) | undefined) => ILogger<TBase & Partial<T>>; |
@@ -21,44 +21,12 @@ 'use strict' | ||
var log = function(level, msg, meta) { | ||
if (msg instanceof Error && !meta) { | ||
var error = msg | ||
logger[level](error.message, __assign({}, defaultMeta, error_1.getMetaFromError(error))) | ||
if (msg instanceof Error) { | ||
logger[level](msg.message, __assign({}, defaultMeta, error_1.getMetaFromError(msg))) | ||
} else if (meta instanceof Error) { | ||
logger[level](msg, __assign({}, defaultMeta, error_1.getMetaFromError(meta))) | ||
return wrappedLogger | ||
} else if (meta) { | ||
logger[level](msg, __assign({}, defaultMeta, convertMeta ? convertMeta(meta) : meta)) | ||
} else { | ||
logger[level](msg, defaultMeta) | ||
} | ||
// just a strange case | ||
if (msg instanceof Error && meta instanceof Error) { | ||
var error1 = msg | ||
var error2 = meta | ||
logger[level]( | ||
error1.message, | ||
__assign( | ||
{}, | ||
defaultMeta, | ||
error_1.getMetaFromError(error1), | ||
error_1.getMetaFromError(error2) | ||
) | ||
) | ||
return wrappedLogger | ||
} | ||
if (meta && meta instanceof Error) { | ||
var error = meta | ||
logger[level]( | ||
msg ? msg : error.message, | ||
__assign({}, defaultMeta, error_1.getMetaFromError(error)) | ||
) | ||
return wrappedLogger | ||
} | ||
logger[level]( | ||
msg, | ||
meta | ||
? __assign( | ||
{}, | ||
defaultMeta, | ||
meta instanceof Error | ||
? error_1.getMetaFromError(meta) | ||
: convertMeta | ||
? convertMeta(meta) | ||
: meta | ||
) | ||
: defaultMeta | ||
) | ||
return wrappedLogger | ||
@@ -65,0 +33,0 @@ } |
{ | ||
"name": "loggerism", | ||
"version": "2.3.4", | ||
"version": "2.3.5", | ||
"description": "Yet another logger abstraction", | ||
@@ -34,3 +34,3 @@ "main": "lib/index.js", | ||
"precommit-hook": "^3.0.0", | ||
"prettier": "^1.15.3", | ||
"prettier": "^1.16.1", | ||
"rimraf": "^2.6.3", | ||
@@ -40,8 +40,4 @@ "ts-node": "^7.0.1", | ||
"tslint-config-prettier": "^1.17.0", | ||
"typescript": "^3.2.2" | ||
"typescript": "^3.2.4" | ||
}, | ||
"peerDependencies": { | ||
"logform": "1.10.0", | ||
"triple-beam": "^1.3.0" | ||
}, | ||
"files": [ | ||
@@ -48,0 +44,0 @@ "lib" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28396
1
23
422