Files
lneto/internal/debug_noheaplog.go
T
Pat Whittingslow d7f3924489 prevent aggressive DCE in MWE w/ TinyGo and cull fmt package (#196)
* cull fmt package use and prevent aggressive DCE in MWE example with TinyGo

* add noslog build tag and small reference section to README

* add memci

* fix ci

* whoops, forgot memci.json to gitignore

* whoops x2

* use noslog build tag

* don't go ham on removing fmt useful data

* remove old benchmarking CI
2026-09-06 13:17:14 -07:00

30 lines
870 B
Go

//go:build !debugheaplog
package internal
import (
"context"
"log/slog"
)
const HeapAllocDebugging = false
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
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 logEnabled && l != nil {
l.LogAttrs(context.Background(), level, msg, attrs...)
}
}
func logAttrsAndAllocs(allocmsg string, l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
LogAllocs(allocmsg)
LogAttrs(l, level, msg, attrs...)
LogAllocs(msg) // Should not log again unless LogAttrs allocated.
}