Configuring Logging
-
The level of logs displayed by
mailbagit
is based on an environment variableMAILBAGIT_LOG_LEVEL
. -
Log levels are available in the following order :
NOTSET
,DEBUG
,INFO
,WARN
,ERROR
, andCRITICAL
. For example, when theMAILBAGIT_LOG_LEVEL
isDEBUG
,mailbagit
displays logs of all levels. And whenMAILBAGIT_LOG_LEVEL
isWARN
, it displays logs of levelWARN
and above. i.e.WARN
,ERROR
, orCRITICAL
. -
If no
MAILBAGIT_LOG_LEVEL
environment variable is set,mailbagit
will default toWARN
.
Unix example:
export MAILBAGIT_LOG_LEVEL=info
echo $MAILBAGIT_LOG_LEVEL
> info
Windows Powershell example:
$env:MAILBAGIT_LOG_LEVEL='debug'
$env:MAILBAGIT_LOG_LEVEL
> debug
On Windows, you can also set environment variables by searching “edit environment variable”.
Example of the logger initiation and usage in Python
:
from structlog import get_logger
import mailbagit.loggerx
loggerx.configure()
log = get_logger()
log.error("Error message here")
log.info("Information message here")