日志.js:
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({ json: false, timestamp: true }),
new winston.transports.File({ filename: **Get from outside**, json: false })
],
});
module.exports = logger;
a.js,想要记录到它自己的日志文件
var logger = require('./log')('log_to_this_file'); <=== How can I pass a filename in?
logger.info('log to file');
b.js,也想记录到自己的日志文件
var logger = require('./log')('log_to_another_file'); <=== How can I pass a filename in?
logger.info('log to file');
我不知道如何编写 log.js 从外部获取文件名。
我怎么能这样?