Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 1.03 KB

logging_survival.rst

File metadata and controls

28 lines (19 loc) · 1.03 KB

Annex: Quick survival guide with the logging module

Sadly, some config still needs to take place for the :py:mod:`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
)