37 lines
904 B
Python
37 lines
904 B
Python
import logging
|
|
from logging.handlers import TimedRotatingFileHandler
|
|
|
|
import json
|
|
import os
|
|
|
|
|
|
def setup_logger():
|
|
logger = logging.getLogger(__name__)
|
|
logger.setLevel(logging.INFO)
|
|
|
|
handler = TimedRotatingFileHandler(
|
|
"logs/app.log",
|
|
when="midnight",
|
|
interval=1,
|
|
backupCount=7,
|
|
encoding='utf-8'
|
|
)
|
|
|
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
|
handler.setFormatter(formatter)
|
|
|
|
logger.addHandler(handler)
|
|
|
|
return logger
|
|
|
|
|
|
def load_config(config_path='config/config.json'):
|
|
"""
|
|
Загрузка конфигурации из JSON файла.
|
|
"""
|
|
if not os.path.exists(config_path):
|
|
raise FileNotFoundError(f"Конфигурационный файл не найден: {config_path}")
|
|
|
|
with open(config_path, 'r') as file:
|
|
return json.load(file)
|