Winston: how to rotate logs

前端 未结 5 1489
傲寒
傲寒 2020-12-08 04:13

How can I rotate logs when using Winston to handle logging for node.js. That is, how can I create a new file for each day the app runs?

    var logger = new          


        
5条回答
  •  无人及你
    2020-12-08 04:37

    According to the author of winston-filerotatedate it is a:

    File transport for winston that allows the log files to be rotated depending on size and time.

    The File transport accepts a filename via the 'filename' option and uses that file as the primary logging target. Should the file grow past 'maxsize' bytes then the current log file is renamed and a new primary log tile is created. The name of the renamed log file is formated as such 'basenameYYYYMMDD[a-z].bak'.

    Available options are:

    • level: Level of messages that this transport should log.
    • silent: Boolean flag indicating whether to suppress output.
    • timestamp: Boolean flag indicating if we should prepend output with timestamps (default true). If function is specified, its return value will be used instead of timestamps.
    • filename: The filename of the logfile to write output to.
    • dirname: The folder the logfile will be created in.
    • maxsize: Max size in bytes of the logfile, if the size is exceeded then a new file is created.
    • json: If true, messages will be logged as JSON (default true).

提交回复
热议问题