Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe this helps you to get an idea? Of course you can make it much better, reading settings from a config file or whatever but this is quick example.</p> <p>A separate module to configure the logging: <code>mylogmod.py</code> :</p> <pre><code>import logging FILENAME = "mylog.log" # Your logfile LOGFORMAT = "%(message)s" # Your format DEFAULT_LEVEL = "info" # Your default level, usually set to warning or error for production LEVELS = { 'debug':logging.DEBUG, 'info':logging.INFO, 'warning':logging.WARNING, 'error':logging.ERROR, 'critical':logging.CRITICAL} def startlogging(filename=FILENAME, level=DEFAULT_LEVEL): logging.basicConfig(filename=filename, level=LEVELS[level], format=LOGFORMAT) </code></pre> <p>The <code>main.py</code> :</p> <pre><code>import logging from mylogmod import startlogging from myclass import MyClass startlogging() logging.info("Program started...") mc = MyClass() </code></pre> <p>A class <code>myclass.py</code> from a module with self test. You can do something similar in a unittest: (Note that you don't need to import the logging module in a unittest, just the <code>startlogging</code> function is enough. This way you can set the default level to warning or error and the unittests and self tests to debug)</p> <pre><code>import logging class MyClass(object): def __init__(self): logging.info("Initialze MyClass instance...") if __name__ == "__main__": from mylogmod import startlogging startlogging(level="debug") logging.debug("Test MyClass...") #... rest of test code... </code></pre>
    singulars
    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