Skip to content

Commit

Permalink
[WIP] More elegant error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ljvmiranda921 committed Aug 17, 2018
1 parent a159989 commit 933b335
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pyswarms/utils/reporter/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,12 @@ def _setup_logger(self, path=None):
Path to a YAML configuration. If not supplied, uses
a default config.
"""
value = os.getenv(self._env_key, None)
if value:
path = value
value = path or os.getenv(self._env_key, None)
try:
if os.path.exists(path):
with open(path, "rt") as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
else:
# Load default config
self._load_defaults()
except TypeError:
with open(path, "rt") as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
except (TypeError, FileNotFoundError):
self._load_defaults()

def _load_defaults(self):
Expand Down

0 comments on commit 933b335

Please sign in to comment.