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 13:36:10 -07:00
committed by GitHub
parent 60160db23a
commit 3058aa6315

View File

@@ -7,6 +7,7 @@
package slogutil
import (
"io"
"log/slog"
"os"
"strings"
@@ -21,10 +22,20 @@ var (
}
slogDef = slog.New(&formattingHandler{
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() {
slog.SetDefault(slogDef)