question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

How to properly configure logger to capture log messages from libraries which uses standart logging?

See original GitHub issue

Iā€™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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Delgancommented, Mar 22, 2019

Thanks for your suggestion, I added a few words about the depth=6 option in the Readme. šŸ‘

0reactions
kiddtencommented, Mar 21, 2019

Thank you again! Btw was confused about what magic number, so may be it is worth to mention about that in readme.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found