(t *testing.T)
| 76 | } |
| 77 | |
| 78 | func TestEncoderConfiguration(t *testing.T) { |
| 79 | base := testEncoderConfig() |
| 80 | |
| 81 | tests := []struct { |
| 82 | desc string |
| 83 | cfg EncoderConfig |
| 84 | amendEntry func(Entry) Entry |
| 85 | extra func(Encoder) |
| 86 | expectedJSON string |
| 87 | expectedConsole string |
| 88 | }{ |
| 89 | { |
| 90 | desc: "messages to be escaped", |
| 91 | cfg: base, |
| 92 | amendEntry: func(ent Entry) Entry { |
| 93 | ent.Message = `hello\` |
| 94 | return ent |
| 95 | }, |
| 96 | expectedJSON: `{"level":"info","ts":0,"name":"main","caller":"foo.go:42","func":"foo.Foo","msg":"hello\\","stacktrace":"fake-stack"}` + "\n", |
| 97 | expectedConsole: "0\tinfo\tmain\tfoo.go:42\tfoo.Foo\thello\\\nfake-stack\n", |
| 98 | }, |
| 99 | { |
| 100 | desc: "use custom entry keys in JSON output and ignore them in console output", |
| 101 | cfg: EncoderConfig{ |
| 102 | LevelKey: "L", |
| 103 | TimeKey: "T", |
| 104 | MessageKey: "M", |
| 105 | NameKey: "N", |
| 106 | CallerKey: "C", |
| 107 | FunctionKey: "F", |
| 108 | StacktraceKey: "S", |
| 109 | LineEnding: base.LineEnding, |
| 110 | EncodeTime: base.EncodeTime, |
| 111 | EncodeDuration: base.EncodeDuration, |
| 112 | EncodeLevel: base.EncodeLevel, |
| 113 | EncodeCaller: base.EncodeCaller, |
| 114 | }, |
| 115 | expectedJSON: `{"L":"info","T":0,"N":"main","C":"foo.go:42","F":"foo.Foo","M":"hello","S":"fake-stack"}` + "\n", |
| 116 | expectedConsole: "0\tinfo\tmain\tfoo.go:42\tfoo.Foo\thello\nfake-stack\n", |
| 117 | }, |
| 118 | { |
| 119 | desc: "skip line ending if SkipLineEnding is 'true'", |
| 120 | cfg: EncoderConfig{ |
| 121 | LevelKey: "L", |
| 122 | TimeKey: "T", |
| 123 | MessageKey: "M", |
| 124 | NameKey: "N", |
| 125 | CallerKey: "C", |
| 126 | FunctionKey: "F", |
| 127 | StacktraceKey: "S", |
| 128 | LineEnding: base.LineEnding, |
| 129 | SkipLineEnding: true, |
| 130 | EncodeTime: base.EncodeTime, |
| 131 | EncodeDuration: base.EncodeDuration, |
| 132 | EncodeLevel: base.EncodeLevel, |
| 133 | EncodeCaller: base.EncodeCaller, |
| 134 | }, |
| 135 | expectedJSON: `{"L":"info","T":0,"N":"main","C":"foo.go:42","F":"foo.Foo","M":"hello","S":"fake-stack"}`, |
nothing calls this directly
no test coverage detected