(entry zapcore.Entry, fields []zapcore.Field)
| 54 | ) |
| 55 | |
| 56 | func (t *consoleEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) { |
| 57 | levelColor, levelIndicator := getLevelColorAndIndicator(&entry) |
| 58 | line := linePool.Get() |
| 59 | |
| 60 | // <space><space><indicator char><space> |
| 61 | if t.colored { |
| 62 | _, _ = fmt.Fprintf(line, "\x1b[%dm%s\x1b[0m", levelColor, levelIndicator) |
| 63 | } else { |
| 64 | line.AppendString(levelIndicator) |
| 65 | } |
| 66 | |
| 67 | if t.colored && entry.Level >= zapcore.ErrorLevel { |
| 68 | _, _ = fmt.Fprintf(line, "\x1b[%dm%s\x1b[0m", levelColor, entry.Message) |
| 69 | } else { |
| 70 | line.AppendString(entry.Message) |
| 71 | } |
| 72 | |
| 73 | paddingSizeAfterMessage := max(2, 16-len(entry.Message)) |
| 74 | line.AppendString(strings.Repeat(" ", paddingSizeAfterMessage)) |
| 75 | // n can be used because ASCII only (so, byte count equals to char count) |
| 76 | |
| 77 | extraFieldNumber := len(t.fieldNames) |
| 78 | fieldNameAndValueList := make([]*buffer.Buffer, len(fields) + extraFieldNumber) |
| 79 | totalLength := 0 |
| 80 | |
| 81 | arrayEncoder := &bufferArrayEncoder{buffer: linePool.Get()} |
| 82 | |
| 83 | totalLength += t.encodeExtraFields(levelColor, &fieldNameAndValueList) |
| 84 | |
| 85 | fieldLoop: |
| 86 | for index, field := range fields { |
| 87 | if field.Type == zapcore.SkipType { |
| 88 | continue |
| 89 | } |
| 90 | |
| 91 | buf := linePool.Get() |
| 92 | if t.colored { |
| 93 | _, _ = fmt.Fprintf(buf, "\x1b[%dm%s\x1b[0m", levelColor, field.Key) |
| 94 | } else { |
| 95 | buf.AppendString(field.Key) |
| 96 | } |
| 97 | buf.AppendString("=") |
| 98 | |
| 99 | var v string |
| 100 | |
| 101 | switch field.Type { |
| 102 | case zapcore.ArrayMarshalerType: |
| 103 | arrayEncoder.buffer.Reset() |
| 104 | |
| 105 | err := field.Interface.(zapcore.ArrayMarshaler).MarshalLogArray(arrayEncoder) |
| 106 | v = arrayEncoder.buffer.String() |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | |
| 111 | case zapcore.ObjectMarshalerType, zapcore.BinaryType, zapcore.Complex128Type, zapcore.Complex64Type, zapcore.ReflectType, zapcore.NamespaceType: |
| 112 | return nil, fmt.Errorf("unsupported field type: %v", field) |
| 113 | case zapcore.BoolType: |
nothing calls this directly
no test coverage detected