natefinch / lumberjack

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

zap-logger with lumberjack not working #185

Open jingc1413 opened 1 year ago

jingc1413 commented 1 year ago

I test in windows environment Integration tests for zap logger and lumberjack-rolling find not working, no rotation

func WithFileRotationP(file string) Option {
    dir := filepath.Dir(file)
    if err := os.MkdirAll(dir, 0766); err != nil {
        panic(err)
    }

    return func(opt *option) {
        opt.file = &lumberjack.Logger{ 
            Filename:   file, 
            MaxSize:    1,    
            MaxBackups: 300,  
            MaxAge:     30,  
            LocalTime:  true, 
            Compress:   true,
        }
    }
}

output error:

2023-03-30 17:24:24.6335537 +0800 CST m=+3.052071301 write error: can't rename log file: rename ./test.log test-2023-03-30T17-24-24.633.log: The process cannot access the file because it is being used by another process.

When I switch to linux environment, it works fine

steve-white commented 6 months ago

I suspect this bug is because on Linux it's fine to rename a file even if it's in use, but not on Windows.