### Purpose Re-enables LOGGER_DISCARD. See #10262. ### Documentation No changes needed, as the docs already mention this variable.
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user