silkworm.logging
Structured logging interfaces and configuration helpers for Silkworm.
Log records accept arbitrary keyword context. The shared logger defaults to
stderr and reads SILKWORM_LOG_LEVEL the first time it is requested.
-
class silkworm.logging.Logger[source]
Bases: Protocol
Structured logger returned by get_logger() and Spider.log.
Keyword arguments become structured context fields on each record.
-
configure(*, handlers=None)[source]
Replace the logger’s handlers with the supplied configurations.
Each handler mapping accepts sink, level, serialize, and
colorize. A sink may be "stderr", "stdout", a filesystem
path, or a writable text stream.
- Parameters:
handlers (list[dict[str, object]] | None)
- Return type:
None
-
bind(**context)[source]
Return a logger carrying context on every subsequent record.
- Parameters:
context (object)
- Return type:
Logger
-
info(message, **context)[source]
Emit an informational record with structured context.
- Parameters:
-
- Return type:
None
-
debug(message, **context)[source]
Emit a diagnostic record with structured context.
- Parameters:
-
- Return type:
None
-
warning(message, **context)[source]
Emit a warning record with structured context.
- Parameters:
-
- Return type:
None
-
error(message, **context)[source]
Emit an error record with structured context.
- Parameters:
-
- Return type:
None
-
exception(message, **context)[source]
Emit an error record including the active exception traceback.
- Parameters:
-
- Return type:
None
-
complete()[source]
Flush all configured handlers.
- Return type:
None
-
__init__(*args, **kwargs)
-
silkworm.logging.complete_logs()[source]
Flush configured log handlers if logging has been initialized.
- Return type:
None
-
silkworm.logging.get_logger(**context)[source]
Return the shared structured logger, optionally bound to context.
The first call configures stderr output using SILKWORM_LOG_LEVEL.
Bound context is copied into every record without mutating the shared base
logger.
- Parameters:
context (object)
- Return type:
Logger
-
silkworm.logging.log_at_level(logger, level, message, **context)[source]
Emit a log message at a caller-selected level.
Passing None intentionally suppresses the message. That escape hatch is
useful for very noisy per-item paths, but should be used sparingly.
- Parameters:
logger (Logger)
level (Literal['TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL', 'FAIL'] | ~typing.Literal['WARN', 'ERR', 'FATAL'] | None)
message (str)
context (object)
- Return type:
None