summaryrefslogtreecommitdiff
path: root/plugins/logger/encoder.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/logger/encoder.go')
-rw-r--r--plugins/logger/encoder.go66
1 files changed, 0 insertions, 66 deletions
diff --git a/plugins/logger/encoder.go b/plugins/logger/encoder.go
deleted file mode 100644
index 4ff583c4..00000000
--- a/plugins/logger/encoder.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package logger
-
-import (
- "hash/fnv"
- "strings"
- "time"
-
- "github.com/fatih/color"
- "go.uber.org/zap/zapcore"
-)
-
-var colorMap = []func(string, ...interface{}) string{
- color.HiYellowString,
- color.HiGreenString,
- color.HiBlueString,
- color.HiRedString,
- color.HiCyanString,
- color.HiMagentaString,
-}
-
-// ColoredLevelEncoder colorizes log levels.
-func ColoredLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
- switch level {
- case zapcore.DebugLevel:
- enc.AppendString(color.HiWhiteString(level.CapitalString()))
- case zapcore.InfoLevel:
- enc.AppendString(color.HiCyanString(level.CapitalString()))
- case zapcore.WarnLevel:
- enc.AppendString(color.HiYellowString(level.CapitalString()))
- case zapcore.ErrorLevel, zapcore.DPanicLevel:
- enc.AppendString(color.HiRedString(level.CapitalString()))
- case zapcore.PanicLevel, zapcore.FatalLevel:
- enc.AppendString(color.HiMagentaString(level.CapitalString()))
- }
-}
-
-// ColoredNameEncoder colorizes service names.
-func ColoredNameEncoder(s string, enc zapcore.PrimitiveArrayEncoder) {
- if len(s) < 12 {
- s += strings.Repeat(" ", 12-len(s))
- }
-
- enc.AppendString(color.HiGreenString(s))
-}
-
-// ColoredHashedNameEncoder colorizes service names and assigns different colors to different names.
-func ColoredHashedNameEncoder(s string, enc zapcore.PrimitiveArrayEncoder) {
- if len(s) < 12 {
- s += strings.Repeat(" ", 12-len(s))
- }
-
- colorID := stringHash(s, len(colorMap))
- enc.AppendString(colorMap[colorID](s))
-}
-
-// UTCTimeEncoder encodes time into short UTC specific timestamp.
-func UTCTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
- enc.AppendString(t.UTC().Format("2006/01/02 15:04:05"))
-}
-
-// returns string hash
-func stringHash(name string, base int) int {
- h := fnv.New32a()
- _, _ = h.Write([]byte(name))
- return int(h.Sum32()) % base
-}