Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions microbootstrap/instruments/logging_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def fill_log_message(
http_version: typing.Final = request.scope["http_version"]
log_on_correct_level: typing.Final = getattr(access_logger, log_level)
log_on_correct_level(
f"{http_method} {url_with_query}",
http={
"url": url_with_query,
"status_code": status_code,
Expand Down Expand Up @@ -146,10 +147,10 @@ def remove_trailing_slashes_from_logging_exclude_endpoints(self) -> typing_exten

class LoggingInstrument(Instrument[LoggingConfig]):
instrument_name = "Logging"
ready_condition = "Works only in non-debug mode"
ready_condition = "Always ready"

def is_ready(self) -> bool:
return not self.instrument_config.service_debug
return True

def teardown(self) -> None:
structlog.reset_defaults()
Expand All @@ -159,6 +160,8 @@ def _unset_handlers(self) -> None:
logging.getLogger(unset_handlers_logger).handlers = []

def _configure_structlog_loggers(self) -> None:
if self.instrument_config.service_debug:
return
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
Expand All @@ -181,6 +184,15 @@ def _configure_foreign_loggers(self) -> None:
stream_handler: typing.Final = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(
structlog.stdlib.ProcessorFormatter(
foreign_pre_chain=structlog.get_config()["processors"][:-1],
processors=[
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.get_config()["processors"][-1],
],
logger=root_logger,
)
if self.instrument_config.service_debug
else structlog.stdlib.ProcessorFormatter(
foreign_pre_chain=STRUCTLOG_PRE_CHAIN_PROCESSORS,
processors=[
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
Expand Down