2017-09-25 02:27:53 +00:00
|
|
|
'use strict'
|
|
|
|
|
2020-01-14 16:59:29 +00:00
|
|
|
const { transports, format, createLogger } = require('winston')
|
2017-09-25 02:27:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* createLog() - Returns a winston logger configured to service
|
|
|
|
*
|
|
|
|
* @param {string} label Label appearing on logger
|
|
|
|
* @param {string} filename Optional file to write log to
|
|
|
|
* @returns {object} Winston logger
|
|
|
|
*/
|
|
|
|
function createLog (label, filename = null) {
|
2020-01-14 16:59:29 +00:00
|
|
|
const transportsArr = [ new (transports.Console)({ label : label }) ]
|
2017-09-25 02:27:53 +00:00
|
|
|
if (filename !== null) {
|
2020-01-14 16:59:29 +00:00
|
|
|
transportsArr.push( new (transports.File)({ label : label, filename : filename }) )
|
2017-09-25 02:27:53 +00:00
|
|
|
}
|
2019-02-23 23:05:48 +00:00
|
|
|
return new (winston.createLogger)({
|
2020-01-14 16:59:29 +00:00
|
|
|
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
|
2017-09-25 02:27:53 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createLog
|