MCPcopy
hub / github.com/kopia/kopia / EncodeEntry

Method EncodeEntry

internal/zaplogutil/zaplogutil.go:81–142  ·  view source on GitHub ↗
(ent zapcore.Entry, fields []zapcore.Field)

Source from the content-addressed store, hash-verified

79}
80
81func (c *stdConsoleEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) {
82 line := bufPool.Get()
83
84 separator := ""
85
86 if c.TimeLayout != "" {
87 if c.LocalTime {
88 line.AppendTime(ent.Time.Local(), c.TimeLayout)
89 } else {
90 line.AppendTime(ent.Time.UTC(), c.TimeLayout)
91 }
92
93 separator = " "
94 }
95
96 if c.EmitLogLevel {
97 line.AppendString(separator)
98
99 if ent.Level != zapcore.InfoLevel || !c.DoNotEmitInfoLevel {
100 if c.ColoredLogLevel {
101 switch ent.Level {
102 case zapcore.DebugLevel:
103 line.AppendString("\x1b[35m") // magenta
104 case zapcore.WarnLevel:
105 line.AppendString("\x1b[33m") // yellow
106 default:
107 line.AppendString("\x1b[31m") // red
108 }
109
110 line.AppendString(ent.Level.CapitalString())
111 line.AppendString("\x1b[0m")
112 } else {
113 line.AppendString(ent.Level.CapitalString())
114 }
115
116 separator = " "
117 }
118 }
119
120 if ent.LoggerName != "" && c.EmitLoggerName {
121 line.AppendString(separator)
122 line.AppendString(ent.LoggerName)
123
124 separator = " "
125 }
126
127 line.AppendString(separator)
128 line.AppendString(ent.Message)
129
130 if line2, err := c.Encoder.EncodeEntry(ent, fields); err == nil {
131 if line2.Len() > 2 { //nolint:mnd
132 line.AppendString("\t")
133 line.AppendString(line2.String())
134 }
135
136 line2.Free()
137 }
138

Callers

nothing calls this directly

Calls 3

GetMethod · 0.65
LenMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected