A simple wrapper for winston, which provides basic timestamp/label/level/color config
nodejs version: >=8.9.1
# install dependencies
npm install --save winston-simple-wrapper
const { Factory } = require('winston-simple-wrapper')
const logger = new Factory({
transports: [{
type: 'console',
level: 'info'
}, {
type: 'file',
level: 'info',
filename: './logs/output.log'
}]
})
const obj = {a: 1}
logger.error('error' + obj, ['test', 'error'])
logger.warn(1)
logger.info(null, 'network')
logger.debug({
a: 3,
b: /123/,
c: () => console.log(1),
d: {
a: [1, 'meme', obj],
c: 3
}
}, 'obj')
try {
console.log(obj.a.b.c)
} catch (e) {
logger.error(e, ['catch', 'error', 'obj'])
}
2018-1-30 19:57:24 error: [test,error] "error[object Object]"
2018-1-30 19:57:24 warn: [common] 1
2018-1-30 19:57:24 info: [network] null
2018-1-30 19:57:24 debug: [obj] {
"a": 3,
"b": "/123/",
"c": "[Function] c",
"d": {
"a": [
1,
"meme",
{
"a": 1
}
],
"c": 3
}
}
2018-1-30 19:57:24 error: [catch,error,obj]
Error message: Cannot read property 'c' of undefined
Error code: undefined
Error stack: TypeError: Cannot read property 'c' of undefined
at Object.<anonymous> (/home/sixestates/test/log.js:25:23)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
-
config
(optional, Object) - If not provided, defaults to basic config-
config.transports
(optional, Array) - contains different transport config object, the default value is console config-
console transport config
(optional, Object) - console config object of config.transports-
type
(necessary, String) - console/file -
level
(optional, String) - The default value is 'info'
-
-
file transport config
(optional, Object) - file config object of config.transports-
type
(necessary, String) - console/file -
level
(optional, String) - The default value is 'info' -
filename
(optional, String) -
datePattern
(optional, String) - The default value is 'YYYY-MM-DD', please refer to winston-daily-rotate-file -
maxSize
(optional, String) - The default value is '200m', please refer to winston-daily-rotate-file -
maxFiles
(optional, Number) - The default file is 30, please refer to winston-daily-rotate-file
-
-
-
-
message
(String) - message info. -
labels
(optional, String/Array) - message label, convenient to filter in log, common will be used if not provided
-
message
(String) - message info. -
labels
(optional, String/Array) - message label, convenient to filter in log, common will be used if not provided
-
message
(String) - message info. -
labels
(optional, String/Array) - message label, convenient to filter in log, common will be used if not provided
-
message
(String) - message info. -
labels
(optional, String/Array) - message label, convenient to filter in log, common will be used if not provided
-
message
(String) - message info. -
labels
(optional, String/Array) - message label, convenient to filter in log, common will be used if not provided
-
message
(String) - message info. -
labels
(optional, String/Array) - message label, convenient to filter in log, common will be used if not provided