lumberjack icon indicating copy to clipboard operation
lumberjack copied to clipboard

zap-logger with lumberjack not working

Open jingc1413 opened this issue 1 year ago • 1 comments

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

jingc1413 avatar Mar 30 '23 09:03 jingc1413

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.

steve-white avatar Mar 21 '24 11:03 steve-white