structlog_config#
Submodules#
- structlog_config.env_config
- structlog_config.factory
- structlog_config.fastapi_access_logger
- structlog_config.formatters
- structlog_config.hook
- structlog_config.levels
- structlog_config.pytest_plugin
- structlog_config.stdlib_logging
- structlog_config.tee
- structlog_config.trace
- structlog_config.version
- structlog_config.warnings
Classes#
A customized bound logger class that adds easy-to-remember methods for adding context. |
Functions#
|
Determine what the "final" processes in the pipeline should be to render the log to the output device. |
|
Return the default list of log processors for structlog configuration. |
|
|
|
Get a structlog logger with the same context alias methods as the logger returned by configure_logger. |
|
Create a structlog logger with some special additions: |
Package Contents#
- structlog_config.log_processors_for_mode(json_logger: bool) list[structlog.types.Processor][source]#
Determine what the “final” processes in the pipeline should be to render the log to the output device.
If JSON, then structure exceptions as dicts and render as JSON
If not JSON, then use the ConsoleRenderer with a nice exception formatter.
- structlog_config.get_default_processors(json_logger: bool) list[structlog.types.Processor][source]#
Return the default list of log processors for structlog configuration.
This includes any “final” processors to render the log as json or not.
- class structlog_config.LoggerWithContext[source]#
Bases:
structlog.typing.FilteringBoundLogger,ProtocolA customized bound logger class that adds easy-to-remember methods for adding context.
We don’t use a real subclass because make_filtering_bound_logger has some logic we don’t want to replicate.
- structlog_config.add_simple_context_aliases(log) LoggerWithContext[source]#
- structlog_config.get_logger(*args, **kwargs) LoggerWithContext[source]#
Get a structlog logger with the same context alias methods as the logger returned by configure_logger.
This is useful in cases where you want to get a logger without configuring it (e.g. in libraries or in tests).
- structlog_config.configure_logger(*, json_logger: bool = False, logger_factory=None, install_exception_hook: bool = False, finalize_configuration: bool = False, enable_tee: bool = False) LoggerWithContext[source]#
Create a structlog logger with some special additions:
>>> with log.context(key=value): >>> log.info("some message")
>>> log.local(key=value) >>> log.info("some message") >>> log.clear()
- Parameters:
json_logger – Flag to use JSON logging. Defaults to False.
logger_factory – Optional logger factory to override the default.
install_exception_hook – Optional flag to install a global exception hook that logs uncaught exceptions using structlog. Defaults to False.
finalize_configuration – If True, any subsequent calls to configure_logger will be ignored with a warning. Useful to setup logging and globally and prevent accidental reconfiguration by other developers.
enable_tee – Flag to enable context-scoped log teeing support (tee_logs). Defaults to False.