-
Notifications
You must be signed in to change notification settings - Fork 0
Logging
Marc Szymkowiak edited this page May 12, 2022
·
1 revision
The flake8 plugin flake8-print checks code for print statements, because it is not a good practice to use print. A better way is to use the python logging library.
Depending on the configured log level, python output more of fewer messages. The higher log levels also output the log of the lower ones.
To configure the loglevel set the env variable LOG_LEVEL. The default value is CRITICAL.
Command | Description |
---|---|
DEBUG | Detailed information, typically of interest only when diagnosing problems. (Highest) |
INFO | Confirmation that things are working as expected. |
WARNING | An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected. |
ERROR | Due to a more serious problem, the software has not been able to perform some function. expected. |
CRITICAL | A serious error, indicating that the program itself may be unable to continue running. (Lowest) |
- Import logger object in the file you want to log something
from .. import logger
- Call the method corresponding to the log level
logger.error("Login failed for user %s", data.get("username"))
For more info see https://docs.python.org/3/howto/logging.html