Documentation
¶
Index ¶
- Constants
- func Crit(msg string, ctx ...interface{})
- func Debug(msg string, ctx ...interface{})
- func DiscardHandler() slog.Handler
- func Error(msg string, ctx ...interface{})
- func FormatLogfmtUint64(n uint64) string
- func FormatSlogValue(v slog.Value, tmp []byte) (result []byte)
- func FromLegacyLevel(lvl int) slog.Level
- func Info(msg string, ctx ...interface{})
- func JSONHandler(wr io.Writer) slog.Handler
- func JSONHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler
- func LevelAlignedString(l slog.Level) string
- func LevelString(l slog.Level) string
- func LogfmtHandler(wr io.Writer) slog.Handler
- func LogfmtHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler
- func SetDefault(l Logger)
- func Trace(msg string, ctx ...interface{})
- func Warn(msg string, ctx ...interface{})
- func WriterAt(logger Logger, level slog.Level) io.Writer
- type Factory
- type Field
- type GlogHandler
- func (g *GlogHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (g *GlogHandler) Handle(ctx context.Context, r slog.Record) error
- func (g *GlogHandler) Verbosity(v slog.Level)
- func (g *GlogHandler) Vmodule(spec string) error
- func (g *GlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (g *GlogHandler) WithGroup(name string) slog.Handler
- type Level
- type Logger
- type LoggerWriter
- type TerminalHandler
- func (h *TerminalHandler) Enabled(_ context.Context, level slog.Level) bool
- func (h *TerminalHandler) Handle(_ context.Context, r slog.Record) error
- func (h *TerminalHandler) ResetFieldPadding()
- func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *TerminalHandler) WithGroup(name string) slog.Handler
- type TerminalStringer
Constants ¶
const ( LevelTrace slog.Level = -8 LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError LevelCrit slog.Level = 12 LevelFatal slog.Level = 16 // Added for Fatal LevelVerbo slog.Level = -10 // Added for Verbo (most verbose) )
Re-export slog levels for compatibility
const ( // DebugLevel logs debug messages. DebugLevel = LevelDebug // InfoLevel logs informational messages. InfoLevel = LevelInfo // WarnLevel logs warning messages. WarnLevel = LevelWarn // ErrorLevel logs error messages. ErrorLevel = LevelError // FatalLevel logs critical messages and exits. FatalLevel = LevelCrit )
Level aliases for convenience.
Variables ¶
This section is empty.
Functions ¶
func FormatLogfmtUint64 ¶
FormatLogfmtUint64 formats n with thousand separators.
func FormatSlogValue ¶
FormatSlogValue formats a slog.Value for serialization to terminal.
func FromLegacyLevel ¶
FromLegacyLevel converts from old Geth verbosity level constants to levels defined by slog
func JSONHandler ¶
JSONHandler returns a handler which prints records in JSON format.
func JSONHandlerWithLevel ¶
JSONHandlerWithLevel returns a handler which prints records in JSON format that are less than or equal to the specified verbosity level.
func LevelAlignedString ¶
LevelAlignedString returns a 5-character aligned string for the level
func LevelString ¶
LevelString returns a string representation of the level
func LogfmtHandler ¶
LogfmtHandler returns a handler which prints records in logfmt format, an easy machine-parseable but human-readable format for key/value pairs.
For more details see: http://godoc.org/github.com/kr/logfmt
func LogfmtHandlerWithLevel ¶
LogfmtHandlerWithLevel returns the same handler as LogfmtHandler but it only outputs records which are less than or equal to the specified verbosity level.
Types ¶
type Factory ¶
type Factory interface {
New(name string) Logger
NewWithFields(name string, fields ...zap.Field) Logger
}
Factory interface for creating loggers
func NewFactory ¶
NewFactory creates a new logger factory
type GlogHandler ¶
type GlogHandler struct {
// contains filtered or unexported fields
}
GlogHandler wraps a slog.Handler to provide glog-style verbosity and vmodule filtering.
func NewGlogHandler ¶
func NewGlogHandler(h slog.Handler) *GlogHandler
NewGlogHandler returns a Handler that filters records according to glog-style severity and verbosity settings. By default, it logs messages with level >= LevelInfo and suppresses verbose logs (levels < LevelInfo) until Verbosity is called.
func (*GlogHandler) Enabled ¶
Enabled reports whether records at the given level should be logged or passed to Handle for further verbose filtering.
func (*GlogHandler) Handle ¶
Handle filters the record according to severity and verbosity (including vmodule) and forwards it to the underlying handler if allowed.
func (*GlogHandler) Verbosity ¶
func (g *GlogHandler) Verbosity(v slog.Level)
Verbosity sets both the minimum severity and default verbosity levels. Messages with level >= v will be logged as severity; messages with level < LevelInfo will be logged if their level <= v.
func (*GlogHandler) Vmodule ¶
func (g *GlogHandler) Vmodule(spec string) error
Vmodule sets a per-file verbosity level according to the spec string of the form "pattern=level". Multiple specs may be comma-separated.
type Logger ¶
type Logger interface {
// Original geth-style methods
With(ctx ...interface{}) Logger
New(ctx ...interface{}) Logger
Log(level slog.Level, msg string, ctx ...interface{})
Trace(msg string, ctx ...interface{})
Debug(msg string, ctx ...interface{})
Info(msg string, ctx ...interface{})
Warn(msg string, ctx ...interface{})
Error(msg string, ctx ...interface{})
Crit(msg string, ctx ...interface{})
WriteLog(level slog.Level, msg string, attrs ...any)
Enabled(ctx context.Context, level slog.Level) bool
Handler() slog.Handler
// Additional methods for node compatibility
Fatal(msg string, fields ...zap.Field)
Verbo(msg string, fields ...zap.Field)
WithFields(fields ...zap.Field) Logger
WithOptions(opts ...zap.Option) Logger
SetLevel(level slog.Level)
GetLevel() slog.Level
EnabledLevel(lvl slog.Level) bool
StopOnPanic()
RecoverAndPanic(f func())
RecoverAndExit(f, exit func())
Stop()
// io.Writer
io.Writer
}
Logger interface that supports both the geth-style interface and zap fields
func NewNoOpLogger ¶
func NewNoOpLogger() Logger
NewNoOpLogger creates a logger that discards all output
func NewZapLogger ¶
NewZapLogger creates a logger directly from a zap logger
type LoggerWriter ¶
type LoggerWriter struct {
// contains filtered or unexported fields
}
LoggerWriter wraps a Logger to provide io.Writer interface
type TerminalHandler ¶
type TerminalHandler struct {
// contains filtered or unexported fields
}
func NewTerminalHandler ¶
func NewTerminalHandler(wr io.Writer, useColor bool) *TerminalHandler
NewTerminalHandler returns a handler which formats log records at all levels optimized for human readability on a terminal with color-coded level output and terser human friendly timestamp. This format should only be used for interactive programs or while developing.
[LEVEL] [TIME] MESSAGE key=value key=value ...
Example:
[DBUG] [May 16 20:58:45] remove route ns=haproxy addr=127.0.0.1:50002
func NewTerminalHandlerWithLevel ¶
NewTerminalHandlerWithLevel returns the same handler as NewTerminalHandler but only outputs records which are less than or equal to the specified verbosity level.
func (*TerminalHandler) ResetFieldPadding ¶
func (h *TerminalHandler) ResetFieldPadding()
ResetFieldPadding zeroes the field-padding for all attribute pairs.
type TerminalStringer ¶
type TerminalStringer interface {
TerminalString() string
}
TerminalStringer is an analogous interface to the stdlib stringer, allowing own types to have custom shortened serialization formats when printed to the screen.