mirror of
https://github.com/soypat/lneto.git
synced 2026-09-07 23:39:04 +00:00
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
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
//go:build noslog
|
||||
|
||||
package internal
|
||||
|
||||
const logEnabled = false
|
||||
@@ -0,0 +1,5 @@
|
||||
//go:build !noslog
|
||||
|
||||
package internal
|
||||
|
||||
const logEnabled = true
|
||||
@@ -1,5 +1,26 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// AppendStrDecimal appends pfx followed by value in base 10 to dst and returns
|
||||
// the resulting slice. It condenses the prefixed-number pattern common to
|
||||
// AppendString/AppendText methods, i.e. `internal.AppendStrDecimal(b, " len=", 4)`.
|
||||
func AppendStrDecimal(dst []byte, pfx string, value int64) []byte {
|
||||
dst = append(dst, pfx...)
|
||||
return strconv.AppendInt(dst, value, 10)
|
||||
}
|
||||
|
||||
// AppendStrHexData appends pfx followed by data as hexadecimaldata.
|
||||
//
|
||||
// dst = internal.AppendStrHexData(dst, "data=0x", data...) // data=0xdeadbeef
|
||||
func AppendStrHexData(dst []byte, pfx string, data ...byte) []byte {
|
||||
dst = append(dst, pfx...)
|
||||
return hex.AppendEncode(dst, data)
|
||||
}
|
||||
|
||||
// IntLen returns the number of bytes [strconv.AppendInt] emits for value in the
|
||||
// given base, including a leading minus sign for negatives. Lets callers size a
|
||||
// buffer, or test whether a value fits an existing slot, before writing a byte.
|
||||
|
||||
Reference in New Issue
Block a user