diff options
| author | Marin Ivanov <[email protected]> | 2026-01-18 16:14:14 +0200 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2026-01-18 23:55:31 +0200 |
| commit | 465177182fae40d377d3e4f8e36d81a4edca43ba (patch) | |
| tree | 8362d899ecfaa784364408d3f8facdddfa566508 /levels.go | |
Diffstat (limited to 'levels.go')
| -rw-r--r-- | levels.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/levels.go b/levels.go new file mode 100644 index 0000000..6b9213e --- /dev/null +++ b/levels.go @@ -0,0 +1,38 @@ +package logging + +type LevelEnum uint16 + +const ( + None LevelEnum = iota + Error + Warn + Info + Debug +) + +type levelInfo struct { + abbrev string + color string +} + +var ( + levelInfos = map[LevelEnum]levelInfo{ + Error: {"ERR", Red}, + Warn: {"WARN", Yellow}, + Info: {"INFO", Cyan}, + Debug: {"DEBUG", Green}, + } +) + +func (s LevelEnum) Info() levelInfo { + info, ok := levelInfos[s] + if !ok { + return levelInfo{"UNK", White} + } + return info +} + +func (s LevelEnum) Format() string { + info := s.Info() + return colorize("["+info.abbrev+"]", info.color) +} |
