From cf11f56bae7c7f3f9abd84c2f7dd7dd247ecb847 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Fri, 29 Aug 2025 15:07:02 +0300 Subject: [PATCH] add setting to enable logging --- docs/introduction/configuration.md | 2 +- lite_bootstrap/instruments/logging_instrument.py | 5 +++-- tests/test_free_bootstrap.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/introduction/configuration.md b/docs/introduction/configuration.md index 5b6f0a2..88c3a4c 100644 --- a/docs/introduction/configuration.md +++ b/docs/introduction/configuration.md @@ -86,7 +86,7 @@ For FastStream you must provide additionally: ## Structlog -To bootstrap Structlog, you must set `service_debug` to False +To bootstrap Structlog, you must keep `logging_enabled` to True Additional parameters: diff --git a/lite_bootstrap/instruments/logging_instrument.py b/lite_bootstrap/instruments/logging_instrument.py index 32242a0..0b151e3 100644 --- a/lite_bootstrap/instruments/logging_instrument.py +++ b/lite_bootstrap/instruments/logging_instrument.py @@ -83,6 +83,7 @@ def __call__(self, *args: typing.Any) -> logging.Logger: # noqa: ANN401 @dataclasses.dataclass(kw_only=True, frozen=True) class LoggingConfig(BaseConfig): + logging_enabled: bool = True logging_log_level: int = logging.INFO logging_flush_level: int = logging.ERROR logging_buffer_capacity: int = 10 @@ -95,11 +96,11 @@ class LoggingConfig(BaseConfig): @dataclasses.dataclass(kw_only=True, slots=True, frozen=True) class LoggingInstrument(BaseInstrument): bootstrap_config: LoggingConfig - not_ready_message = "service_debug is True" + not_ready_message = "logging_enabled is False" missing_dependency_message = "structlog is not installed" def is_ready(self) -> bool: - return not self.bootstrap_config.service_debug and import_checker.is_structlog_installed + return self.bootstrap_config.logging_enabled and import_checker.is_structlog_installed @staticmethod def check_dependencies() -> bool: diff --git a/tests/test_free_bootstrap.py b/tests/test_free_bootstrap.py index f627aa8..c6e8726 100644 --- a/tests/test_free_bootstrap.py +++ b/tests/test_free_bootstrap.py @@ -34,7 +34,7 @@ def test_free_bootstrap(free_bootstrapper_config: FreeBootstrapperConfig) -> Non def test_free_bootstrap_logging_not_ready(log_output: list[EventDict]) -> None: FreeBootstrapper( bootstrap_config=FreeBootstrapperConfig( - service_debug=True, + logging_enabled=False, opentelemetry_endpoint="otl", opentelemetry_instrumentors=[CustomInstrumentor()], opentelemetry_span_exporter=ConsoleSpanExporter(), @@ -43,7 +43,7 @@ def test_free_bootstrap_logging_not_ready(log_output: list[EventDict]) -> None: ), ) assert log_output == [ - {"event": "LoggingInstrument is not ready, because service_debug is True", "log_level": "info"} + {"event": "LoggingInstrument is not ready, because logging_enabled is False", "log_level": "info"} ]