Skip to content

Commit

Permalink
refactor: added messages to the logfile that indicate the beginning a…
Browse files Browse the repository at this point in the history
…nd the end of a run

refactor: the path of the log file is now handled by PathTree
feat: logfile can be assigned a name from within config_file
feat: logging is now by default False. A flag can be given when calling from CLI and/or within an experiment config file. The config file has priority.
fix: correctly showing in logs the end date of an experiment
  • Loading branch information
pabloitu committed Jul 5, 2024
1 parent da27fc7 commit 6f5e1d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions floatcsep/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run(config, **kwargs):
exp.make_repr()

log.info('Finalized')
log.debug('')
log.debug(f'-------- END OF RUN --------')


def plot(config, **kwargs):
Expand All @@ -43,7 +43,7 @@ def plot(config, **kwargs):
exp.plot_forecasts()
exp.generate_report()

log.info('Finalized')
log.info('Finalized\n')
log.debug('')


Expand Down Expand Up @@ -77,7 +77,7 @@ def floatcsep():
help='Run a calculation')
parser.add_argument('config', type=str,
help='Experiment Configuration file')
parser.add_argument('-l', '--log', action='store_false', default=True,
parser.add_argument('-l', '--logging', action='store_true', default=False,
help="Don't log experiment")
parser.add_argument('-t', '--timestamp', action='store_true',
default=False, help="Timestamp results")
Expand Down
16 changes: 11 additions & 5 deletions floatcsep/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ def __init__(self,
rundir,
f'run_{datetime.datetime.utcnow().date().isoformat()}')
os.makedirs(os.path.join(workdir, rundir), exist_ok=True)
if kwargs.get(log, True):
logpath = os.path.join(workdir, rundir, 'experiment.log')
log.info(f'Logging at {logpath}')
add_fhandler(logpath)

self.name = name if name else 'floatingExp'
self.path = PathTree(workdir, rundir)
Expand All @@ -152,6 +148,14 @@ def __init__(self,
self.model_config = models if isinstance(models, str) else None
self.test_config = tests if isinstance(tests, str) else None

logger = kwargs.get('logging', True)
if logger:
filename = 'experiment.log' if logger is True else logger
self.path.logger = os.path.join(workdir, rundir, filename)
log.info(f'Logging at {self.path.logger}')
add_fhandler(self.path.logger)

log.debug(f'-------- BEGIN OF RUN --------')
log.info(f'Setting up experiment {self.name}:')
log.info(f'\tStart: {self.start_date}')
log.info(f'\tEnd: {self.end_date}')
Expand Down Expand Up @@ -977,5 +981,7 @@ def from_yml(cls, config_yml: str, reprdir=None, **kwargs):
_dict['rundir'] = _dict.get('rundir',
kwargs.pop('rundir', 'results'))
_dict['config_file'] = relpath(config_yml, _dir_yml)
# print(_dict['rundir'])
if 'logging' in _dict:
kwargs.pop('logging')

return cls(**_dict, **kwargs)

0 comments on commit 6f5e1d0

Please sign in to comment.