intval3/lib/log/index.js

22 lines
623 B
JavaScript
Raw Normal View History

2017-09-25 02:27:53 +00:00
'use strict'
const winston = require('winston')
/**
* 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) {
const transports = [ new (winston.transports.Console)({ label : label }) ]
if (filename !== null) {
transports.push( new (winston.transports.File)({ label : label, filename : filename }) )
}
return new (winston.Logger)({
transports: transports
})
}
module.exports = createLog