natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.81k stars 593 forks source link

Rotate on start? #173

Closed djarbz closed 11 months ago

djarbz commented 1 year ago

Is it possible to rotate at the start of the application?

pgalbavy-itrs commented 11 months ago

Perhaps boring, but this is what I do (with zerolog as the upper layer):

        var out io.WriteCloser
    out = os.Stderr
        if logfile != "" {
        l := &lumberjack.Logger{
            Filename:   logfile,
            MaxBackups: globalConf.GetInt("server.logs.backups"),
            MaxSize:    globalConf.GetInt("server.logs.size"),
            MaxAge:     globalConf.GetInt("server.logs.age"),
            Compress:   globalConf.GetBool("server.logs.compress"),
        }
        if globalConf.GetBool("server.logs.rotate-at-start") {
            l.Rotate()
        }
        out = l
    }
djarbz commented 11 months ago

I like it, I will proceed with that method, simple enough and no need modify anything in the library.