Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Best practice is, in each module, to have a logger defined like this:</p> <pre><code>import logging logger = logging.getLogger(__name__) </code></pre> <p>near the top of the module, and then in other code in the module do e.g.</p> <pre><code>logger.debug('My message with %s', 'variable data') </code></pre> <p>If you need to subdivide logging activity inside a module, use e.g.</p> <pre><code>loggerA = logging.getLogger(__name__ + '.A') loggerB = logging.getLogger(__name__ + '.B') </code></pre> <p>and log to <code>loggerA</code> and <code>loggerB</code> as appropriate.</p> <p>In your main program or programs, do e.g.:</p> <pre><code>def main(): "your program code" if __name__ == '__main__': import logging.config logging.config.fileConfig('/path/to/logging.conf') main() </code></pre> <p>or </p> <pre><code>def main(): import logging.config logging.config.fileConfig('/path/to/logging.conf') # your program code if __name__ == '__main__': main() </code></pre> <p>See <a href="http://docs.python.org/howto/logging.html#logging-from-multiple-modules">here</a> for logging from multiple modules, and <a href="http://docs.python.org/howto/logging.html#configuring-logging-for-a-library">here</a> for logging configuration for code which will be used as a library module by other code.</p> <p><strong>Update:</strong> When calling <code>fileConfig()</code>, you may want to specify <code>disable_existing_loggers=False</code> if you're using Python 2.6 or later (see <a href="http://docs.python.org/2/library/logging.config.html#logging.config.fileConfig">the docs</a> for more information). The default value is <code>True</code> for backward compatibility, which causes all existing loggers to be disabled by <code>fileConfig()</code> unless they or their ancestor are explicitly named in the configuration. With the value set to <code>False</code>, existing loggers are left alone. If using Python 2.7/Python 3.2 or later, you may wish to consider the <code>dictConfig()</code> API which is better than <code>fileConfig()</code> as it gives more control over the configuration.</p>
 

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