Categorygithub.com/kyungjoonkim/zap-time-file-logger

# Packages

No description provided by the author

# README

zap-time-file-logger

I created this because it seemed like there was no option to generate log files by date when using the zap Logger. The usage is very simple, as shown below.

The zap Logger library must be installed and in use. The explanation assumes that the installation has already been completed.

go get github.com/kyungjoonkim/[email protected]
zapcore.AddSync(&rolling.DateFileLogger{
    PrefixFileName:     "xxxx/you-log-file-name",
    TimeFormat:         "2006-01-02",
    LogRetentionPeriod: 10 * 24 * time.Hour,
    MaxSize:            300,
})

When used as above, log files will be generated by date in the form of xxxx/you-log-file-name-2020-01-01-0.log.

PrefixFileName:

  • Specifies the path and prefix of the log file name. (xxxx/you-log-file-name)

TimeFormat:

  • Specifies the format in which the date will be displayed in the log file name. Uses the time format defined in the time package.

LogRetentionPeriod:

  • The log file deletion period. 10 * 24 * time.Hour (10 days). Files older than 10 days from the creation date will be deleted.

MaxSize:

  • The maximum size of the log file. A new file will be created if it exceeds 300MB.