From efbf2d59e9443db90537783a3f3e8d1d41c7363b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Laz=C4=83r?= Date: Sat, 12 Dec 2020 17:23:57 +0100 Subject: [PATCH] Adds --log=LEVEL to allow specifying verbosity. --- adb-sync | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/adb-sync b/adb-sync index 3b4eaf6..d5422b2 100755 --- a/adb-sync +++ b/adb-sync @@ -684,9 +684,15 @@ def FixPath(src: bytes, dst: bytes) -> Tuple[bytes, bytes]: return (src, dst) -def main() -> None: - logging.basicConfig(level=logging.INFO) +def GetLogLevel(name: str) -> int: + """Returns the numeric value for the named logging level.""" + level = getattr(logging, name.upper(), logging.INFO) + if not isinstance(level, int): + return logging.INFO + return level + +def main() -> None: parser = argparse.ArgumentParser( description='Synchronize a directory between an Android device and the ' 'local file system') @@ -792,12 +798,21 @@ def main() -> None: '--copy-links', action='store_true', help='transform symlink into referent file/dir') + parser.add_argument( + '--log', + metavar='LEVEL', + default='INFO', + type=str, + help='Minimum log level to display - one of: ' + 'DEBUG INFO WARNING ERROR CRITICAL (default: INFO).') parser.add_argument( '--dry-run', action='store_true', help='Do not do anything - just show what would be done.') args = parser.parse_args() + logging.basicConfig(level=GetLogLevel(args.log)) + localpatterns = [os.fsencode(x) for x in args.source] remotepath = os.fsencode(args.destination) adb_args = os.fsencode(args.adb).split(b' ')