Documentation
¶
Index ¶
- Constants
- Variables
- func ConsoleColorLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func Crit(msg string, ctx ...interface{})
- func Crit0(msg string)
- func CritF(msg string, fields ...zap.Field)
- func Debug(msg string, ctx ...interface{})
- func Debug0(msg string)
- func DebugF(msg string, fields ...zap.Field)
- func DiscardHandler() slog.Handler
- func Error(msg string, ctx ...interface{})
- func Error0(msg string)
- func ErrorF(msg string, fields ...zap.Field)
- 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 Info0(msg string)
- func InfoF(msg string, fields ...zap.Field)
- 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 RegisterInternalPackages(pkgs ...string)
- func SetDefault(l Logger)
- func SetGlobalLogger(l Logger)
- func Trace(msg string, ctx ...interface{})
- func Trace0(msg string)
- func TraceF(msg string, fields ...zap.Field)
- func Warn(msg string, ctx ...interface{})
- func Warn0(msg string)
- func WarnF(msg string, fields ...zap.Field)
- func WriterAt(logger Logger, level slog.Level) io.Writer
- type ArrayMarshaler
- type Color
- type Config
- type Factory
- type Field
- func Array(key string, val ArrayMarshaler) Field
- func Durationp(key string, val *time.Duration) Field
- func Inline(val ObjectMarshaler) Field
- func Namespace(key string) Field
- func Object(key string, val ObjectMarshaler) Field
- func Reflect(key string, val interface{}) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Timep(key string, val *time.Time) Field
- func UserString(key, val string) Field
- func UserStrings(key string, vals []string) Field
- type Format
- 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 NoLog
- func (NoLog) Crit(msg string, ctx ...interface{})
- func (NoLog) Debug(msg string, ctx ...interface{})
- func (NoLog) Enabled(ctx context.Context, level slog.Level) bool
- func (NoLog) EnabledLevel(lvl slog.Level) bool
- func (NoLog) Error(msg string, ctx ...interface{})
- func (NoLog) Fatal(msg string, fields ...Field)
- func (NoLog) GetLevel() slog.Level
- func (NoLog) Handler() slog.Handler
- func (NoLog) Info(msg string, ctx ...interface{})
- func (NoLog) Log(level slog.Level, msg string, ctx ...interface{})
- func (NoLog) New(ctx ...interface{}) Logger
- func (NoLog) RecoverAndExit(f, exit func())
- func (NoLog) RecoverAndPanic(f func())
- func (NoLog) SetLevel(level slog.Level)
- func (NoLog) Stop()
- func (NoLog) StopOnPanic()
- func (NoLog) Trace(msg string, ctx ...interface{})
- func (NoLog) Verbo(msg string, fields ...Field)
- func (NoLog) Warn(msg string, ctx ...interface{})
- func (NoLog) With(ctx ...interface{}) Logger
- func (NoLog) WithFields(fields ...Field) Logger
- func (NoLog) WithOptions(opts ...Option) Logger
- func (NoLog) Write(p []byte) (n int, err error)
- func (NoLog) WriteLog(level slog.Level, msg string, attrs ...any)
- type ObjectMarshaler
- type Option
- type RotatingWriterConfig
- 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
- type WrappedCore
- func (c *WrappedCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (c *WrappedCore) Enabled(level zapcore.Level) bool
- func (c *WrappedCore) Sync() error
- func (c *WrappedCore) With(fields []zapcore.Field) zapcore.Core
- func (c *WrappedCore) Write(ent zapcore.Entry, fields []zapcore.Field) error
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 ¶
var ( // String constructs a field with the given key and value. String = zap.String // Strings constructs a field that carries a slice of strings. Strings = zap.Strings // Int constructs a field with the given key and value. Int = zap.Int // Int64 constructs a field with the given key and value. Int64 = zap.Int64 // Int32 constructs a field with the given key and value. Int32 = zap.Int32 // Int16 constructs a field with the given key and value. Int16 = zap.Int16 // Int8 constructs a field with the given key and value. Int8 = zap.Int8 // Uint constructs a field with the given key and value. Uint = zap.Uint // Uint64 constructs a field with the given key and value. Uint64 = zap.Uint64 // Uint32 constructs a field with the given key and value. Uint32 = zap.Uint32 // Uint16 constructs a field with the given key and value. Uint16 = zap.Uint16 // Uint8 constructs a field with the given key and value. Uint8 = zap.Uint8 // Uintptr constructs a field with the given key and value. Uintptr = zap.Uintptr // Float64 constructs a field with the given key and value. Float64 = zap.Float64 // Float32 constructs a field with the given key and value. Float32 = zap.Float32 // Bool constructs a field that carries a bool. Bool = zap.Bool // Any takes a key and an arbitrary value and chooses the best way to represent // them as a field, falling back to a reflection-based approach only if necessary. Any = zap.Any // Err is shorthand for the common idiom NamedError("error", err). Err = zap.Error // NamedError constructs a field that lazily stores err.Error() under the // provided key. Errors which also implement fmt.Formatter (like those produced // by github.com/pkg/errors) will also have their verbose representation stored // under key+"Verbose". If passed a nil error, the field is a no-op. NamedError = zap.NamedError // Skip constructs a no-op field, which is often useful when handling invalid // inputs in other Field constructors. Skip = zap.Skip // Binary constructs a field that carries an opaque binary blob. Binary = zap.Binary // ByteString constructs a field that carries UTF-8 encoded text as a []byte. // To log opaque binary blobs (which aren't necessarily valid UTF-8), use // Binary. ByteString = zap.ByteString // Complex128 constructs a field that carries a complex number. Unlike most // numeric fields, this costs an allocation (to convert the complex128 to // interface{}). Complex128 = zap.Complex128 // Complex64 constructs a field that carries a complex number. Unlike most // numeric fields, this costs an allocation (to convert the complex64 to // interface{}). Complex64 = zap.Complex64 // Duration constructs a field with the given key and value. The encoder // controls how the duration is serialized. Duration = zap.Duration // Time constructs a field with the given key and value. The encoder // controls how the time is serialized. Time = zap.Time // Stack constructs a field that stores a stacktrace of the current goroutine // under provided key. Keep in mind that taking a stacktrace is eager and // expensive (relatively speaking); this function both makes an allocation and // takes about two microseconds. Stack = zap.Stack // StackSkip constructs a field similarly to Stack, but also skips the given // number of frames from the top of the stacktrace. StackSkip = zap.StackSkip )
Field constructors - re-export commonly used ones from zap
var Discard io.WriteCloser = discard{}
Discard is a writer that discards all data
var ErrUnknownLevel = level.ErrUnknownLevel
Re-export level error
Functions ¶
func ConsoleColorLevelEncoder ¶ added in v0.1.1
func ConsoleColorLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
func Crit ¶
func Crit(msg string, ctx ...interface{})
Crit logs a message at critical level with context
func Debug ¶
func Debug(msg string, ctx ...interface{})
Debug logs a message at debug level with context
func Error ¶
func Error(msg string, ctx ...interface{})
Error logs a message at error level with context
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 Info ¶
func Info(msg string, ctx ...interface{})
Info logs a message at info level with context
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.
func RegisterInternalPackages ¶ added in v1.0.5
func RegisterInternalPackages(pkgs ...string)
RegisterInternalPackages lets applications add package prefixes that should be treated as "internal" (wrappers, adapters, etc.). Calls are concurrency-safe.
func SetGlobalLogger ¶ added in v0.1.1
func SetGlobalLogger(l Logger)
SetGlobalLogger sets the global logger used by package-level functions
func Trace ¶
func Trace(msg string, ctx ...interface{})
Trace logs a message at trace level with context
func Warn ¶
func Warn(msg string, ctx ...interface{})
Warn logs a message at warn level with context
Types ¶
type ArrayMarshaler ¶ added in v1.0.3
type ArrayMarshaler = zapcore.ArrayMarshaler
ArrayMarshaler is an alias for zapcore.ArrayMarshaler
type Color ¶ added in v0.1.1
type Color string
Color represents ANSI color codes
const ( Black Color = "\033[0;30m" DarkGray Color = "\033[1;30m" Red Color = "\033[0;31m" LightRed Color = "\033[1;31m" Green Color = "\033[0;32m" LightGreen Color = "\033[1;32m" Orange Color = "\033[0;33m" Yellow Color = "\033[1;33m" Blue Color = "\033[0;34m" LightBlue Color = "\033[1;34m" Purple Color = "\033[0;35m" LightPurple Color = "\033[1;35m" Cyan Color = "\033[0;36m" LightCyan Color = "\033[1;36m" LightGray Color = "\033[0;37m" White Color = "\033[1;37m" Reset Color = "\033[0;0m" Bold Color = "\033[;1m" Reverse Color = "\033[;7m" )
Colors
type Config ¶ added in v0.1.1
type Config struct { RotatingWriterConfig DisableWriterDisplaying bool `json:"disableWriterDisplaying"` LogLevel Level `json:"logLevel"` DisplayLevel Level `json:"displayLevel"` LogFormat Format `json:"logFormat"` MsgPrefix string `json:"-"` LoggerName string `json:"-"` }
Config defines the configuration of a logger
func DefaultConfig ¶ added in v0.1.1
func DefaultConfig() Config
DefaultConfig returns a default configuration for the logger factory
type Factory ¶
type Factory interface { // Make creates a new logger with name [name] Make(name string) (Logger, error) // MakeChain creates a new logger to log the events of chain [chainID] MakeChain(chainID string) (Logger, error) // SetLogLevel sets log levels for all loggers in factory with given logger name, level pairs. SetLogLevel(name string, level Level) error // SetDisplayLevel sets log display levels for all loggers in factory with given logger name, level pairs. SetDisplayLevel(name string, level Level) error // GetLogLevel returns all log levels in factory as name, level pairs GetLogLevel(name string) (Level, error) // GetDisplayLevel returns all log display levels in factory as name, level pairs GetDisplayLevel(name string) (Level, error) // GetLoggerNames returns the names of all logs created by this factory GetLoggerNames() []string // Close stops and clears all of a Factory's instantiated loggers Close() // Legacy methods for compatibility New(name string) Logger NewWithFields(name string, fields ...zap.Field) Logger }
Factory interface for creating loggers - extended version with all methods needed by node
func NewFactoryWithConfig ¶ added in v0.1.1
NewFactory creates a new logger factory with config
func NewSimpleFactory ¶ added in v0.1.1
NewSimpleFactory creates a simple logger factory from zap config This is a convenience function for simple use cases
type Field ¶
Field is an alias for zap.Field for structured logging
func Array ¶ added in v1.0.3
func Array(key string, val ArrayMarshaler) Field
Array constructs a field with the given key and ArrayMarshaler. It provides a flexible, but still type-safe and efficient, way to add array-like types to the logging context. The struct's MarshalLogArray method is called lazily.
func Durationp ¶ added in v1.0.3
Durationp constructs a field that carries a *time.Duration. The returned Field will safely and explicitly represent `nil` when appropriate.
func Inline ¶ added in v1.0.3
func Inline(val ObjectMarshaler) Field
Inline constructs a Field that is similar to Object, but it will add the elements of the provided ObjectMarshaler to the current namespace.
func Namespace ¶ added in v1.0.3
Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.
This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.
func Object ¶ added in v1.0.3
func Object(key string, val ObjectMarshaler) Field
Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.
func Reflect ¶ added in v1.0.3
Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.
func Stringer ¶ added in v0.1.1
Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.
func Timep ¶ added in v1.0.3
Timep constructs a field that carries a *time.Time. The returned Field will safely and explicitly represent `nil` when appropriate.
func UserString ¶ added in v0.1.1
UserString creates a field for user-provided strings that may need sanitization
func UserStrings ¶ added in v0.1.1
UserStrings creates a field for user-provided string slices that may need sanitization
type Format ¶ added in v0.1.1
type Format int
Format specifies the log format
func (Format) ConsoleEncoder ¶ added in v0.1.1
ConsoleEncoder returns a zapcore.Encoder for console output
func (Format) FileEncoder ¶ added in v0.1.1
FileEncoder returns a zapcore.Encoder for file output
func (Format) MarshalJSON ¶ added in v0.1.1
MarshalJSON marshals Format to JSON
func (Format) WrapPrefix ¶ added in v0.1.1
WrapPrefix adds a prefix to messages if non-empty
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 ...Field) Verbo(msg string, fields ...Field) WithFields(fields ...Field) Logger WithOptions(opts ...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 New ¶
func New(ctx ...interface{}) Logger
New creates a new logger with the given context (alias for With)
func NewLogger ¶
func NewLogger(prefix string, wrappedCores ...WrappedCore) Logger
NewLogger creates a logger with custom cores
func NewNoOpLogger ¶
func NewNoOpLogger() Logger
NewNoOpLogger creates a logger that discards all output
func NewTestLogger ¶ added in v0.1.1
NewTestLogger creates a logger suitable for testing
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 NoLog ¶ added in v1.0.3
type NoLog struct{}
NoLog is a no-op logger for testing
func (NoLog) RecoverAndExit ¶ added in v1.0.3
func (NoLog) RecoverAndExit(f, exit func())
func (NoLog) RecoverAndPanic ¶ added in v1.0.3
func (NoLog) RecoverAndPanic(f func())
func (NoLog) StopOnPanic ¶ added in v1.0.3
func (NoLog) StopOnPanic()
func (NoLog) WithFields ¶ added in v1.0.3
func (NoLog) WithOptions ¶ added in v1.0.3
type ObjectMarshaler ¶ added in v1.0.3
type ObjectMarshaler = zapcore.ObjectMarshaler
ObjectMarshaler is an alias for zapcore.ObjectMarshaler
type RotatingWriterConfig ¶ added in v0.1.1
type RotatingWriterConfig struct { MaxSize int `json:"maxSize"` // in megabytes MaxFiles int `json:"maxFiles"` MaxAge int `json:"maxAge"` // in days Directory string `json:"directory"` Compress bool `json:"compress"` }
RotatingWriterConfig defines rotating log file configuration
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.
type WrappedCore ¶ added in v0.1.1
type WrappedCore struct { zapcore.Core AtomicLevel zap.AtomicLevel Writer zapcore.WriteSyncer WriterDisabled bool }
WrappedCore wraps a zapcore.Core with additional functionality
func NewWrappedCore ¶ added in v0.1.1
func NewWrappedCore(lvl Level, writer zapcore.WriteSyncer, encoder zapcore.Encoder) *WrappedCore
NewWrappedCore creates a wrapped core with atomic level
func (*WrappedCore) Check ¶ added in v0.1.1
func (c *WrappedCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
Check implements zapcore.Core
func (*WrappedCore) Enabled ¶ added in v0.1.1
func (c *WrappedCore) Enabled(level zapcore.Level) bool
Enabled implements zapcore.Core
func (*WrappedCore) Sync ¶ added in v0.1.1
func (c *WrappedCore) Sync() error
Sync implements zapcore.Core