Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding custom handler to Python logging module without a logger instance?
    primarykey
    data
    text
    <p>This is a follow-up question to the answer <a href="https://stackoverflow.com/questions/14349563/how-to-get-non-blocking-real-time-behavior-from-python-logging-module-output-t/14353888#14353888">How to get non-blocking/real-time behavior from Python logging module? (output to PyQt QTextBrowser)</a> provided by <a href="https://stackoverflow.com/users/1006989/x-jacobs">X.Jacobs</a>.</p> <p>In the Python logging module, the normal method of adding a custom handler is to define a handler class that inherits from <code>logging.Handler</code> (we'll call this <code>CustomLogHandler</code>). To attach it to <code>logging</code> process, we typically do this:</p> <pre><code>import logging class CustomLogHandler(logging.Handler): ... (some code here)... logger = logging.getLogger() logger.addHandler(CustomLogHandler) </code></pre> <p>where <code>addHandler</code> is a method of the <code>logger</code> instance. </p> <p><strong>Question</strong>: Suppose we <strong>didn't</strong> want to get a <code>logger</code> (i.e. we <strong>don't want</strong> to do the above). Is is possible to attach the <code>CustomLogHandler</code> to <code>logging</code> itself?</p> <p>See comments in <a href="https://stackoverflow.com/questions/14349563/how-to-get-non-blocking-real-time-behavior-from-python-logging-module-output-t/14353888#14353888">How to get non-blocking/real-time behavior from Python logging module? (output to PyQt QTextBrowser)</a> for context.</p> <p>The premise is that it is possible to use custom handlers without any reference to the <code>logger</code> instance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload