@@ -31,10 +31,14 @@ def parse_args(argv: Optional[List[str]] = None, default_command: Optional[str]
31
31
argv = sys .argv
32
32
argv = list (argv ) # copy argv for manipulation to avoid side-effects
33
33
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.
34
38
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 ,
36
40
choices = ['DEBUG' , 'INFO' , 'WARN' , 'ERROR' , 'CRITICAL' ],
37
- help = 'Set the logging level' )
41
+ help = 'Set the logging level (default: INFO) ' )
38
42
39
43
parser = argparse .ArgumentParser (parents = [parent_parser ],
40
44
formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
@@ -74,11 +78,18 @@ def set_up_logging(level: str):
74
78
Args:
75
79
level: logging level (DEBUG, INFO, WARN, ERROR, CRITICAL)
76
80
"""
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
82
93
logging .config .dictConfig (config_dict )
83
94
84
95
0 commit comments