Skip to content

Commit b6ab5c7

Browse files
committed
small import fix
1 parent e65ed00 commit b6ab5c7

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

lite_bootstrap/instruments/logging_instrument.py

+30-28
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,36 @@ def tracer_injection(_: "WrappedLogger", __: str, event_dict: "EventDict") -> "E
4949
return event_dict
5050

5151

52-
class MemoryLoggerFactory(structlog.stdlib.LoggerFactory):
53-
def __init__(
54-
self,
55-
*args: typing.Any, # noqa: ANN401
56-
logging_buffer_capacity: int,
57-
logging_flush_level: int,
58-
logging_log_level: int,
59-
log_stream: typing.Any = None, # noqa: ANN401
60-
**kwargs: typing.Any, # noqa: ANN401
61-
) -> None:
62-
super().__init__(*args, **kwargs)
63-
self.logging_buffer_capacity = logging_buffer_capacity
64-
self.logging_flush_level = logging_flush_level
65-
self.logging_log_level = logging_log_level
66-
self.log_stream = log_stream
67-
68-
def __call__(self, *args: typing.Any) -> logging.Logger: # noqa: ANN401
69-
logger: typing.Final = super().__call__(*args)
70-
stream_handler: typing.Final = logging.StreamHandler(stream=self.log_stream)
71-
handler: typing.Final = logging.handlers.MemoryHandler(
72-
capacity=self.logging_buffer_capacity,
73-
flushLevel=self.logging_flush_level,
74-
target=stream_handler,
75-
)
76-
logger.addHandler(handler)
77-
logger.setLevel(self.logging_log_level)
78-
logger.propagate = False
79-
return logger
52+
if import_checker.is_structlog_installed:
53+
54+
class MemoryLoggerFactory(structlog.stdlib.LoggerFactory):
55+
def __init__(
56+
self,
57+
*args: typing.Any, # noqa: ANN401
58+
logging_buffer_capacity: int,
59+
logging_flush_level: int,
60+
logging_log_level: int,
61+
log_stream: typing.Any = None, # noqa: ANN401
62+
**kwargs: typing.Any, # noqa: ANN401
63+
) -> None:
64+
super().__init__(*args, **kwargs)
65+
self.logging_buffer_capacity = logging_buffer_capacity
66+
self.logging_flush_level = logging_flush_level
67+
self.logging_log_level = logging_log_level
68+
self.log_stream = log_stream
69+
70+
def __call__(self, *args: typing.Any) -> logging.Logger: # noqa: ANN401
71+
logger: typing.Final = super().__call__(*args)
72+
stream_handler: typing.Final = logging.StreamHandler(stream=self.log_stream)
73+
handler: typing.Final = logging.handlers.MemoryHandler(
74+
capacity=self.logging_buffer_capacity,
75+
flushLevel=self.logging_flush_level,
76+
target=stream_handler,
77+
)
78+
logger.addHandler(handler)
79+
logger.setLevel(self.logging_log_level)
80+
logger.propagate = False
81+
return logger
8082

8183

8284
@dataclasses.dataclass(kw_only=True, frozen=True)

0 commit comments

Comments
 (0)