Comparing version 2.3.3 to 2.3.4
@@ -1,14 +0,2 @@ | ||
export declare type LogMethod = (msg: string | Error, meta?: object | Error) => ILogger; | ||
export interface ILogger { | ||
error: LogMethod; | ||
warn: LogMethod; | ||
info: LogMethod; | ||
debug: LogMethod; | ||
} | ||
export interface ILoggerOptions { | ||
logLevel?: string; | ||
wipeSensitiveData?: (meta: any) => any; | ||
} | ||
export declare const makeLogger: (options?: ILoggerOptions) => ILogger; | ||
export declare const wrapLogger: <T extends object = object>(logger: ILogger, baseMeta: T, getMeta?: (m: T) => object) => ILogger; | ||
export declare const wipeSensitiveData: (meta: any) => any; | ||
export { ILogger, ILoggerOptions, LogMethod, makeLogger, wipeSensitiveData } from './logger'; | ||
export { IWrappedLogger, WrappedLogMethod, wrapLogger } from './wrap'; |
145
lib/index.js
'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 path_1 = require('path') | ||
var triple_beam_1 = require('triple-beam') | ||
var util_1 = require('util') | ||
var winston_1 = require('winston') | ||
var environment = | ||
(typeof process !== 'undefined' && process.env.NODE_ENV && process.env.NODE_ENV.trim()) || | ||
'development' | ||
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 getMetaFromError(info) | ||
} | ||
if (info && info.message instanceof Error) { | ||
var err = info.message | ||
return __assign({}, 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({}, getMetaFromError(err), info) | ||
} | ||
return info | ||
}) | ||
var customFormat = isDevelopment | ||
? winston_1.format.combine( | ||
errorFormat(), | ||
winston_1.format.metadata(), | ||
winston_1.format.timestamp(), | ||
winston_1.format.colorize(), | ||
// format.prettyPrint() | ||
winston_1.format.printf(function(info) { | ||
var str = '[' + info.timestamp + '] ' + info.level + ': ' + info.message | ||
if (info.metadata && Object.keys(info.metadata).length > 0) { | ||
str += '\n' + util_1.inspect(info.metadata, false, null, true) | ||
} | ||
return str | ||
}) | ||
) | ||
: winston_1.format.combine( | ||
winston_1.format.timestamp(), | ||
errorFormat(), | ||
winston_1.format.logstash() | ||
) | ||
exports.makeLogger = function(options) { | ||
if (options === void 0) { | ||
options = defaultOptions | ||
} | ||
options.logLevel = options.logLevel ? options.logLevel : defaultOptions.logLevel | ||
options.wipeSensitiveData = options.wipeSensitiveData | ||
? options.wipeSensitiveData | ||
: defaultOptions.wipeSensitiveData | ||
var wipeSensitiveDataFormat = winston_1.format(function(meta) { | ||
return options.wipeSensitiveData(meta) | ||
}) | ||
return winston_1.createLogger({ | ||
level: options.logLevel, | ||
exitOnError: false, | ||
format: isDevelopment | ||
? customFormat | ||
: winston_1.format.combine(wipeSensitiveDataFormat(), customFormat), | ||
transports: [ | ||
new winston_1.transports.Console({ | ||
handleExceptions: true | ||
}) | ||
] | ||
}) | ||
} | ||
exports.wrapLogger = function(logger, baseMeta, getMeta) { | ||
var defaultMeta = getMeta | ||
? getMeta(baseMeta) | ||
: typeof baseMeta === 'object' | ||
? path_1.basename | ||
: { meta: baseMeta } | ||
var log = function(level, msg, meta) { | ||
if (msg instanceof Error && !meta) { | ||
var error = msg | ||
logger[level](error.message, __assign({}, getMetaFromError(error))) | ||
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)) | ||
) | ||
return wrappedLogger | ||
} | ||
if (meta && meta instanceof Error) { | ||
var error = meta | ||
logger[level](msg ? msg : error.message, __assign({}, getMetaFromError(error), meta)) | ||
return wrappedLogger | ||
} | ||
logger[level]( | ||
msg, | ||
meta ? __assign({}, defaultMeta, getMeta ? getMeta(meta) : meta) : defaultMeta | ||
) | ||
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) { | ||
return meta | ||
} | ||
var defaultOptions = { logLevel: 'debug', wipeSensitiveData: exports.wipeSensitiveData } | ||
var logger_1 = require('./logger') | ||
exports.makeLogger = logger_1.makeLogger | ||
exports.wipeSensitiveData = logger_1.wipeSensitiveData | ||
var wrap_1 = require('./wrap') | ||
exports.wrapLogger = wrap_1.wrapLogger | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "loggerism", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "Yet another logger abstraction", | ||
@@ -19,2 +19,3 @@ "main": "lib/index.js", | ||
"build:watch": "npm run build -- --watch", | ||
"test": "mocha -t 5000 --require ts-node/register --recursive \"src/**/*.spec.ts\"", | ||
"_clean": "rimraf lib", | ||
@@ -28,6 +29,11 @@ "validate": "npm ls" | ||
"devDependencies": { | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.12.18", | ||
"chai": "^4.2.0", | ||
"mocha": "^5.2.0", | ||
"precommit-hook": "^3.0.0", | ||
"prettier": "^1.15.3", | ||
"rimraf": "^2.6.3", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.12.1", | ||
@@ -34,0 +40,0 @@ "tslint-config-prettier": "^1.17.0", |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
14323
20
241
1
12
1