Skip to content

Commit

Permalink
feat: log support hourly splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao committed Jan 23, 2024
1 parent edd31cf commit b28f3c4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,15 @@ func (l *ZapLogger) timeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
}

func (l *ZapLogger) getWriter(logLocation string, rorateCount uint) (zapcore.WriteSyncer, error) {
logf, err := rotatelogs.New(logLocation+sp+l.loggerPrefixName+".%Y-%m-%d",
var path string
if l.rotationTime%(time.Hour*24) == 0 {
path = logLocation + sp + l.loggerPrefixName + ".%Y-%m-%d"
} else if l.rotationTime%time.Hour == 0 {
path = logLocation + sp + l.loggerPrefixName + ".%Y-%m-%d_%H"
} else {
path = logLocation + sp + l.loggerPrefixName + ".%Y-%m-%d_%H_%M_%S"
}
logf, err := rotatelogs.New(path,
rotatelogs.WithRotationCount(rorateCount),
rotatelogs.WithRotationTime(l.rotationTime),
)
Expand Down

0 comments on commit b28f3c4

Please sign in to comment.