Skip to content

Commit

Permalink
Enable redirection of all loggers by configuring a FileHandler within…
Browse files Browse the repository at this point in the history
… the bundle (#8142)

Fix Project-MONAI/model-zoo#658, part of #7513

### Description
Enable redirection of all loggers by configuring a FileHandler within
the bundle

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
KumoLiu and pre-commit-ci[bot] authored Oct 23, 2024
1 parent a6f8f68 commit 90173c9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions monai/bundle/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,6 @@ def create_workflow(
"""
_args = update_kwargs(args=args_file, workflow_name=workflow_name, config_file=config_file, **kwargs)
_log_input_summary(tag="run", args=_args)
(workflow_name, config_file) = _pop_args(
_args, workflow_name=ConfigWorkflow, config_file=None
) # the default workflow name is "ConfigWorkflow"
Expand All @@ -1969,7 +1968,7 @@ def create_workflow(
workflow_ = workflow_class(**_args)

workflow_.initialize()

_log_input_summary(tag="run", args=_args)
return workflow_


Expand Down
2 changes: 1 addition & 1 deletion monai/bundle/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ def __init__(
else:
raise FileNotFoundError(f"Cannot find the logging config file: {logging_file}.")
else:
logger.info(f"Setting logging properties based on config: {logging_file}.")
fileConfig(str(logging_file), disable_existing_loggers=False)
logger.info(f"Setting logging properties based on config: {logging_file}.")

self.parser = ConfigParser()
self.parser.read_config(f=config_file)
Expand Down
2 changes: 1 addition & 1 deletion monai/handlers/stats_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(
output_transform: Callable = lambda x: x[0],
global_epoch_transform: Callable = lambda x: x,
state_attributes: Sequence[str] | None = None,
name: str | None = "StatsHandler",
name: str | None = "monai.handlers.StatsHandler",
tag_name: str = DEFAULT_TAG,
key_var_format: str = DEFAULT_KEY_VAL_FORMAT,
) -> None:
Expand Down
6 changes: 3 additions & 3 deletions monai/networks/trt_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self, plan_path, logger=None):
logger: optional logger object
"""
self.plan_path = plan_path
self.logger = logger or get_logger("trt_compile")
self.logger = logger or get_logger("monai.networks.trt_compiler")
self.logger.info(f"Loading TensorRT engine: {self.plan_path}")
self.engine = engine_from_bytes(bytes_from_path(self.plan_path))
self.tensors = OrderedDict()
Expand Down Expand Up @@ -288,7 +288,7 @@ def __init__(
self.fallback = fallback
self.disabled = False

self.logger = logger or get_logger("trt_compile")
self.logger = logger or get_logger("monai.networks.trt_compiler")

# Normally we read input_names from forward() but can be overridden
if input_names is None:
Expand Down Expand Up @@ -563,7 +563,7 @@ def find_sub(parent, submodule):
else:
wrap(model, base_path)
else:
logger = logger or get_logger("trt_compile")
logger = logger or get_logger("monai.networks.trt_compiler")
logger.warning("TensorRT and/or polygraphy packages are not available! trt_compile() has no effect.")

return model
2 changes: 1 addition & 1 deletion monai/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def run_cmd(cmd_list: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
if kwargs.pop("run_cmd_verbose", False):
import monai

monai.apps.utils.get_logger("run_cmd").info(f"{cmd_list}") # type: ignore[attr-defined]
monai.apps.utils.get_logger("monai.utils.run_cmd").info(f"{cmd_list}") # type: ignore[attr-defined]
try:
return subprocess.run(cmd_list, **kwargs)
except subprocess.CalledProcessError as e:
Expand Down

0 comments on commit 90173c9

Please sign in to comment.