natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.76k stars 585 forks source link

compressing bug. #124

Closed authendic closed 2 years ago

authendic commented 3 years ago
package main

import (
    "github.com/labstack/gommon/log"
    "github.com/natefinch/lumberjack"
)

func main() {
    Log := log.New("echo")
    w := &lumberjack.Logger{
        Filename:   "/tmp/example.log",
        MaxSize:    100, // M
        MaxBackups: 5,
        MaxAge:     30, // days
        Compress:   true,
    }
    defer w.Close()
    Log.SetOutput(w)
    Log.SetHeader("${time_rfc3339} ${level} ${message}")
    for i := 0; i < 2390000; i++ {
        Log.Infof("hello %s", "world")
    }
}

compressing goroutine will be interrupted when main routine exit. and the .gz file is semi-finished

natefinch commented 3 years ago

Hmm, yeah. That's hard to get around. We could have the Close() method interrupt saving to the compressed file and delete the half created file.... But if people don't call close or don't wait for it to finish... One goroutine can't stop the world - or the process - from ending.

Do you know if the process correctly picks up if you restart? A least-effort solution would be to try again when the process restarts and overwrite the half-created file.

natefinch commented 2 years ago

I think this is actually fixed now, BTW.