chore(slog): re-enable LOGGER_DISCARD (fixes #10262) (#10267)

### Purpose

Re-enables LOGGER_DISCARD. See #10262.

### Documentation

No changes needed, as the docs already mention this variable.
This commit is contained in:
Ross Smith II
2025-08-19 22:36:10 +02:00
committed by GitHub
parent 60160db23a
commit 3058aa6315
+12 -1
View File
@@ -7,6 +7,7 @@
package slogutil package slogutil
import ( import (
"io"
"log/slog" "log/slog"
"os" "os"
"strings" "strings"
@@ -21,10 +22,20 @@ var (
} }
slogDef = slog.New(&formattingHandler{ slogDef = slog.New(&formattingHandler{
recs: []*lineRecorder{GlobalRecorder, ErrorRecorder}, recs: []*lineRecorder{GlobalRecorder, ErrorRecorder},
out: os.Stdout, out: logWriter(),
}) })
) )
func logWriter() io.Writer {
if os.Getenv("LOGGER_DISCARD") != "" {
// Hack to completely disable logging, for example when running
// benchmarks.
return io.Discard
}
return os.Stdout
}
func init() { func init() {
slog.SetDefault(slogDef) slog.SetDefault(slogDef)