dok*_*han 7 javascript node.js express pinojs
我创建了这个简单的函数来记录代码中发生的任何情况:
const pino = require('pino')
module.exports = pino({
transport: {
target: "pino-pretty",
options: {
translateTime: "SYS:dd-mm-yyyy HH:MM:ss",
ignore: "pid,hostname",
destination: './logs/logs.txt'
}
}
})
Run Code Online (Sandbox Code Playgroud)
的问题destination。如果此选项是,pino将把所有内容写入文件中,而不是控制台中,如果没有,将在控制台中打印,但不打印在文件中。我想在控制台中打印并同时写入日志。
这可能吗?
小智 7
I know this is old, but I thought I'd drop this in as I'm working with it right now.
transport: {
targets: [
{
level: 'info',
target: 'pino-pretty',
options: {}
},
{
level: 'trace',
target: 'pino/file',
options: { destination: './pino-logger.log' }
}
],
},
Run Code Online (Sandbox Code Playgroud)
You can set up multiple targets and distinguish which will receive what levels and options. Hope that helps anyone still looking around.
| 归档时间: |
|
| 查看次数: |
4782 次 |
| 最近记录: |