TestLoggerV2PrintFuncDiscardOnlyInfo ensures that logs at the INFO level are discarded when set to io.Discard, while logs at other levels (WARN, ERROR) are still printed. It does this by using a custom error function that raises an error if the logger attempts to print at the INFO level, ensuring ea
(t *testing.T)
| 132 | // an error if the logger attempts to print at the INFO level, ensuring early |
| 133 | // return when io.Discard is used. |
| 134 | func TestLoggerV2PrintFuncDiscardOnlyInfo(t *testing.T) { |
| 135 | buffers := []*bytes.Buffer{nil, new(bytes.Buffer), new(bytes.Buffer)} |
| 136 | logger := NewLoggerV2(io.Discard, buffers[warningLog], buffers[errorLog], LoggerV2Config{}) |
| 137 | loggerTp := logger.(*loggerT) |
| 138 | |
| 139 | // test that output doesn't call expensive printf funcs on an io.Discard logger |
| 140 | sprintf = makeSprintfErr(t) |
| 141 | sprint = makeSprintErr(t) |
| 142 | sprintln = makeSprintErr(t) |
| 143 | |
| 144 | loggerTp.output(infoLog, "something") |
| 145 | |
| 146 | sprintf = fmt.Sprintf |
| 147 | sprint = fmt.Sprint |
| 148 | sprintln = fmt.Sprintln |
| 149 | |
| 150 | loggerTp.output(errorLog, logFuncStr) |
| 151 | warnB, err := buffers[warningLog].ReadBytes('\n') |
| 152 | if err != nil { |
| 153 | t.Fatalf("level %v: %v", warningLog, err) |
| 154 | } |
| 155 | checkLogContainsFuncStr(t, warnB) |
| 156 | |
| 157 | errB, err := buffers[errorLog].ReadBytes('\n') |
| 158 | if err != nil { |
| 159 | t.Fatalf("level %v: %v", errorLog, err) |
| 160 | } |
| 161 | checkLogContainsFuncStr(t, errB) |
| 162 | } |
| 163 | |
| 164 | func TestLoggerV2PrintFuncNoDiscard(t *testing.T) { |
| 165 | buffers := []*bytes.Buffer{new(bytes.Buffer), new(bytes.Buffer), new(bytes.Buffer)} |
nothing calls this directly
no test coverage detected