Note that there are some explanatory texts on larger screens.

plurals
  1. POPython logging for non-trivial uses?
    primarykey
    data
    text
    <p>I'm attempting to use the python logging module to do complex things. I'll leave the motivation for this design out because it would greatly lengthen the post, but I need to have a root logger that spams a regular log file for our code and libraries that use logging -- and a collection of other loggers that go to <em>different</em> log files.</p> <p>The overall setup should look like this. I will do everything to stdout in this example to simplify the code.</p> <pre><code> import logging, sys root = logging.getLogger('') top = logging.getLogger('top') bottom = logging.getLogger('top.bottom') class KillFilter(object): def filter(self, msg): return 0 root_handler = logging.StreamHandler(sys.stdout) top_handler = logging.StreamHandler(sys.stdout) bottom_handler = logging.StreamHandler(sys.stdout) root_handler.setFormatter(logging.Formatter('ROOT')) top_handler.setFormatter(logging.Formatter('TOP HANDLER')) bottom_handler.setFormatter(logging.Formatter("BOTTOM HANDLER")) msg_killer = KillFilter() root.addHandler(root_handler) top.addHandler(top_handler) bottom.addHandler(bottom_handler) top.addFilter(msg_killer) root.error('hi') top.error('hi') bottom.error('hi') </code></pre> <p>This outputs</p> <p><pre><code> ROOT BOTTOM HANDLER ROOT </pre></code></p> <p>The second root handler call should not because according to logging documentation the <code>msg_killer</code> will stop the message from going up to the root logger. Obviously the documentation could use improvement.</p> <p>Edit: removed my "in the moment" harsh words for python logging.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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