add feature toggle with new format (#47336)
* add feature toggle with new format * fix some comments ❤️ * Update pkg/infra/log/term/terminal_logger.go Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
co-authored by
Emil Tullstedt
parent
fb0f30e30b
commit
03ba91e8a4
@@ -14,14 +14,22 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
)
|
||||
|
||||
const (
|
||||
var (
|
||||
timeFormat = "2006-01-02T15:04:05-0700"
|
||||
termTimeFormat = "01-02|15:04:05"
|
||||
floatFormat = 'f'
|
||||
termMsgJust = 40
|
||||
errorKey = "LOG15_ERROR"
|
||||
)
|
||||
|
||||
const (
|
||||
floatFormat = 'f'
|
||||
termMsgJust = 40
|
||||
errorKey = "LOG15_ERROR"
|
||||
)
|
||||
|
||||
func SetTimeFormatGokitLog() {
|
||||
timeFormat = "2006-01-02T15:04:05.000-0700"
|
||||
termTimeFormat = "01-02|15:04:05.000"
|
||||
}
|
||||
|
||||
type terminalLogger struct {
|
||||
w io.Writer
|
||||
}
|
||||
@@ -45,7 +53,10 @@ func (l terminalLogger) Log(keyvals ...interface{}) error {
|
||||
r := getRecord(keyvals)
|
||||
|
||||
b := &bytes.Buffer{}
|
||||
lvl := strings.ToUpper(r.level.String())
|
||||
|
||||
// To make the log output more readable, we make all log levels 5 characters long
|
||||
lvl := fmt.Sprintf("%-5s", strings.ToUpper(r.level.String()))
|
||||
|
||||
if r.color > 0 {
|
||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", r.color, lvl, r.time.Format(termTimeFormat), r.msg) // lgtm[go/log-injection]
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user