22 lines
746 B
Python
22 lines
746 B
Python
import yaml
|
|
|
|
def load_config(config_file):
|
|
with open(config_file, "r", encoding="utf-8") as f:
|
|
data = yaml.safe_load(f)
|
|
return data
|
|
|
|
def setup_logging(config):
|
|
import logging
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
|
logging.basicConfig(level=config['logging']['level'], format=LOG_FORMAT)
|
|
file_handler = RotatingFileHandler(
|
|
config['logging']['file'],
|
|
maxBytes=config['logging']['max_size'],
|
|
backupCount=config['logging']['backup_count'],
|
|
encoding='utf-8'
|
|
)
|
|
file_handler.setFormatter(logging.Formatter(LOG_FORMAT))
|
|
logger = logging.getLogger()
|
|
logger.addHandler(file_handler) |