本人主要是写python的,公司突然需要我写node代码,现在发现一个排错问题,我同事之前用winston的时候,并没有打上时间戳,感觉调试起来比较麻烦,有什么方法可以在winston日志中添加时间戳吗?
回复 (9)
I
前段时间刚用了winston,加上timestamp即可
R
引用 im-here前段时间刚用了winston,加上`timestamp`即可
@imhered 有对应的教程链接吗?或者例子代码,因为看到一些方法还是挺复杂的,但是我只是为了方便调试才去做这个
I
引用 ray1888@imhered 有对应的教程链接吗?或者例子代码,因为看到一些方法还是挺复杂的,但是我只是为了方便调试才去做这个
transports: [
new (winston.transports.File)({
name: 'error',
filename: '/logs/crash.log',
level: 'error',
handleExceptions: true,
timestamp: () => moment().format('YYYY-MM-DD HH:mm:ss.SSS'),
humanReadableUnhandledException: true,
json: false,
colorize: true
})
]
这里的 timestamp 就是在log加入时间
R
好的,谢谢
D
引用 im-here@ray1888 ` 这里的 timestamp 就是在log加入时间
@imhered 请问下 可以按天分割日志嘛 winston
I
引用 datura-lj@imhered 请问下 可以按天分割日志嘛 winston
@datura-lj 可以的,自己写或者用第三方的库,第三方的话用winston-daily-rotate-file
D
引用 im-here@datura lj 可以的,自己写或者用第三方的库,第三方的话用winston daily rotate file
@imhered 谢谢,这个在 PM 2 cluster 模式下 正常吗
I
引用 datura-lj@imhered 谢谢,这个在 PM 2 cluster 模式下 正常吗
@datura-lj 没在 PM 2 cluster 模式下使用过这个
D
引用 im-here@datura lj 没在 PM 2 cluster 模式下使用过这个
@imhered 刚试了下,还是不输出日志文件
参与回复
登录后即可参与回复。登录