mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 19:46:57 +08:00
color
This commit is contained in:
parent
bbcc6c212a
commit
9445f74e1a
50
pkg/common/log/color.go
Normal file
50
pkg/common/log/color.go
Normal file
@ -0,0 +1,50 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// Foreground colors.
|
||||
const (
|
||||
Black Color = iota + 30
|
||||
Red
|
||||
Green
|
||||
Yellow
|
||||
Blue
|
||||
Magenta
|
||||
Cyan
|
||||
White
|
||||
)
|
||||
|
||||
var (
|
||||
_levelToColor = map[zapcore.Level]Color{
|
||||
zapcore.DebugLevel: Magenta,
|
||||
zapcore.InfoLevel: Blue,
|
||||
zapcore.WarnLevel: Yellow,
|
||||
zapcore.ErrorLevel: Red,
|
||||
zapcore.DPanicLevel: Red,
|
||||
zapcore.PanicLevel: Red,
|
||||
zapcore.FatalLevel: Red,
|
||||
}
|
||||
_unknownLevelColor = make(map[zapcore.Level][]string, len(_levelToColor))
|
||||
|
||||
_levelToLowercaseColorString = make(map[zapcore.Level][]string, len(_levelToColor))
|
||||
_levelToCapitalColorString = make(map[zapcore.Level][]string, len(_levelToColor))
|
||||
)
|
||||
|
||||
func init() {
|
||||
for level, color := range _levelToColor {
|
||||
_levelToLowercaseColorString[level] = append(_levelToLowercaseColorString[level], color.Add(level.String()), color.Add("caller"))
|
||||
_levelToCapitalColorString[level] = append(_levelToCapitalColorString[level], color.Add(level.CapitalString()), color.Add("caller"))
|
||||
}
|
||||
}
|
||||
|
||||
// Color represents a text color.
|
||||
type Color uint8
|
||||
|
||||
// Add adds the coloring to the given string.
|
||||
func (c Color) Add(s string) string {
|
||||
return fmt.Sprintf("\x1b[%dm%s\x1b[0m", uint8(c), s)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user