Add library and command for human-readable logs (#9809)
* Update logrus to 1.2 and add as a direct dependency * Create an mlog/human package for pretty-printing logs This package can read JSON logs from mattermost.log, and output the data to either logrus or a custom formatter, to make the logs more human readable. * Create a command for outputting human-readable logs This command will read JSON data from mattermost.log or stdin, and output in a human readable format. An optional argument can be used to activate logrus output (which includes color support). * Reorganize code in mlog/human and improve logrus timestamp formatting
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
e67d89b9a8
Коммит
8d56fcf568
51
mlog/human/entry.go
Обычный файл
51
mlog/human/entry.go
Обычный файл
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package human
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LogEntry struct {
|
||||
Time time.Time
|
||||
Level string
|
||||
Message string
|
||||
Caller string
|
||||
Fields []mlog.Field
|
||||
}
|
||||
|
||||
// Provide default string representation. Used by SimpleWriter
|
||||
func (f LogEntry) String() string {
|
||||
var sb strings.Builder
|
||||
if !f.Time.IsZero() {
|
||||
sb.WriteString(f.Time.Format(time.RFC3339Nano))
|
||||
sb.WriteRune(' ')
|
||||
}
|
||||
if f.Level != "" {
|
||||
sb.WriteString(f.Level)
|
||||
sb.WriteRune(' ')
|
||||
}
|
||||
if f.Caller != "" {
|
||||
sb.WriteString(f.Caller)
|
||||
sb.WriteRune(' ')
|
||||
}
|
||||
for _, field := range f.Fields {
|
||||
sb.WriteString(field.Key)
|
||||
sb.WriteRune('=')
|
||||
sb.WriteString(fmt.Sprint(field.Interface))
|
||||
sb.WriteRune(' ')
|
||||
}
|
||||
if f.Message != "" {
|
||||
// If the message is multiple lines, start the whole message on a new line
|
||||
if strings.ContainsRune(f.Message, '\n') {
|
||||
sb.WriteRune('\n')
|
||||
}
|
||||
sb.WriteString(f.Message)
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
Ссылка в новой задаче
Block a user