diff --git a/gp2040ce_bintools/__init__.py b/gp2040ce_bintools/__init__.py index 6f72632..cc20164 100644 --- a/gp2040ce_bintools/__init__.py +++ b/gp2040ce_bintools/__init__.py @@ -17,11 +17,20 @@ except ImportError: from setuptools_scm import get_version __version__ = get_version(root='..', relative_to=__file__) +# configure basic logging and logger for this module +root = logging.getLogger() +root.setLevel(logging.DEBUG) +handler = logging.StreamHandler(sys.stderr) +formatter = logging.Formatter('%(asctime)s %(levelname)8s [%(name)s] %(message)s') +handler.setFormatter(formatter) +root.addHandler(handler) + logger = logging.getLogger(__name__) # parse flags that are common to many tools (e.g. adding paths for finding .proto files) core_parser = argparse.ArgumentParser(add_help=False) core_parser.add_argument('-v', '--version', action='version', version=f"%(prog)s {__version__}") +core_parser.add_argument('-d', '--debug', action='store_true', help="enable debug logging") core_parser.add_argument('-P', '--proto-files-path', type=pathlib.Path, default=list(), action='append', help="path to .proto files to read, including dependencies; you will likely need " "to supply this twice, once for GP2040-CE's .proto files and once for nanopb's") @@ -29,6 +38,11 @@ args, _ = core_parser.parse_known_args() for path in args.proto_files_path: sys.path.append(os.path.abspath(os.path.expanduser(path))) +if args.debug: + handler.setLevel(logging.DEBUG) +else: + handler.setLevel(logging.WARNING) + def get_config_pb2(): """Retrieve prebuilt _pb2 file or attempt to compile it live."""