-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add log configuration #63
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #63 +/- ##
==========================================
+ Coverage 45.73% 46.83% +1.10%
==========================================
Files 48 48
Lines 2683 2797 +114
==========================================
+ Hits 1227 1310 +83
- Misses 1374 1394 +20
- Partials 82 93 +11
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
add testcase |
0d885dd
to
e8596e9
Compare
ca00f87
to
6410a02
Compare
} | ||
|
||
func (l *Logger) mill() { | ||
if l.roller.MaxBackups != defaultRotateKeep || l.roller.MaxAge != defaultRotateAge || l.roller.Compress { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个判断套件不太对啊。
如果配置成和default 一样的值就不执行,这个行为应该是不对的。
为了保持之前默认不执行的逻辑,是不是新加一个开关比较合适。
@@ -400,3 +400,61 @@ WAIT: | |||
t.Logf("received %d reopens", reopens) | |||
close(l.stopRotate) | |||
} | |||
|
|||
func TestLogRollerTimeAndCompress(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试应该覆盖如下场景:
- 配置按时间轮转,Compress与MaxBackup(比如1),那么至少应该有3个文件,第一个文件正常写,第二个文件写的时候,第一个被轮转,第三个写的时候第二个被轮转,第一个被压缩
- 同样的情况,没有配置Compress,那第一个应该是被删除
- 配置按照大小轮转,其他同1)和2)
@@ -205,6 +209,7 @@ func (l *Logger) start() error { | |||
l.create = time.Now() | |||
} | |||
l.writer = file | |||
l.mill() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里执行mill ,看上去可能会有一些耗时。在这期间这个logger实际上是没有办法正常工作的(后面的l.handler没有执行)。如果这里mill 卡太久,可能会导致日志丢失等情况出现,这是需要考虑的风险。
是否可以考虑将这个mill 做成异步的,可以按照日志路径有锁避免并发冲突?但是不影响start的时候及时可以执行写新日志,可以讨论一下
No description provided.