coo*_*koo 7 javascript formatting logging node.js winston
我需要为每个传输使用不同类型的格式化程序.
例
logger = new (winston.Logger)({
transports: [
new (winston.transports.LogstashUDP)({
// some config here. Do noting on formatting
}),
new (winston.transports.Mail)({
// do formatting one way
}),
new (winston.transports.File)({
// write to file as json (maybe format it here)
}),
new (winston.transports.Console)({
// do another formatting
})
]
});
Run Code Online (Sandbox Code Playgroud)
正如我从winston transports 文档中看到的那样,只有Console支持自定义格式化程序.
我正在使用winston-mailer模块邮件和winston-logstash-upd
有没有办法用Winston解决这个问题?或者也许如何围绕其中一个模块创建包装以支持格式化?
const logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: 'error.log', level: 'error',
format: winston.format.simple(),
}),
new winston.transports.File({
filename: 'combined.log', level: 'debug',
format: winston.format.printf(info => `${new Date().toISOString(), ${info.message}`),
}),
],
});
logger.error('prefixed by the timestamp only in `combined.log`');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
697 次 |
| 最近记录: |