1717logger = logging .getLogger (__name__ )
1818
1919
20- _VERBOSITY_LEVEL = {0 : logging .WARNING , 1 : logging .INFO , 2 : logging .DEBUG }
21-
22-
2320def _find_configuration (source_dir , config_path ):
2421 """Find and load configuration from multiple possible sources.
2522
@@ -54,6 +51,21 @@ def _find_configuration(source_dir, config_path):
5451 return config
5552
5653
54+ def _setup_logging (* , verbose ):
55+ _VERBOSITY_LEVEL = {0 : logging .WARNING , 1 : logging .INFO , 2 : logging .DEBUG }
56+ verbose = min (2 , max (0 , verbose )) # Limit to range [0, 2]
57+
58+ format_ = "%(levelname)s: %(message)s"
59+ if verbose >= 2 :
60+ format_ += " py_source=%(filename)s#L%(lineno)d::%(funcName)s"
61+
62+ logging .basicConfig (
63+ level = _VERBOSITY_LEVEL [verbose ],
64+ format = format_ ,
65+ stream = sys .stderr ,
66+ )
67+
68+
5769@click .command ()
5870@click .version_option (__version__ )
5971@click .argument ("source_dir" , type = click .Path (exists = True , file_okay = False ))
@@ -72,12 +84,7 @@ def _find_configuration(source_dir, config_path):
7284@click .option ("-v" , "--verbose" , count = True , help = "Log more details." )
7385@click .help_option ("-h" , "--help" )
7486def main (source_dir , out_dir , config_path , verbose ):
75- verbose = min (2 , max (0 , verbose )) # Limit to range [0, 2]
76- logging .basicConfig (
77- level = _VERBOSITY_LEVEL [verbose ],
78- format = "%(levelname)s: %(filename)s#L%(lineno)d::%(funcName)s: %(message)s" ,
79- stream = sys .stderr ,
80- )
87+ _setup_logging (verbose = verbose )
8188
8289 source_dir = Path (source_dir )
8390 config = _find_configuration (source_dir , config_path )
0 commit comments