import os import logging import logging.config import yaml from sim import BASE_DIR _yaml_path = os.path.join(BASE_DIR,'config', 'logging.yaml') _logs_path = os.path.join(BASE_DIR,'log','sim-cenace.log') _error_path = os.path.join(BASE_DIR,'log','error-sim-cenace.log') _value = os.getenv('LOG_CFG', None) _default_level = logging.INFO if _value: path = _value if os.path.exists(_yaml_path): with open(_yaml_path, 'rt') as f: try: config = yaml.safe_load(f.read()) config['handlers']['file_handler']['filename'] = _logs_path config['handlers']['error_file_handler']['filename'] = _error_path logging.config.dictConfig(config) except Exception as e: print(e) print('Error in Logging Configuration. Using default configs') logging.basicConfig(level=_default_level) else: logging.basicConfig(level=_default_level) print('Failed to load configuration file. Using default configs')