platform: Add group interface

This commit is contained in:
世界 2023-07-02 16:45:30 +08:00
parent 5ad0ea2b5a
commit 9c8565cf21
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
25 changed files with 576 additions and 95 deletions

View file

@ -17,6 +17,7 @@ type Formatter struct {
DisableTimestamp bool
FullTimestamp bool
TimestampFormat string
DisableLineBreak bool
}
func (f Formatter) Format(ctx context.Context, level Level, tag string, message string, timestamp time.Time) string {
@ -76,8 +77,14 @@ func (f Formatter) Format(ctx context.Context, level Level, tag string, message
default:
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
}
if message[len(message)-1] != '\n' {
message += "\n"
if f.DisableLineBreak {
if message[len(message)-1] != '\n' {
message = message[:len(message)-1]
}
} else {
if message[len(message)-1] != '\n' {
message += "\n"
}
}
return message
}