# Logger setup in python
def get_logger(self) -> logging.RootLogger:
"""instance of logger module, will be used for logging operations"""
# logger config
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# log format
lg_format = "%(levelname)s|%(filename)s:%(lineno)d|%(asctime)s|%(message)s"
log_format = logging.Formatter(lg_format)
# file handler
file_handler = logging.FileHandler("log/monitor_model.log")
file_handler.setFormatter(log_format)
logger.handlers.clear()
logger.addHandler(file_handler)
return logger
# Note: Only levels on or above the current chosen level are outputted
Logging Levels -> Numeric Value
CRITICAL -> 50
ERROR -> 40
WARNING -> 30
INFO -> 20
DEBUG -> 10
NOTSET -> 0
import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
FORMAT = '%(asctime)s %(clientip)-15s %(user)-8s %(message)s'
logging.basicConfig(format=FORMAT)
d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
logger = logging.getLogger('tcpserver')
logger.warning('Protocol problem: %s', 'connection reset', extra=d)
logger = fmeobjects.FMELogFile()
logger.logMessageString("{}".format('Error'), fmeobjects.FME_ERROR)