Files
base/tools/logger/luxfi_adapter.go
zeekay a5007b48ed logger: introduce luxfi/log compatibility shim
App callers and plugins want one structured-logging surface that does
not pin them to log/slog. Add a tiny Logger interface and two
implementations:

  - SlogAdapter wraps *slog.Logger so the BatchHandler-backed on-disk
    storage path keeps working; exposes Slog()/Handler() for the
    BatchHandler.SetLevel reload hook and tests that type-assert the
    underlying handler.
  - LuxfiAdapter wraps github.com/luxfi/log.Logger so packages that do
    not own the storage path can run on the canonical Lux logger
    directly.

Both adapters share the geth-style variadic API (msg + "k", v pairs)
that the prior commit already collapsed every call site to, so flipping
core.App.Logger() to return Logger in the next commit is a pure
type-narrowing change for ~95 percent of consumers.
2026-05-15 03:52:54 -07:00

42 lines
1.3 KiB
Go

package logger
import luxlog "github.com/luxfi/log"
// LuxfiAdapter wraps a github.com/luxfi/log.Logger so that it
// satisfies Logger. The luxfi/log API already uses the geth-style
// variadic key/value pairs, so the adapter is a thin pass-through.
type LuxfiAdapter struct {
l luxlog.Logger
}
// NewLuxfi wraps the given luxfi/log.Logger. Pass nil to fall back to
// the package default logger.
func NewLuxfi(l luxlog.Logger) *LuxfiAdapter {
if l == nil {
// luxlog.NewLogger needs a slog.Handler; for a no-arg adapter
// we lean on the package's discard handler.
l = luxlog.New()
}
return &LuxfiAdapter{l: l}
}
// Underlying returns the wrapped luxfi/log Logger.
func (a *LuxfiAdapter) Underlying() luxlog.Logger { return a.l }
// Debug logs at debug level.
func (a *LuxfiAdapter) Debug(msg string, kv ...any) { a.l.Debug(msg, kv...) }
// Info logs at info level.
func (a *LuxfiAdapter) Info(msg string, kv ...any) { a.l.Info(msg, kv...) }
// Warn logs at warn level.
func (a *LuxfiAdapter) Warn(msg string, kv ...any) { a.l.Warn(msg, kv...) }
// Error logs at error level.
func (a *LuxfiAdapter) Error(msg string, kv ...any) { a.l.Error(msg, kv...) }
// With returns a child logger seeded with the given key/value pairs.
func (a *LuxfiAdapter) With(kv ...any) Logger {
return &LuxfiAdapter{l: a.l.New(kv...)}
}