Skip to content

Commit a18b885

Browse files
committed
Added external logging
1 parent 6df6c75 commit a18b885

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

microbootstrap/instruments/logging_instrument.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@ def bootstrap(self) -> None:
150150
for unset_handlers_logger in self.instrument_config.logging_unset_handlers:
151151
logging.getLogger(unset_handlers_logger).handlers = []
152152

153+
stream_handler: typing.Final = logging.StreamHandler()
154+
root_logger: typing.Final = logging.getLogger()
155+
*foreign_pre_chain, renderer = structlog.get_config()["processors"]
153156
structlog.configure(
154157
processors=[
155158
*DEFAULT_STRUCTLOG_PROCESSORS,
156159
*self.instrument_config.logging_extra_processors,
160+
*foreign_pre_chain,
157161
DEFAULT_STRUCTLOG_FORMATTER_PROCESSOR,
158162
],
159163
context_class=dict,
@@ -165,6 +169,17 @@ def bootstrap(self) -> None:
165169
wrapper_class=structlog.stdlib.BoundLogger,
166170
cache_logger_on_first_use=True,
167171
)
172+
stream_handler.setFormatter(
173+
structlog.stdlib.ProcessorFormatter(
174+
foreign_pre_chain=[
175+
*foreign_pre_chain,
176+
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
177+
],
178+
processors=[renderer],
179+
logger=root_logger,
180+
)
181+
)
182+
root_logger.addHandler(stream_handler)
168183

169184
@classmethod
170185
def get_config_type(cls) -> type[LoggingConfig]:

0 commit comments

Comments
 (0)