File size: 903 Bytes
8e29341 |
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 |
import logging
def setup_logger():
# Format for our loglines
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
# Setup basic configuration for logging
logging.basicConfig(filename='app.log',
level=logging.ERROR,
format='%(asctime)s - %(levelname)s - %(message)s')
# Create a logger
logger = logging.getLogger('AppLogger')
# Create handlers (if you want to log to file and console)
file_handler = logging.FileHandler('app.log')
file_handler.setFormatter(formatter)
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
# Add handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)
return logger
app_logger = setup_logger() |