backend / src /logging.py
AlyxTeam's picture
feat: init
2bc5a2c
raw
history blame contribute delete
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)