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

后端 未结 9 624
清歌不尽
清歌不尽 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:34

    You can use built-in util and forever to achieve logging with timestap for your nodejs server. When you start a server add log output as part of the parameter:

    forever start -ao log/out.log server.js
    

    And then you can write util in your server.js

    server.js

    var util = require('util');
    util.log("something with timestamp");
    

    The output will look something like this to out.log file:

    out.log

    15 Mar 15:09:28 - something with timestamp
    

提交回复
热议问题