implementing only EncodeEntry
(entry zapcore.Entry, fields []zapcore.Field)
| 32 | |
| 33 | // implementing only EncodeEntry |
| 34 | func (e *prependEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) { |
| 35 | // new log buffer |
| 36 | buf := e.pool.Get() |
| 37 | blue := color.New(color.BgBlue) |
| 38 | red := color.New(color.BgRed) |
| 39 | |
| 40 | coloredPrefix := blue.Sprint("[BRICKSLLM]") |
| 41 | if entry.Level != zap.InfoLevel { |
| 42 | coloredPrefix = red.Sprint("[BRICKSLLM]") |
| 43 | } |
| 44 | |
| 45 | buf.AppendString(coloredPrefix) |
| 46 | buf.AppendString(" ") |
| 47 | buf.AppendString(e.toAtalasPrefix(entry.Level)) |
| 48 | buf.AppendString(" | ") |
| 49 | buf.AppendString(time.Now().Format(time.RFC3339)) |
| 50 | buf.AppendString(" | ") |
| 51 | |
| 52 | // calling the embedded encoder's EncodeEntry to keep the original encoding format |
| 53 | consolebuf, err := e.Encoder.EncodeEntry(entry, fields) |
| 54 | if err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | |
| 58 | // just write the output into your own buffer |
| 59 | _, err = buf.Write(consolebuf.Bytes()) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | return buf, nil |
| 64 | } |
| 65 | |
| 66 | func (e *prependEncoder) toAtalasPrefix(lvl zapcore.Level) string { |
| 67 | switch lvl { |
nothing calls this directly
no test coverage detected