This is a follow-up question to the answer How to get non-blocking/real-time behavior from Python logging module? (output to PyQt QTextBrowser) provided by X.Jacobs.
In the Python logging module, the normal method of adding a custom handler is to define a handler class that inherits from logging.Handler (we'll call this CustomLogHandler). To attach it to logging process, we typically do this:
import logging
class CustomLogHandler(logging.Handler):
... (some code here)...
logger = logging.getLogger()
logger.addHandler(CustomLogHandler)
where addHandler is a method of the logger instance.
Question: Suppose we didn't want to get a logger (i.e. we don't want to do the above). Is is possible to attach the CustomLogHandler to logging itself?
See comments in How to get non-blocking/real-time behavior from Python logging module? (output to PyQt QTextBrowser) for context.
The premise is that it is possible to use custom handlers without any reference to the logger instance.
CustomLogHandlertologgingitself'?logging.error()instead oflogger.error().