1
// Copyright 2019 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
10
"code.gitea.io/gitea/modules/json"
13
// Level is the level of the logger
17
UNDEFINED Level = iota
27
const CRITICAL = ERROR // most logger frameworks doesn't support CRITICAL, and it doesn't seem useful
29
var toString = map[Level]string{
30
UNDEFINED: "undefined",
42
var toLevel = map[string]Level{
43
"undefined": UNDEFINED,
56
var levelToColor = map[Level][]ColorAttribute{
57
TRACE: {Bold, FgCyan},
58
DEBUG: {Bold, FgBlue},
59
INFO: {Bold, FgGreen},
60
WARN: {Bold, FgYellow},
66
func (l Level) String() string {
74
func (l Level) ColorAttributes() []ColorAttribute {
75
color, ok := levelToColor[l]
79
none := levelToColor[NONE]
83
// MarshalJSON takes a Level and turns it into text
84
func (l Level) MarshalJSON() ([]byte, error) {
85
buffer := bytes.NewBufferString(`"`)
86
buffer.WriteString(toString[l])
87
buffer.WriteString(`"`)
88
return buffer.Bytes(), nil
91
// UnmarshalJSON takes text and turns it into a Level
92
func (l *Level) UnmarshalJSON(b []byte) error {
94
err := json.Unmarshal(b, &tmp)
99
switch v := tmp.(type) {
101
*l = LevelFromString(v)
103
*l = LevelFromString(Level(v).String())
110
// LevelFromString takes a level string and returns a Level
111
func LevelFromString(level string) Level {
112
if l, ok := toLevel[strings.ToLower(level)]; ok {