gf icon indicating copy to clipboard operation
gf copied to clipboard

os/glog/glog_logger_rotate.go:The time for slicing should be based on the file creation time rather than the update time

Open yiqiang3344 opened this issue 1 year ago • 0 comments

Go version

go1.22.3 darwin/amd64

GoFrame version

v2.7.1

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

日志配置了按时间切片。配置如下:

rotateSize: 100000000           
rotateExpire: "24h"             
rotateBackupLimit: 30           
rotateBackupExpire: "720h"      
rotateBackupCompress: 0         
rotateCheckInterval: "1h"       

What did you see happen?

比如昨天12点启动程序,生成了日志文件log/access.log,持续到今天13点时,也没有生成log/access.log的切片。

What did you expect to see?

应该按文件的创建时间来判断是否生成切片,而不是修改时间。 框架的相关逻辑如下: github.com/gogf/gf/[email protected]/os/glog/glog_logger_rotate.go:163

			mtime = gfile.MTime(file)
			subDuration = now.Sub(mtime)
			if subDuration > l.config.RotateExpire {
				func() {
					memoryLockFileKey := memoryLockPrefixForPrintingToFile + file
					if !gmlock.TryLock(memoryLockFileKey) {
						return
					}
					defer gmlock.Unlock(memoryLockFileKey)
					expireRotated = true
					intlog.Printf(
						ctx,
						`%v - %v = %v > %v, rotation expire logging file: %s`,
						now, mtime, subDuration, l.config.RotateExpire, file,
					)
					if err = l.doRotateFile(ctx, file); err != nil {
						intlog.Errorf(ctx, `%+v`, err)
					}
				}()
			}

其中获取文件时间这块mtime = gfile.MTime(file)实际取到的文件修改时间。

yiqiang3344 avatar May 30 '24 09:05 yiqiang3344