add noslog build tag and small reference section to README

This commit is contained in:
soypat
2026-09-01 13:12:51 -07:00
parent c97a32f3c1
commit 91a048fb1d
6 changed files with 23 additions and 5 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ var (
)
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
return true
return logEnabled
}
func logAttrsAndAllocs(allocmsg string, l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
+2 -2
View File
@@ -10,14 +10,14 @@ import (
const HeapAllocDebugging = false
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
return l != nil && l.Handler().Enabled(context.Background(), lvl)
return logEnabled && l != nil && l.Handler().Enabled(context.Background(), lvl)
}
// LogAttrs is a helper function that is used by all package loggers and that
// can be switched out with the `debugheaplog` build tag for a non-allocating
// logger that prints out when heap allocations occur.
func LogAttrs(l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
if l != nil {
if logEnabled && l != nil {
l.LogAttrs(context.Background(), level, msg, attrs...)
}
}
+5
View File
@@ -0,0 +1,5 @@
//go:build noslog
package internal
const logEnabled = false
+5
View File
@@ -0,0 +1,5 @@
//go:build !noslog
package internal
const logEnabled = true