summaryrefslogtreecommitdiff
path: root/plugins/logger/encoder.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-09-16 21:46:50 +0300
committerGitHub <[email protected]>2021-09-16 21:46:50 +0300
commit3581b45f237a3f7aa29591ceb2bf6f4a4642a2f5 (patch)
treee723b19ec1ac16b7ccc7b3c2da69d4a416d63d81 /plugins/logger/encoder.go
parent337d292dd2d6ff0a555098b1970d8194d8df8bc2 (diff)
parent823d831b57b75f70c7c3bbbee355f2016633bb3b (diff)
[#803]: feat(plugins): move plugins to a separate repositoryv2.5.0-alpha.2
[#803]: feat(plugins): move plugins to a separate repository
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
-}