Logging
Python provides logging APIs. Web2py provides a mechanism to configure it so that apps can use it.
In your application, you can create a logger, for example in a model:
import logging
logger = logging.getLogger("web2py.app.myapp")
logger.setLevel(logging.DEBUG)
and you can use it to log messages of various importance
logger.debug("Just checking that %s", details)
logger.info("You ought to know that %s", details)
logger.warn("Mind that %s", details)
logger.error("Oops, something bad happened %s", details)
logging
is a standard Python module described at https://docs.python.org/2/library/logging.html (Python 2.x) and https://docs.python.org/3/library/logging.html (Python 3.x)
The string “web2py.app.myapp” defines an app-level logger.
For this to work properly, you need a configuration file for the logger. One is provided by web2py in the “examples” folder “logging.example.conf”. You need to copy the file to web2py’s directory and rename the file to “logging.conf” and customize it as necessary.
This file is self documenting, so you should open it and read it.
To create a configurable logger for application “myapp”, you must add myapp to the [loggers] keys list:
[loggers]
keys=root,rocket,markdown,web2py,rewrite,app,welcome,myapp
and you must add a [logger_myapp] section, using [logger_welcome] as a starting point.
[logger_myapp]
level=WARNING
qualname=web2py.app.myapp
handlers=consoleHandler
propagate=0
The “handlers” directive specifies the type of logging and here it is logging “myapp” to the console.