Skip to content

Commit

Permalink
Update Logger semantics to reduce needless file creation
Browse files Browse the repository at this point in the history
This change does 2 main things:

1. Fixes a bug where simlinks were created to logger files that were
   never created, if -N is passed (ie logger is disabled)
2. Delays the creation of logger directories and makes them conditional
   on logger enablement
  • Loading branch information
rfbgo committed Apr 3, 2024
1 parent 4eecfe1 commit 4f3b2dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions lib/ramble/ramble/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ def __init__(self, workspace, filters):
self.log_path_latest = os.path.join(self.workspace.log_dir,
f'{self.name}.latest.out')

fs.mkdirp(self.log_dir)

# Create simlinks to give known paths
self.create_simlink(self.log_dir, self.log_dir_latest)
self.create_simlink(self.log_path, self.log_path_latest)

self._software_environments = ramble.software_environments.SoftwareEnvironments(workspace)
self.workspace.software_environments = self._software_environments
self._experiment_set = workspace.build_experiment_set()
Expand Down Expand Up @@ -127,6 +121,11 @@ def _execute(self):

num_exps = self._experiment_set.num_filtered_experiments(self.filters)

if logger.enabled:
fs.mkdirp(self.log_dir)
# Also create simlink to give known paths
self.create_simlink(self.log_dir, self.log_dir_latest)

if self.suppress_per_experiment_prints and not self.suppress_run_header:
logger.all_msg(f' Log files for experiments are stored in: {self.log_dir}')

Expand Down Expand Up @@ -192,6 +191,9 @@ def run(self):
)

logger.add_log(self.log_path)
if logger.enabled:
self.create_simlink(self.log_path, self.log_path_latest)

self._prepare()
self._execute()
self._complete()
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/util/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):
def add_log(self, path):
"""Add a log to the current log stack
Opens (with 'w+' permissions) the file provided by the 'path' argument,
Opens (with 'a+' permissions) the file provided by the 'path' argument,
and stores both the path, and the opened stream object in the current stack
in the active position.
Expand Down

0 comments on commit 4f3b2dc

Please sign in to comment.