Skip to content

Commit 4bdd6b7

Browse files
committed
Include logging.json in package and allow logging.json overrides
1 parent 9e2c368 commit 4bdd6b7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
include versioneer.py
44
include monai/deploy/_version.py
5+
include monai/deploy/logging.json
56

67
include README.md
78
include LICENSE

monai/deploy/cli/main.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ def parse_args(argv: Optional[List[str]] = None, default_command: Optional[str]
3131
argv = sys.argv
3232
argv = list(argv) # copy argv for manipulation to avoid side-effects
3333

34+
# We have intentionally not set the default using `default="INFO"` here so that the default
35+
# value from here doesn't override the value in "logging.json" unless the user indends to do
36+
# so. If the user doesn't use this flag to set log level, this argument is set to "None"
37+
# and the logging level specified in "logging.json" is used.
3438
parent_parser = argparse.ArgumentParser()
35-
parent_parser.add_argument('-l', '--log-level', dest='log_level', default='INFO', type=str.upper,
39+
parent_parser.add_argument('-l', '--log-level', dest='log_level', type=str.upper,
3640
choices=['DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL'],
37-
help='Set the logging level')
41+
help='Set the logging level (default: INFO)')
3842

3943
parser = argparse.ArgumentParser(parents=[parent_parser],
4044
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
@@ -74,11 +78,18 @@ def set_up_logging(level: str):
7478
Args:
7579
level: logging level (DEBUG, INFO, WARN, ERROR, CRITICAL)
7680
"""
77-
default_log_dir = Path(__file__).absolute().parent.parent.parent.parent
78-
default_config = default_log_dir / "logging.json"
79-
with open(default_config, 'r') as f:
80-
config_dict = json.load(f)
81-
config_dict['root']['level'] = level
81+
# Default log config directory
82+
log_config_dir = Path(__file__).absolute().parent.parent
83+
84+
# If a logging.json file exists in the current folder, it overrides the default one
85+
if Path('logging.json').exists():
86+
log_config_dir = Path.cwd()
87+
88+
logging_config = log_config_dir / "logging.json"
89+
config_dict = json.loads(logging_config.read_bytes())
90+
91+
if level is not None:
92+
config_dict['root']['level'] = level
8293
logging.config.dictConfig(config_dict)
8394

8495

File renamed without changes.

0 commit comments

Comments
 (0)