How can I add timestamp to logs using Node.js library Winston?

后端 未结 9 720
清歌不尽
清歌不尽 2021-01-31 12:55

I want to add timestamp to logs. What is the best way to achieve this?

9条回答
  •  轮回少年
    2021-01-31 13:32

    Although I'm not aware of winston, this is a suggestion. I use log4js for logging & my logs by default look like this

    [2012-04-23 16:36:02.965] [INFO] Development - Node Application is running on port 8090
    [2012-04-23 16:36:02.966] [FATAL] Development - Connection Terminated to  '127.0.0.1' '6379'
    

    Development is the environment of my node process & [INFO|FATAL] is log level

    Maintaining different profiles for logging is possible in log4js. I have Development & Production profiles. Also there are logger types like rolling file appender, console appender, etc. As a addon your log files will be colorful based on the log level [Trace, Info, Debug, Error, Fatal] ;)

    log4js will override your console.log It is a configurable parameter now in 0.5+

提交回复
热议问题