A simple log file format

后端 未结 8 1110
广开言路
广开言路 2021-01-12 07:16

I\'m not sure if it was asked, but I couldn\'t find anything like this.

My program uses a simple .txt file for log purposes, It just creates/opens a file and appends

8条回答
  •  悲哀的现实
    2021-01-12 07:49

    A fairly standard way to deal with logging from an application into a plain text file is to:

    • split the logs into different program functional areas.
    • rotate the logs on a daily/weekly basis (i.e. split the log on a size or date basis)
      • so the current log is "mylog.log" or whatever, and yesterday's was "mylog.log.1" or "mylog.ddmmyyyy.log"

    This keeps the size of the active log manageable. And then you can just have expiry rules so that old logs get thrown away on a regular basis.

    In addition it would be a good idea to have different log levels for your application (info/warning/error/fatal) so that you're not logging more than is necessary.

提交回复
热议问题