37 lines
827 B
Python
37 lines
827 B
Python
from datetime import datetime
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from config.main import BACKEND_DIR
|
|
|
|
|
|
LOG_DIR = BACKEND_DIR / 'logs'
|
|
|
|
|
|
def configure_logging() -> None:
|
|
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
|
log_path = LOG_DIR / f'dcalc_{datetime.now().strftime("%Y_%m_%d")}.log'
|
|
|
|
logger = logging.getLogger('dcalc')
|
|
logger.setLevel(logging.INFO)
|
|
logger.propagate = True
|
|
|
|
if any(isinstance(handler, logging.FileHandler) and Path(handler.baseFilename) == log_path for handler in logger.handlers):
|
|
return
|
|
|
|
handler = logging.FileHandler(log_path, encoding='utf-8')
|
|
handler.setLevel(logging.ERROR)
|
|
handler.setFormatter(
|
|
logging.Formatter(
|
|
"""
|
|
[start]
|
|
%(asctime)s
|
|
<%(name)s>
|
|
%(levelname)s
|
|
%(message)s
|
|
[end]
|
|
"""
|
|
)
|
|
)
|
|
logger.addHandler(handler)
|