Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def setup_logging(default_path=script_path.joinpath('logging.yaml'), default_level=logging.CRITICAL, env_key='LOG_CFG'):
- """Module to configure program-wide logging. Designed for yaml configuration files."""
- log_level = read_logging_config('plot_manager_config', 'system_logging', 'log_level')
- log = logging.getLogger(__name__)
- level = logging._checkLevel(log_level)
- log.setLevel(level)
- system_logging = read_logging_config('plot_manager_config', 'system_logging', 'logging')
- if system_logging:
- path = default_path
- value = os.getenv(env_key, None)
- if value:
- path = value
- if os.path.exists(path):
- with open(path, 'rt') as f:
- try:
- config = yaml.safe_load(f.read())
- logging.config.dictConfig(config)
- except Exception as e:
- print(e)
- print('Error in Logging Configuration. Using default configs. Check File Permissions (for a start)!')
- logging.basicConfig(level=default_level)
- else:
- logging.basicConfig(level=default_level)
- print('Failed to load configuration file. Using default configs')
- return log
- else:
- log.disabled = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement