backend / src /logging.py
clefourrier's picture
clefourrier HF staff
pr_3_add_button_readme_and_better_logs (#3)
95c19d6 verified
raw
history blame
964 Bytes
import sys
from pathlib import Path
proj_dir = Path(__file__).parents[1]
log_file = proj_dir/"output.log"
import logging
def setup_logger(name: str):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Create a file handler to write logs to a file
file_handler = logging.FileHandler(log_file)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
return logger
def configure_root_logger():
# Configure the root logger
logging.basicConfig(level=logging.INFO)
root_logger = logging.getLogger()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler = logging.FileHandler(log_file)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)
root_logger.addHandler(file_handler)