New log format that is more readable, not json. Has timestamps.
This commit is contained in:
parent
94e6982adb
commit
1cf581602b
|
@ -1,6 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const winston = require('winston')
|
const { transports, format, createLogger } = require('winston')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* createLog() - Returns a winston logger configured to service
|
* createLog() - Returns a winston logger configured to service
|
||||||
|
@ -10,12 +10,19 @@ const winston = require('winston')
|
||||||
* @returns {object} Winston logger
|
* @returns {object} Winston logger
|
||||||
*/
|
*/
|
||||||
function createLog (label, filename = null) {
|
function createLog (label, filename = null) {
|
||||||
const transports = [ new (winston.transports.Console)({ label : label }) ]
|
const transportsArr = [ new (transports.Console)({ label : label }) ]
|
||||||
if (filename !== null) {
|
if (filename !== null) {
|
||||||
transports.push( new (winston.transports.File)({ label : label, filename : filename }) )
|
transportsArr.push( new (transports.File)({ label : label, filename : filename }) )
|
||||||
}
|
}
|
||||||
return new (winston.createLogger)({
|
return new (winston.createLogger)({
|
||||||
transports: transports
|
format: format.combine(
|
||||||
|
format.label({ label : arg.label || 'intval3' }),
|
||||||
|
format.timestamp({
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss'
|
||||||
|
}),
|
||||||
|
format.printf((info) => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`+(info.splat!==undefined?`${info.splat}`:" "))
|
||||||
|
),
|
||||||
|
transports: transportsArr
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue