SetUpBenchmarkLogging will set the given log level and key, and do log processing for that configuration, but discards the output, instead of writing it to console.
(tb testing.TB, logLevel LogLevel, logKeys ...LogKey)
| 617 | // SetUpBenchmarkLogging will set the given log level and key, and do log processing for that configuration, |
| 618 | // but discards the output, instead of writing it to console. |
| 619 | func SetUpBenchmarkLogging(tb testing.TB, logLevel LogLevel, logKeys ...LogKey) { |
| 620 | teardownFnOrig := setTestLogging(logLevel, "", logKeys...) |
| 621 | |
| 622 | // discard all logging output for benchmarking (but still execute logging as normal) |
| 623 | consoleLogger.Load().logger.SetOutput(io.Discard) |
| 624 | tb.Cleanup(func() { |
| 625 | logger := consoleLogger.Load() |
| 626 | // revert back to original output |
| 627 | if logger != nil && logger.output != nil { |
| 628 | logger.logger.SetOutput(logger.output) |
| 629 | } else { |
| 630 | logger.logger.SetOutput(os.Stderr) |
| 631 | } |
| 632 | teardownFnOrig() |
| 633 | }) |
| 634 | } |
| 635 | |
| 636 | func setTestLogging(logLevel LogLevel, caller string, logKeys ...LogKey) (teardownFn func()) { |
| 637 | if GlobalTestLoggingSet.IsTrue() { |