structlog API reference
127 public APIs from structlog (hynek/structlog) — 40 classes, 27 functions, 60 methods. Signatures extracted by static analysis of the actual source.
Repository: hynek/structlog
| Kind | Count |
|---|---|
| Classes | 40 |
| Functions | 27 |
| Methods | 60 |
API list
class
src.structlog._base.BoundLoggerBaseImmutable context carrier.
method
src.structlog._base.BoundLoggerBase.bind(**new_values:Any) -> SelfReturn a new logger with *new_values* added to the existing ones.
method
src.structlog._base.BoundLoggerBase.new(**new_values:Any) -> SelfClear context and binds *new_values* using `bind`.
method
src.structlog._base.BoundLoggerBase.try_unbind(*keys:str) -> SelfLike :meth:`unbind`, but best effort: missing keys are ignored.
method
src.structlog._base.BoundLoggerBase.unbind(*keys:str) -> SelfReturn a new logger with *keys* removed from the context.
func
src.structlog._base.get_context(bound_logger:BindableLogger) -> ContextReturn *bound_logger*'s context.
class
src.structlog._config.BoundLoggerLazyProxyInstantiates a bound logger on first usage.
method
src.structlog._config.BoundLoggerLazyProxy.bind(**new_values:Any) -> BindableLoggerAssemble a new BoundLogger from arguments and configuration.
func
src.structlog._config.BoundLoggerLazyProxy.finalized_bind(**new_values:Any) -> BindableLoggerUse cached assembled logger to bind potentially new values.
method
src.structlog._config.BoundLoggerLazyProxy.new(**new_values:Any) -> BindableLoggerClear context, then bind.
method
src.structlog._config.BoundLoggerLazyProxy.unbind(*keys:str) -> BindableLoggerSame as bind, except unbind *keys* first.
func
src.structlog._config.get_config() -> dict[str, Any]Get a dictionary with the current configuration.
func
src.structlog._config.get_logger(*args:Any, **initial_values:Any) -> AnyConvenience function that returns a logger according to configuration.
func
src.structlog._config.is_configured() -> boolReturn whether *structlog* has been configured.
func
src.structlog._config.reset_defaults() -> NoneResets global default values to builtin defaults.
class
src.structlog._generic.BoundLoggerA generic BoundLogger that can wrap anything.
class
src.structlog._greenlets.GreenThreadLocalthreading.local() replacement for greenlets.
func
src.structlog._native.aexception(self:FilteringBoundLogger, event:str, *args:Any, **kw:Any) -> Any..
func
src.structlog._native.alog(self:Any, level:int, event:str, *args:Any, **kw:Any) -> Any..
func
src.structlog._native.ameth(self:Any, event:str, *args:Any, **kw:Any) -> Any..
class
src.structlog._output.BytesLoggerWrites bytes into a file.
method
src.structlog._output.BytesLogger.msg(message:bytes) -> NoneWrite *message*.
class
src.structlog._output.BytesLoggerFactoryProduce `BytesLogger`\ s.
class
src.structlog._output.PrintLoggerPrint events into a file.
method
src.structlog._output.PrintLogger.msg(message:str) -> NonePrint *message*.
class
src.structlog._output.PrintLoggerFactoryProduce `PrintLogger`\ s.
class
src.structlog._output.WriteLoggerWrite events into a file.
method
src.structlog._output.WriteLogger.msg(message:str) -> NoneWrite and flush *message*.
class
src.structlog._output.WriteLoggerFactoryProduce `WriteLogger`\ s.
func
src.structlog.contextvars.bind_contextvars(**kw:Any) -> Mapping[str, contextvars.Token[Any]]Put keys and values into the context-local context.
func
src.structlog.contextvars.bound_contextvars(**kw:Any) -> Generator[None, None, None]Bind *kw* to the current context-local context.
func
src.structlog.contextvars.clear_contextvars() -> NoneClear the context-local context.
func
src.structlog.contextvars.reset_contextvars(**kw:contextvars.Token[Any]) -> NoneReset contextvars corresponding to the given Tokens.
func
src.structlog.contextvars.unbind_contextvars(*keys:str) -> NoneRemove *keys* from the context-local context if they are present.
class
src.structlog.dev.ColumnFormatter:class:`~typing.Protocol` for column formatters.
class
src.structlog.dev.ColumnStylesColumn styles settings for console rendering.
class
src.structlog.dev.KeyValueColumnFormatterFormat a key-value pair.
class
src.structlog.dev.LogLevelColumnFormatterFormat a log level according to *level_styles*.
class
src.structlog.dev.RichTracebackFormatterA Rich traceback renderer with the given options.
func
src.structlog.dev.plain_traceback(sio:TextIO, exc_info:ExcInfo) -> None"Pretty"-print *exc_info* to *sio* using our own plain formatter.
class
src.structlog.exceptions.DropEventIf raised by an processor, the event gets silently dropped.
class
src.structlog.processors.EventRenamerRename the ``event`` key in event dicts.
class
src.structlog.processors.LogfmtRendererRender ``event_dict`` using the logfmt_ format.
class
src.structlog.processors.MaybeTimeStamperA timestamper that only adds a timestamp if there is none.
class
src.structlog.processors.TimeStamperAdd a timestamp to ``event_dict``.
class
src.structlog.processors.UnicodeDecoderDecode byte string values in ``event_dict``.
class
src.structlog.processors.UnicodeEncoderEncode unicode values in ``event_dict``.
class
src.structlog.stdlib.BoundLoggerPython Standard Library version of `structlog.BoundLogger`.
method
src.structlog.stdlib.BoundLogger.acritical(event:str, *args:Any, **kw:Any) -> NoneLog using `critical()`, but asynchronously in a separate thread.
method
src.structlog.stdlib.BoundLogger.addHandler(hdlr:logging.Handler) -> NoneCalls :meth:`logging.Logger.addHandler` with unmodified arguments.
method
src.structlog.stdlib.BoundLogger.adebug(event:str, *args:Any, **kw:Any) -> NoneLog using `debug()`, but asynchronously in a separate thread.
method
src.structlog.stdlib.BoundLogger.aerror(event:str, *args:Any, **kw:Any) -> NoneLog using `error()`, but asynchronously in a separate thread.
method
src.structlog.stdlib.BoundLogger.afatal(event:str, *args:Any, **kw:Any) -> NoneLog using `critical()`, but asynchronously in a separate thread.
method
src.structlog.stdlib.BoundLogger.ainfo(event:str, *args:Any, **kw:Any) -> NoneLog using `info()`, but asynchronously in a separate thread.
method
src.structlog.stdlib.BoundLogger.alog(level:Any, event:str, *args:Any, **kw:Any) -> NoneLog using `log()`, but asynchronously in a separate thread.
method
src.structlog.stdlib.BoundLogger.awarning(event:str, *args:Any, **kw:Any) -> NoneLog using `warning()`, but asynchronously in a separate thread.
method
src.structlog.stdlib.BoundLogger.bind(**new_values:Any) -> SelfReturn a new logger with *new_values* added to the existing ones.
method
src.structlog.stdlib.BoundLogger.debug(event:str | None=None, *args:Any, **kw:Any) -> AnyProcess event and call `logging.Logger.debug` with the result.
method
src.structlog.stdlib.BoundLogger.disabled() -> intReturns :attr:`logging.Logger.disabled`
method
src.structlog.stdlib.BoundLogger.error(event:str | None=None, *args:Any, **kw:Any) -> AnyProcess event and call `logging.Logger.error` with the result.
method
src.structlog.stdlib.BoundLogger.getChild(suffix:str) -> logging.LoggerCalls :meth:`logging.Logger.getChild` with unmodified arguments.
method
src.structlog.stdlib.BoundLogger.handle(record:logging.LogRecord) -> NoneCalls :meth:`logging.Logger.handle` with unmodified arguments.
method
src.structlog.stdlib.BoundLogger.handlers() -> AnyReturns :attr:`logging.Logger.handlers`
method
src.structlog.stdlib.BoundLogger.info(event:str | None=None, *args:Any, **kw:Any) -> AnyProcess event and call `logging.Logger.info` with the result.
method
src.structlog.stdlib.BoundLogger.isEnabledFor(level:int) -> boolCalls :meth:`logging.Logger.isEnabledFor` with unmodified arguments.
method
src.structlog.stdlib.BoundLogger.level() -> intReturns :attr:`logging.Logger.level`
method
src.structlog.stdlib.BoundLogger.name() -> strReturns :attr:`logging.Logger.name`
method
src.structlog.stdlib.BoundLogger.new(**new_values:Any) -> SelfClear context and binds *initial_values* using `bind`.
method
src.structlog.stdlib.BoundLogger.parent() -> AnyReturns :attr:`logging.Logger.parent`
method
src.structlog.stdlib.BoundLogger.propagate() -> boolReturns :attr:`logging.Logger.propagate`
method
src.structlog.stdlib.BoundLogger.setLevel(level:int) -> NoneCalls :meth:`logging.Logger.setLevel` with unmodified arguments.
method
src.structlog.stdlib.BoundLogger.try_unbind(*keys:str) -> SelfLike :meth:`unbind`, but best effort: missing keys are ignored.
method
src.structlog.stdlib.BoundLogger.unbind(*keys:str) -> SelfReturn a new logger with *keys* removed from the context.
class
src.structlog.stdlib.LoggerFactoryBuild a standard library logger when an *instance* is called.
class
src.structlog.stdlib.PositionalArgumentsFormatterApply stdlib-like string formatting to the ``event`` key.
class
src.structlog.stdlib.ProcessorFormatterCall *structlog* processors on `logging.LogRecord`\s.
func
src.structlog.stdlib.add_log_level_number(logger:logging.Logger, method_name:str, event_dict:EventDict) -> EventDictAdd the log level number to the event dict.
func
src.structlog.stdlib.add_logger_name(logger:logging.Logger, method_name:str, event_dict:EventDict) -> EventDictAdd the logger name to the event dict.
func
src.structlog.stdlib.recreate_defaults(*log_level:int | None=logging.NOTSET) -> NoneRecreate defaults on top of standard library's logging.
class
src.structlog.testing.CapturedCallA call as captured by `CapturingLogger`.
class
src.structlog.testing.CapturingLoggerStore the method calls that it's been called with.
class
src.structlog.testing.CapturingLoggerFactoryProduce and cache `CapturingLogger`\ s.
class
src.structlog.testing.LogCaptureClass for capturing log messages in its entries list.
class
src.structlog.testing.ReturnLoggerReturn the arguments that it's called with.
class
src.structlog.testing.ReturnLoggerFactoryProduce and cache `ReturnLogger`\ s.
func
src.structlog.threadlocal.bind_threadlocal(**kw:Any) -> NonePut keys and values into the thread-local context.
func
src.structlog.threadlocal.bound_threadlocal(**kw:Any) -> Generator[None, None, None]Bind *kw* to the current thread-local context.
func
src.structlog.threadlocal.clear_threadlocal() -> NoneClear the thread-local context.
func
src.structlog.threadlocal.get_threadlocal() -> ContextReturn a copy of the current thread-local context.
func
src.structlog.threadlocal.tmp_bind(logger:TLLogger, **tmp_values:Any) -> Generator[TLLogger, None, None]Bind *tmp_values* to *logger* & memorize current state.
func
src.structlog.threadlocal.wrap_dict(dict_class:type[Context]) -> type[Context]Wrap a dict-like class and return the resulting class.
class
src.structlog.tracebacks.FrameRepresents a single stack frame.
class
src.structlog.tracebacks.StackRepresents an exception and a list of stack frames.
class
src.structlog.tracebacks.TraceContainer for a list of stack traces.
func
src.structlog.tracebacks.get_locals(iter_locals:Iterable[tuple[str, object]]) -> Iterable[tuple[str, object]]Extract locals from an iterator of key pairs.
func
src.structlog.tracebacks.safe_str(_object:Any) -> strDon't allow exceptions from __str__ to propagate.
func
src.structlog.tracebacks.to_repr(obj:Any, max_length:int | None=None, max_string:int | None=None, use_rich:bool=True) -> strGet repr string for an object, but catch errors.
class
src.structlog.twisted.BoundLoggerTwisted-specific version of `structlog.BoundLogger`.
method
src.structlog.twisted.BoundLogger.err(event:str | None=None, **kw:Any) -> AnyProcess event and call ``log.err()`` with the result.
method
src.structlog.twisted.BoundLogger.msg(event:str | None=None, **kw:Any) -> AnyProcess event and call ``log.msg()`` with the result.
class
src.structlog.twisted.EventAdapterAdapt an ``event_dict`` to Twisted logging system.
class
src.structlog.twisted.LoggerFactoryBuild a Twisted logger when an *instance* is called.
class
src.structlog.twisted.ReprWrapperWrap a string and return it as the ``__repr__``.
class
src.structlog.typing.FilteringBoundLogger**Protocol**: A `BindableLogger` that filters by a level.
method
src.structlog.typing.FilteringBoundLogger.acritical(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **critical** level.
method
src.structlog.typing.FilteringBoundLogger.adebug(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **debug** level.
method
src.structlog.typing.FilteringBoundLogger.aerror(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **error** level.
method
src.structlog.typing.FilteringBoundLogger.afatal(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **critical** level.
method
src.structlog.typing.FilteringBoundLogger.ainfo(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **info** level.
method
src.structlog.typing.FilteringBoundLogger.alog(level:int, event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at *level*.
method
src.structlog.typing.FilteringBoundLogger.amsg(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **info** level.
method
src.structlog.typing.FilteringBoundLogger.awarn(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **warn** level.
method
src.structlog.typing.FilteringBoundLogger.awarning(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **warn** level.
method
src.structlog.typing.FilteringBoundLogger.critical(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **critical** level.
method
src.structlog.typing.FilteringBoundLogger.debug(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **debug** level.
method
src.structlog.typing.FilteringBoundLogger.err(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **error** level.
method
src.structlog.typing.FilteringBoundLogger.error(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **error** level.
method
src.structlog.typing.FilteringBoundLogger.fatal(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **critical** level.
method
src.structlog.typing.FilteringBoundLogger.get_effective_level() -> intReturn the effective level of the logger.
method
src.structlog.typing.FilteringBoundLogger.info(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **info** level.
method
src.structlog.typing.FilteringBoundLogger.is_enabled_for(level:int) -> boolCheck whether the logger is enabled for *level*.
method
src.structlog.typing.FilteringBoundLogger.log(level:int, event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at *level*.
method
src.structlog.typing.FilteringBoundLogger.msg(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **info** level.
method
src.structlog.typing.FilteringBoundLogger.new(**new_values:Any) -> FilteringBoundLoggerClear context and binds *initial_values* using `bind`.
method
src.structlog.typing.FilteringBoundLogger.unbind(*keys:str) -> FilteringBoundLoggerReturn a new logger with *keys* removed from the context.
method
src.structlog.typing.FilteringBoundLogger.warn(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **warn** level.
method
src.structlog.typing.FilteringBoundLogger.warning(event:str, *args:Any, **kw:Any) -> AnyLog ``event % args`` with **kw** at **warn** level.
About this data
These signatures were extracted from the public source of hynek/structlog
using Python's ast module. Argument names, default values,
type annotations and return types are taken verbatim from the code.
Implementation bodies are never stored. See
how it works for details.