diff --git a/microbootstrap/instruments/logging_instrument.py b/microbootstrap/instruments/logging_instrument.py index 1426aa3..07839a2 100644 --- a/microbootstrap/instruments/logging_instrument.py +++ b/microbootstrap/instruments/logging_instrument.py @@ -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, @@ -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() @@ -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, @@ -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,