go-p2p/specs/logging.md
Virgil 2d63a8ba18
Some checks failed
Security Scan / security (push) Successful in 9s
Test / test (push) Failing after 52s
refactor(node): add AX-native aliases for component and path APIs
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-30 19:32:26 +00:00

4.5 KiB

logging

Import: dappco.re/go/core/p2p/logging

Files: 1

Types

Level

type Level int

Log severity used by Logger. String renders the level name in upper case, and ParseLevel accepts debug, info, warn or warning, and error.

Config

type Config struct {
	Output    io.Writer
	Level     Level
	Component string
}

Configuration passed to New.

  • Output: destination for log lines. New falls back to stderr when this is nil.
  • Level: minimum severity that will be emitted.
  • Component: optional component label added to each line.

Fields

type Fields map[string]any

Structured key/value fields passed to logging calls. When multiple Fields values are supplied, they are merged from left to right, so later maps override earlier keys.

Logger

type Logger struct { /* unexported fields */ }

Structured logger with configurable output, severity filtering, and component scoping. Log writes are serialised by a mutex and are formatted as timestamped single-line records.

Functions

Top-level

Name Signature Description
DefaultConfig func DefaultConfig() Config Returns the default configuration: stderr output, LevelInfo, and no component label.
New func New(cfg Config) *Logger Creates a Logger from cfg, substituting the default stderr writer when cfg.Output is nil.
SetGlobal func SetGlobal(l *Logger) Replaces the package-level global logger instance.
GetGlobal func GetGlobal() *Logger Returns the current package-level global logger.
SetGlobalLevel func SetGlobalLevel(level Level) Updates the minimum severity on the current global logger.
Debug func Debug(msg string, fields ...Fields) Logs a debug message through the global logger.
Info func Info(msg string, fields ...Fields) Logs an informational message through the global logger.
Warn func Warn(msg string, fields ...Fields) Logs a warning message through the global logger.
Error func Error(msg string, fields ...Fields) Logs an error message through the global logger.
Debugf func Debugf(format string, args ...any) Formats and logs a debug message through the global logger.
Infof func Infof(format string, args ...any) Formats and logs an informational message through the global logger.
Warnf func Warnf(format string, args ...any) Formats and logs a warning message through the global logger.
Errorf func Errorf(format string, args ...any) Formats and logs an error message through the global logger.
ParseLevel func ParseLevel(s string) (Level, error) Parses a text level into Level. Unknown strings return LevelInfo plus an error.

Level methods

Name Signature Description
String func (l Level) String() string Returns DEBUG, INFO, WARN, ERROR, or UNKNOWN for out-of-range values.

*Logger methods

Name Signature Description
ComponentLogger func (l *Logger) ComponentLogger(component string) *Logger Returns a new logger scoped to component. Preferred over WithComponent.
WithComponent func (l *Logger) WithComponent(component string) *Logger Deprecated compatibility alias for ComponentLogger.
SetLevel func (l *Logger) SetLevel(level Level) Sets the minimum severity that the logger will emit.
GetLevel func (l *Logger) GetLevel() Level Returns the current minimum severity.
Debug func (l *Logger) Debug(msg string, fields ...Fields) Logs msg at debug level after merging any supplied field maps.
Info func (l *Logger) Info(msg string, fields ...Fields) Logs msg at info level after merging any supplied field maps.
Warn func (l *Logger) Warn(msg string, fields ...Fields) Logs msg at warning level after merging any supplied field maps.
Error func (l *Logger) Error(msg string, fields ...Fields) Logs msg at error level after merging any supplied field maps.
Debugf func (l *Logger) Debugf(format string, args ...any) Formats and logs a debug message.
Infof func (l *Logger) Infof(format string, args ...any) Formats and logs an informational message.
Warnf func (l *Logger) Warnf(format string, args ...any) Formats and logs a warning message.
Errorf func (l *Logger) Errorf(format string, args ...any) Formats and logs an error message.