Debian Codegraph @

level.go

raw symbols SCIP
1 // mauLogger - A logger for Go programs
2 // Copyright (c) 2016-2021 Tulir Asokan
3 //
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8 package maulogger
9
10 import (
11 "fmt"
12 )
13
14 // Level is the severity level of a log entry.
15 type Level struct {
16 Name string
17 Severity, Color int
18 }
19
20 var (
21 // LevelDebug is the level for debug messages.
22 LevelDebug = Level{Name: "DEBUG", Color: -1, Severity: 0}
23 // LevelInfo is the level for basic log messages.
24 LevelInfo = Level{Name: "INFO", Color: 36, Severity: 10}
25 // LevelWarn is the level saying that something went wrong, but the program will continue operating mostly normally.
26 LevelWarn = Level{Name: "WARN", Color: 33, Severity: 50}
27 // LevelError is the level saying that something went wrong and the program may not operate as expected, but will still continue.
28 LevelError = Level{Name: "ERROR", Color: 31, Severity: 100}
29 // LevelFatal is the level saying that something went wrong and the program will not operate normally.
30 LevelFatal = Level{Name: "FATAL", Color: 35, Severity: 9001}
31 )
32
33 // GetColor gets the ANSI escape color code for the log level.
34 func (lvl Level) GetColor() string {
35 if lvl.Color < 0 {
36 return "\x1b[0m"
37 }
38 return fmt.Sprintf("\x1b[%dm", lvl.Color)
39 }
40
41 // GetReset gets the ANSI escape reset code.
42 func (lvl Level) GetReset() string {
43 if lvl.Color < 0 {
44 return ""
45 }
46 return "\x1b[0m"
47 }