Files
zeekay abbf1a0837 feat(log): replace slog DiscardHandler with luxfi/log bridge
Delete the old slog-based log package (format.go, handler.go,
handler_glog.go, logger.go, root.go) which initialized with
DiscardHandler — silently swallowing all log output including Crit
messages before calling os.Exit(1). This caused the EVM plugin
subprocess to die with no trace.

Replace with a thin bridge package (log/log.go) that re-exports
github.com/luxfi/log, ensuring:
- All geth log.Crit/Fatal calls properly log to stderr before exiting
- Default logger writes to stderr (not /dev/null)
- slog.Handler shims for backward compatibility

Also rewrite all 249 source files to import luxfi/log directly.
2026-02-10 21:07:22 -08:00

68 lines
1.4 KiB
Go

package testlog
import (
"bytes"
"fmt"
"io"
"strings"
"testing"
log "github.com/luxfi/log"
)
type mockT struct {
out io.Writer
}
func (t *mockT) Helper() {
// noop for the purposes of unit tests
}
func (t *mockT) Logf(format string, args ...any) {
// we could gate this operation in a mutex, but because testlogger
// only calls Logf with its internal mutex held, we just write output here
var lineBuf bytes.Buffer
if _, err := fmt.Fprintf(&lineBuf, format, args...); err != nil {
panic(err)
}
// The timestamp is locale-dependent, so we want to trim that off
// "INFO [01-01|00:00:00.000] a message ..." -> "a message..."
sanitized := strings.Split(lineBuf.String(), "]")[1]
if _, err := t.out.Write([]byte(sanitized)); err != nil {
panic(err)
}
}
func TestLogging(t *testing.T) {
tests := []struct {
name string
expected string
run func(t *mockT)
}{
{
"SubLogger",
` Visible
Hide and seek foobar=123
Also visible
`,
func(t *mockT) {
l := Logger(t, log.LevelInfo)
subLogger := l.New("foobar", 123)
l.Info("Visible")
subLogger.Info("Hide and seek")
l.Info("Also visible")
},
},
}
for _, tc := range tests {
outp := bytes.Buffer{}
mock := mockT{&outp}
tc.run(&mock)
if outp.String() != tc.expected {
fmt.Printf("output mismatch.\nwant: '%s'\ngot: '%s'\n", tc.expected, outp.String())
}
}
}