4. Annex: Quick survival guide with the logging moduleΒΆ

Sadly, some config still needs to take place for the logging module.

Disclaimer: we are not responsible for the boilerplate required by the logging API

You still need to configure logging somewhere at the start of your script -for complex apps (pyramid for example), initial scaffolding is likely to do this for you (see generated .ini file).

Example boilerplate for a script logging to my_app.log:

import logging
import logging.handlers
import quicklogging

# basicConfig is only effective once (if the root logger was not configured before)
logging.basicConfig(
    handlers=[logging.handlers.WatchedFileHandler('my_app.log')],
    format="%(asctime)s %(pathname)s:%(lineno)s%(message)s\\n",
    level=logging.WARNING
)