Skip to content

Commit 5795d21

Browse files
authored
Merge pull request #8 from cseptesting/7-improving-logging
Improving loggins
2 parents 0b205a1 + 6f5e1d0 commit 5795d21

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

floatcsep/cmd/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def run(config, **kwargs):
2929
exp.make_repr()
3030

3131
log.info('Finalized')
32-
log.debug('')
32+
log.debug(f'-------- END OF RUN --------')
3333

3434

3535
def plot(config, **kwargs):
@@ -43,7 +43,7 @@ def plot(config, **kwargs):
4343
exp.plot_forecasts()
4444
exp.generate_report()
4545

46-
log.info('Finalized')
46+
log.info('Finalized\n')
4747
log.debug('')
4848

4949

@@ -77,7 +77,7 @@ def floatcsep():
7777
help='Run a calculation')
7878
parser.add_argument('config', type=str,
7979
help='Experiment Configuration file')
80-
parser.add_argument('-l', '--log', action='store_false', default=True,
80+
parser.add_argument('-l', '--logging', action='store_true', default=False,
8181
help="Don't log experiment")
8282
parser.add_argument('-t', '--timestamp', action='store_true',
8383
default=False, help="Timestamp results")

floatcsep/experiment.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ def __init__(self,
135135
rundir,
136136
f'run_{datetime.datetime.utcnow().date().isoformat()}')
137137
os.makedirs(os.path.join(workdir, rundir), exist_ok=True)
138-
if kwargs.get(log, True):
139-
logpath = os.path.join(workdir, rundir, 'experiment.log')
140-
log.info(f'Logging at {logpath}')
141-
add_fhandler(logpath)
142138

143139
self.name = name if name else 'floatingExp'
144140
self.path = PathTree(workdir, rundir)
@@ -152,9 +148,17 @@ def __init__(self,
152148
self.model_config = models if isinstance(models, str) else None
153149
self.test_config = tests if isinstance(tests, str) else None
154150

151+
logger = kwargs.get('logging', True)
152+
if logger:
153+
filename = 'experiment.log' if logger is True else logger
154+
self.path.logger = os.path.join(workdir, rundir, filename)
155+
log.info(f'Logging at {self.path.logger}')
156+
add_fhandler(self.path.logger)
157+
158+
log.debug(f'-------- BEGIN OF RUN --------')
155159
log.info(f'Setting up experiment {self.name}:')
156160
log.info(f'\tStart: {self.start_date}')
157-
log.info(f'\tEnd: {self.start_date}')
161+
log.info(f'\tEnd: {self.end_date}')
158162
log.info(f'\tTime windows: {len(self.timewindows)}')
159163
log.info(f'\tRegion: {self.region.name if self.region else None}')
160164
log.info(f'\tMagnitude range: [{numpy.min(self.magnitudes)},'
@@ -957,7 +961,7 @@ def from_yml(cls, config_yml: str, reprdir=None, **kwargs):
957961
with open(config_yml, 'r') as yml:
958962

959963
# experiment configuration file
960-
_dict = yaml.safe_load(yml)
964+
_dict = yaml.load(yml, NoAliasLoader)
961965
_dir_yml = dirname(config_yml)
962966
# uses yml path and append if a rel/abs path is given in config.
963967
_path = _dict.get('path', '')
@@ -977,5 +981,7 @@ def from_yml(cls, config_yml: str, reprdir=None, **kwargs):
977981
_dict['rundir'] = _dict.get('rundir',
978982
kwargs.pop('rundir', 'results'))
979983
_dict['config_file'] = relpath(config_yml, _dir_yml)
980-
# print(_dict['rundir'])
984+
if 'logging' in _dict:
985+
kwargs.pop('logging')
986+
981987
return cls(**_dict, **kwargs)

0 commit comments

Comments
 (0)