mirror of
https://github.com/soypat/lneto.git
synced 2026-07-26 10:38:47 +00:00
157a8537a2
* testing.B.Loop() standardization and StackAsync.Debug heap debugging improvement * apply @MDr164 fixes * @MDr164 great suggestions to prevent panic and print correct mallocs
30 lines
842 B
Go
30 lines
842 B
Go
//go:build !debugheaplog
|
|
|
|
package internal
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
)
|
|
|
|
const HeapAllocDebugging = false
|
|
|
|
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
|
|
return 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 {
|
|
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.
|
|
}
|