How to properly configure logger to capture log messages from libraries which uses standart logging?
See original GitHub issueIāve tried to use InterceptHandler
for that purpose with asyncio lib. But I am only getting messages spawned from my script by logger.info(..)
, but messages from libs are missingā¦
What is the proper way to capture underlying libraries log messages?
config = {
'handlers': [
{
'sink': sys.stdout,
'level': 'DEBUG'
},
],
}
logger.configure(**config)
class InterceptHandler(logging.Handler):
def emit(self, record):
logger_opt = logger.opt(exception=record.exc_info)
logger_opt.log(record.levelname, record.getMessage())
logging.getLogger(None).addHandler(InterceptHandler())
logging.getLogger('asyncio').addHandler(InterceptHandler())
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python Logging Guide - Best Practices and Hands-on Examples
The Python standard library provides a logging module as a solution to log events from applications and libraries. Once the logger is configured...
Read more >Python Logging Basics - The Ultimate Guide To Logging
To emit a log message, a caller first requests a named logger. The application can use the name to configure different rules for...
Read more >Python Logging: In-Depth Tutorial - Toptal
Configure the root logger but never use it in your codeāe.g., never call a function like logging.info() , which actually calls the root...
Read more >How to Collect, Customize, and Centralize Python Logs
Digging deeper into Python's logging library Ā· Configure multiple loggers and capture the logger name Ā· Use fileConfig() to output logs toĀ ...
Read more >logging ā Logging facility for Python ā Python 3.11.1 ...
Logs a message with level DEBUG on this logger. The msg is the message format string, and the args are the arguments which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your suggestion, I added a few words about the
depth=6
option in the Readme. šThank you again! Btw was confused about what magic number, so may be it is worth to mention about that in readme.