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
|
|
|
}
|
2020-01-14 18:33:13 +00:00
|
|
|
return new (createLogger)({
|
2020-01-14 16:59:29 +00:00
|
|
|
format: format.combine(
|
2020-01-14 18:34:31 +00:00
|
|
|
format.label({ label : label || 'intval3' }),
|
2020-01-14 16:59:29 +00:00
|
|
|
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
|