Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yiqiang3344 opened this issue May 30, 2024 · 4 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@yiqiang3344
Copy link

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/v2@v2.7.1/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 yiqiang3344 added the bug It is confirmed a bug, but don't worry, we'll handle it. label May 30, 2024
yiqiang3344 pushed a commit to yiqiang3344/gf that referenced this issue Jun 21, 2024
@yiqiang3344 yiqiang3344 changed the title os/glog/glog_logger_rotate.go os/glog/glog_logger_rotate.go:The time for slicing should be based on the file creation time rather than the update time Jun 26, 2024
yiqiang3344 pushed a commit to yiqiang3344/gf-micro that referenced this issue Jul 2, 2024
yiqiang3344 pushed a commit to yiqiang3344/gf that referenced this issue Aug 5, 2024
…me change edit time to create time, no good solution, only darwin system effective. (gogf#3620)
@yiqiang3344
Copy link
Author

只能通过给日志文件名添加{Y-m-d}日期配置来让按时间切片生效,因为linux系统文件没有创建时间。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Time slicing can only take effect by adding {Y-m-d} date configuration to the log file name, because Linux system files do not have a creation time.

@yiqiang3344
Copy link
Author

无需处理

@yiqiang3344 yiqiang3344 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


No processing required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

2 participants