1 Upvote
Creating Logs Using Python Logger
In this code snippet we set the logger to output log messages to a log file named 'train.log'. Each message will be time stamped and include the function name where the logging occurs. The lowest logging level is set to info so all debug messages will be ignored.
import logging logging.basicConfig(format='%(asctime)s[%(levelname)s] %(funcName)s: %(message)s', datefmt='%d/%m/%Y %I:%M:%S %p', filename='../logs/train.log', level=logging.INFO) # logger set to name of the script LOG = logging.getLogger('__name__') LOG.info('Start') LOG.info('End') """List of log levels: LOG.debug() LOG.info() LOG.warning() LOG.error() LOG.critical() LOG.exception() """
By analyseup - Last Updated June 11, 2022, 4 p.m.
COMMENTS
RELATED SNIPPETS
3
Python Class Example Using __init__ and __repr__
Python
General Python
2
Using a Python Decorator to Print Memory Usage of a DataFrame
Python
General Python
2
2
2
2
2
2
2
2
Find Snippets by Language
Find Snippets by Use