Advertisement
MD500_Pilot

Untitled

May 28th, 2021
1,170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. def setup_logging(default_path=script_path.joinpath('logging.yaml'), default_level=logging.CRITICAL, env_key='LOG_CFG'):
  2.     """Module to configure program-wide logging. Designed for yaml configuration files."""
  3.     log_level = read_logging_config('plot_manager_config', 'system_logging', 'log_level')
  4.     log = logging.getLogger(__name__)
  5.     level = logging._checkLevel(log_level)
  6.     log.setLevel(level)
  7.     system_logging = read_logging_config('plot_manager_config', 'system_logging', 'logging')
  8.     if system_logging:
  9.         path = default_path
  10.         value = os.getenv(env_key, None)
  11.         if value:
  12.             path = value
  13.         if os.path.exists(path):
  14.             with open(path, 'rt') as f:
  15.                 try:
  16.                     config = yaml.safe_load(f.read())
  17.                     logging.config.dictConfig(config)
  18.                 except Exception as e:
  19.                     print(e)
  20.                     print('Error in Logging Configuration. Using default configs. Check File Permissions (for a start)!')
  21.                     logging.basicConfig(level=default_level)
  22.         else:
  23.             logging.basicConfig(level=default_level)
  24.             print('Failed to load configuration file. Using default configs')
  25.             return log
  26.     else:
  27.         log.disabled = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement