30
30
31
31
from dragonfly import get_engine , MimicFailure , EngineError
32
32
from dragonfly .loader import CommandModule , CommandModuleDirectory
33
+ from dragonfly .log import setup_log
33
34
34
35
LOG = logging .getLogger ("command" )
35
36
36
37
37
38
#---------------------------------------------------------------------------
38
39
# CLI helper functions.
39
40
40
- def _set_logging_level (args ):
41
- if args .quiet :
42
- args .log_level = "WARNING"
41
+ def _setup_logging (args ):
42
+ # Use the specified logging defaults.
43
+ if args .log_level == "DFLY" :
44
+ setup_log () # Use Dragonfly defaults.
45
+ else :
46
+ logging .basicConfig (level = getattr (logging , args .log_level ))
43
47
44
- # Set up logging with the specified logging level.
45
- logging .basicConfig (level = getattr (logging , args .log_level ))
48
+ # Suppress loader-related informational messages.
49
+ if args .quiet :
50
+ for logger_name in ("command" , "module" , "directory" ):
51
+ logging .getLogger (logger_name ).setLevel (logging .WARNING )
46
52
47
53
48
54
def _init_engine (args ):
@@ -156,8 +162,8 @@ def _do_recognition(engine, args):
156
162
# Main CLI functions.
157
163
158
164
def cli_cmd_test (args ):
159
- # Set the logging level .
160
- _set_logging_level (args )
165
+ # Setup logging.
166
+ _setup_logging (args )
161
167
162
168
# Initialise the specified engine. Return early if there was an error.
163
169
engine = _init_engine (args )
@@ -217,8 +223,8 @@ def cli_cmd_test(args):
217
223
218
224
219
225
def cli_cmd_load (args ):
220
- # Set the logging level .
221
- _set_logging_level (args )
226
+ # Setup logging.
227
+ _setup_logging (args )
222
228
223
229
# Initialise the specified engine. Return early if there was an error.
224
230
engine = _init_engine (args )
@@ -245,8 +251,8 @@ def cli_cmd_load(args):
245
251
246
252
247
253
def cli_cmd_load_directory (args ):
248
- # Set the logging level .
249
- _set_logging_level (args )
254
+ # Setup logging.
255
+ _setup_logging (args )
250
256
251
257
# Initialise the specified engine. Return early if there was an error.
252
258
engine = _init_engine (args )
@@ -400,14 +406,14 @@ def make_arg_parser():
400
406
"reading input from stdin or recognizing speech."
401
407
)
402
408
log_level_argument = _build_argument (
403
- "-l" , "--log-level" , default = "INFO" ,
404
- choices = ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ],
405
- help = "Log level to use."
409
+ "-l" , "--log-level" , default = "DFLY" ,
410
+ choices = ["DFLY" , "DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ],
411
+ help = "Logging defaults/level to use. By default, Dragonfly's "
412
+ "setup_log() function is called."
406
413
)
407
414
quiet_argument = _build_argument (
408
415
"-q" , "--quiet" , default = False , action = "store_true" ,
409
- help = "Equivalent to '-l WARNING' -- suppresses INFO and DEBUG "
410
- "logging."
416
+ help = "Suppress loader-related informational messages."
411
417
)
412
418
413
419
# Create the parser for the "test" command.
0 commit comments