summaryrefslogtreecommitdiff
path: root/plugins/logger/zap_logger.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-10-28 13:26:00 +0300
committerWolfy-J <[email protected]>2020-10-28 13:26:00 +0300
commitd6ceb16a9a165764739137de6a2b621685bb8ac3 (patch)
tree5a5202aea9021aa2de3daccb06680d6174ed8717 /plugins/logger/zap_logger.go
parenta9ddea1855ffda6f6388fc91223b8c63ed48b32f (diff)
- new coloring strategy for names
Diffstat (limited to 'plugins/logger/zap_logger.go')
-rw-r--r--plugins/logger/zap_logger.go38
1 files changed, 7 insertions, 31 deletions
diff --git a/plugins/logger/zap_logger.go b/plugins/logger/zap_logger.go
index 747cbf77..e1986da3 100644
--- a/plugins/logger/zap_logger.go
+++ b/plugins/logger/zap_logger.go
@@ -1,13 +1,10 @@
package logger
import (
- "github.com/fatih/color"
"github.com/spiral/endure"
"github.com/spiral/roadrunner/v2/plugins/config"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
- "strings"
- "time"
)
// ServiceName declares service name.
@@ -38,34 +35,13 @@ func (z *ZapLogger) Init(cfg config.Provider) (err error) {
Level: zap.NewAtomicLevelAt(zap.DebugLevel),
Encoding: "console",
EncoderConfig: zapcore.EncoderConfig{
- MessageKey: "message",
- LevelKey: "level",
- TimeKey: "time",
- NameKey: "name",
- EncodeName: func(s string, enc zapcore.PrimitiveArrayEncoder) {
- if len(s) < 12 {
- s = s + strings.Repeat(" ", 12-len(s))
- }
-
- enc.AppendString(color.HiGreenString(s))
- },
- EncodeLevel: func(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()))
- }
- },
- EncodeTime: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
- enc.AppendString(t.UTC().Format("2006/01/02 15:04:05"))
- },
+ MessageKey: "message",
+ LevelKey: "level",
+ TimeKey: "time",
+ NameKey: "name",
+ EncodeName: ColoredHashedNameEncoder,
+ EncodeLevel: ColoredLevelEncoder,
+ EncodeTime: UTCTimeEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
},
OutputPaths: []string{"stderr"},