Skip to content

Commit

Permalink
Merge pull request #297 from ornlneutronimaging/log_to_file
Browse files Browse the repository at this point in the history
Add log file entry to backend engine
  • Loading branch information
KedoKudo authored Mar 8, 2024
2 parents 2fb979b + 31ef8b7 commit bdd1581
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/imars3d/backend/workflow/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from enum import Enum
import importlib
from typing import Any, Optional
from pathlib import Path
import logging


class WorkflowEngineExitCodes(Enum):
Expand Down Expand Up @@ -238,6 +240,20 @@ def _dryrun(self) -> None:

def run(self) -> None:
r"""Sequential execution of the tasks specified in the JSON configuration file."""
# set the logger file if it is specified in the configuration
log_file_name = self.config.get("log_file_name", "")
if log_file_name:
# create log file to capture the root logger, in order to also capture messages from the backend
log_file_path = Path(log_file_name)
log_file_handler = logging.FileHandler(log_file_path)
log_file_handler.setLevel(logging.INFO)
# set formatter
formatter = logging.Formatter("[%(levelname)s] - %(asctime)s - %(name)s - %(message)s")
log_file_handler.setFormatter(formatter)
# add handler to root logger
root_logger = logging.getLogger()
root_logger.addHandler(log_file_handler)
# verify the inputs are sensible
self._dryrun()
# initialize the registry of global parameters with the metadata
self._registry = {k: v for k, v in self.config.items() if k not in ("name", "tasks")}
Expand Down
1 change: 1 addition & 0 deletions tests/data/json/good_non_interactive_full.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "name for reconstructed ct scans",
"workingdir": "/path/to/working/dir",
"outputdir": "/tmp/imars3d/",
"log_file_name": "/tmp/test_run.log",
"tasks": [{
"name": "task1",
"function": "imars3d.backend.dataio.data.load_data",
Expand Down

1 comment on commit bdd1581

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for imars3d-dev has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/imars-deploy/-/pipelines/536462"

Please sign in to comment.