From 50b2f85cc42a96a1eb7e25957d502dfc14968bf0 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Tue, 9 Jul 2013 07:22:12 +0200 Subject: [PATCH] switch verbosity level via command line --- virtualsmartcard/src/vpicc/vicc.in | 18 ++++++++++++++++-- .../vpicc/virtualsmartcard/VirtualSmartcard.py | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/virtualsmartcard/src/vpicc/vicc.in b/virtualsmartcard/src/vpicc/vicc.in index 2b2f115..61ae1c2 100644 --- a/virtualsmartcard/src/vpicc/vicc.in +++ b/virtualsmartcard/src/vpicc/vicc.in @@ -19,7 +19,7 @@ # virtualsmartcard. If not, see . # -import argparse +import argparse, logging parser = argparse.ArgumentParser( @@ -38,6 +38,9 @@ parser.add_argument("-t", "--type", choices=['iso7816', 'cryptoflex', 'ePass', 'nPA', 'relay', 'handler_test'], default='iso7816', help="type of smart card to emulate (default: %(default)s)") +parser.add_argument("-v", "--verbose", + action="count", + help="Use (several times) to be more verbose") parser.add_argument("-f", "--file", action="store", type=argparse.FileType('r'), @@ -104,8 +107,19 @@ if (args.cvca): cvca = args.cvca.read() args.cvca.close() +if not args.verbose: + logginglevel = logging.CRITICAL +elif args.verbose == 1: + logginglevel = logging.ERROR +elif args.verbose == 2: + logginglevel = logging.WARNING +elif args.verbose == 3: + logginglevel = logging.INFO +else: + logginglevel = logging.DEBUG + vicc = VirtualICC(args.file, args.type, args.hostname, args.port, readernum=args.reader, ef_cardaccess=ef_cardaccess_data, ef_cardsecurity=ef_cardsecurity_data, - ca_key=ca_key_data, cvca=cvca, disable_checks=args.disable_ta_checks) + ca_key=ca_key_data, cvca=cvca, disable_checks=args.disable_ta_checks, logginglevel=logginglevel) vicc.run() diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py b/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py index 0b75fcb..c884ef0 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py @@ -622,10 +622,10 @@ class VirtualICC(object): the vpcd, which forwards it to the application. """ - def __init__(self, filename, card_type, host, port, lenlen=3, readernum=None, ef_cardsecurity=None, ef_cardaccess=None, ca_key=None, cvca=None, disable_checks=False): + def __init__(self, filename, card_type, host, port, lenlen=3, readernum=None, ef_cardsecurity=None, ef_cardaccess=None, ca_key=None, cvca=None, disable_checks=False, logginglevel=logging.INFO): from os.path import exists - logging.basicConfig(level = logging.INFO, + logging.basicConfig(level = logginglevel, format = "%(asctime)s [%(levelname)s] %(message)s", datefmt = "%d.%m.%Y %H:%M:%S")