* 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
24 строки
457 B
Go
24 строки
457 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package human
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
)
|
|
|
|
type LogWriter interface {
|
|
Write(e LogEntry)
|
|
}
|
|
|
|
// Read JSON logs from input and write formatted logs to the output
|
|
func ProcessLogs(reader io.Reader, writer LogWriter) {
|
|
scanner := bufio.NewScanner(reader)
|
|
for scanner.Scan() {
|
|
s := scanner.Text()
|
|
e := ParseLogMessage(s)
|
|
writer.Write(e)
|
|
}
|
|
}
|