backend / src /logging.py
albertvillanova's picture
Fix E402 module-import-not-at-top-of-file
d295ed3 verified
raw
history blame
954 Bytes
import logging
from pathlib import Path
proj_dir = Path(__file__).parents[1]
log_file = proj_dir / "output.log"
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)