Skip to content

Commit c06b2e1

Browse files
authored
Added logging levels (#131)
* added logging levels * fix imports * remove the log set level flags * set log levels before parsing extras * dont remove the log flags for docker run * do not pass log level arg to script automation * maps multiple similar log levels to one
1 parent 8f90c70 commit c06b2e1

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

mlc/logger.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def setup_logging(log_path = os.getcwd(),log_file = 'mlc-log.txt'):
2525

2626
if not logger.hasHandlers():
2727
logFormatter = ColoredFormatter('[%(asctime)s %(filename)s:%(lineno)d %(levelname)s] - %(message)s')
28+
# by default logging level is set to INFO is being set
2829
logger.setLevel(logging.INFO)
2930

3031

mlc/main.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from . import utils
88

9-
from .action import Action, logger, default_parent
9+
from .action import Action, default_parent
1010
from .repo_action import RepoAction
1111
from .script_action import ScriptAction
1212
from .cache_action import CacheAction
@@ -15,7 +15,7 @@
1515

1616
from .item import Item
1717
from .action_factory import get_action
18-
from .logger import logger
18+
from .logger import logger, logging
1919

2020

2121
class Automation:
@@ -167,9 +167,29 @@ def main():
167167

168168
# Parse arguments
169169
args = parser.parse_args()
170-
170+
171171
#logger.info(f"Args = {args}")
172172

173+
# set log level for MLCFlow if -v/--verbose or -s/--silent is specified
174+
log_flag_aliases = {
175+
'-v': '--verbose',
176+
'-s': '--silent'
177+
}
178+
179+
log_levels = {
180+
'--verbose': logging.DEBUG,
181+
'--silent': logging.WARNING
182+
}
183+
184+
# Modify args.extra in place
185+
args.extra[:] = [log_flag_aliases.get(arg, arg) for arg in args.extra]
186+
187+
# Set log level based on the first matching flag
188+
for flag, level in log_levels.items():
189+
if flag in args.extra:
190+
logger.setLevel(level)
191+
args.extra.remove(flag)
192+
173193
res = utils.convert_args_to_dictionary(args.extra)
174194
if res['return'] > 0:
175195
return res
@@ -215,7 +235,7 @@ def main():
215235
if help_text != "":
216236
print(help_text)
217237
sys.exit(0)
218-
238+
219239
if hasattr(args, 'repo') and args.repo:
220240
run_args['repo'] = args.repo
221241

0 commit comments

Comments
 (0)