Logging

OpenLEADR uses the standard Python Logging facility. Following the Python guidelines, no default handlers are configured, but you can easily get going if you want to:

Log to standard output

To print logs to your standard output, you can use the following convenience method:

import openleadr
import logging
openleadr.enable_default_logging(level=logging.INFO)

Which is the same as:

import logging
logger = logging.getLogger('openleadr')
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)

Setting the logging level

You can set different logging levels for the logging generated by OpenLEADR:

import logging
logger = logging.getLogger('openleadr')
logger.setLevel(logging.WARNING)

The different logging levels are:

logging.DEBUG
logging.INFO
logging.WARNING
logging.ERROR
logging.CRITICAL

Redirecting logs to a different file

To write logs to a file:

import logging
logger = logging.getLogger('openleadr')

handler = logging.FileHandler('mylogfile.txt')
logger.addHandler(logger)

More info

Detailed info on logging configuration can be found on the official Python documentation.