Skip to content

Commit 48f8d16

Browse files
authored
Merge pull request #45 from modern-python/add-setting-to-enable-logging
add setting to enable logging
2 parents ce8432a + cf11f56 commit 48f8d16

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

docs/introduction/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ For FastStream you must provide additionally:
8686

8787
## Structlog
8888

89-
To bootstrap Structlog, you must set `service_debug` to False
89+
To bootstrap Structlog, you must keep `logging_enabled` to True
9090

9191
Additional parameters:
9292

lite_bootstrap/instruments/logging_instrument.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __call__(self, *args: typing.Any) -> logging.Logger: # noqa: ANN401
8383

8484
@dataclasses.dataclass(kw_only=True, frozen=True)
8585
class LoggingConfig(BaseConfig):
86+
logging_enabled: bool = True
8687
logging_log_level: int = logging.INFO
8788
logging_flush_level: int = logging.ERROR
8889
logging_buffer_capacity: int = 10
@@ -95,11 +96,11 @@ class LoggingConfig(BaseConfig):
9596
@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
9697
class LoggingInstrument(BaseInstrument):
9798
bootstrap_config: LoggingConfig
98-
not_ready_message = "service_debug is True"
99+
not_ready_message = "logging_enabled is False"
99100
missing_dependency_message = "structlog is not installed"
100101

101102
def is_ready(self) -> bool:
102-
return not self.bootstrap_config.service_debug and import_checker.is_structlog_installed
103+
return self.bootstrap_config.logging_enabled and import_checker.is_structlog_installed
103104

104105
@staticmethod
105106
def check_dependencies() -> bool:

tests/test_free_bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_free_bootstrap(free_bootstrapper_config: FreeBootstrapperConfig) -> Non
3333
def test_free_bootstrap_logging_not_ready(log_output: list[EventDict]) -> None:
3434
FreeBootstrapper(
3535
bootstrap_config=FreeBootstrapperConfig(
36-
service_debug=True,
36+
logging_enabled=False,
3737
opentelemetry_endpoint="otl",
3838
opentelemetry_instrumentors=[CustomInstrumentor()],
3939
opentelemetry_log_traces=True,
@@ -42,7 +42,7 @@ def test_free_bootstrap_logging_not_ready(log_output: list[EventDict]) -> None:
4242
),
4343
)
4444
assert log_output == [
45-
{"event": "LoggingInstrument is not ready, because service_debug is True", "log_level": "info"}
45+
{"event": "LoggingInstrument is not ready, because logging_enabled is False", "log_level": "info"}
4646
]
4747

4848

0 commit comments

Comments
 (0)