File size: 975 Bytes
211b431 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import logging
def setup_logger(log_file_path):
# Get the logger for the current module
logger = logging.getLogger(__name__)
# Check if the logger has handlers and clear them if it does
if logger.hasHandlers():
logger.handlers.clear()
# Create a file handler and add it to the logger (use 'w' to overwrite existing file)
file_handler = logging.FileHandler(log_file_path, 'w')
logger.addHandler(file_handler)
# Set the logging level to DEBUG
logger.setLevel(logging.DEBUG)
# Set the formatter for the file handler
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
return logger
log_file_path = './utils/log_debug.log'
logger = setup_logger(log_file_path)
# # use the logger for logging messages
# logger.debug('This is a debug message.')
# logger.info('This is an info message.')
# logger.warning('This is a warning message.')
# logger.error('This is an error message.') |