Skip to content

Commit

Permalink
add option to write logs in a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ElouanPetereau committed Jun 7, 2021
1 parent 409cf14 commit 6ad46d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
if sys.version_info[0:2] < (2, 6):
raise RuntimeError("smartcard_control requires Python 3.0+ to build.")

VERSION_INFO = (1, 0, 0, 0)
VERSION_STR = '%i.%i.%i' % VERSION_INFO[:3]
VERSION_ALT = '%i,%01i,%01i,%04i' % VERSION_INFO

from smartcard_control.controller.main_controller import VERSION_STR

setup(name="smartcard_control",
version=VERSION_STR,
Expand Down
33 changes: 23 additions & 10 deletions smartcard_control/controller/main_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@
from smartcard_control.view import menu_util
from smartcard_control.view.menu_util import printChooseShareMode

VERSION_INFO = (1, 0, 1, 0)
VERSION_STR = '%i.%i.%i' % VERSION_INFO[:3]

share_mode = SCARD_SHARE_SHARED
disposition = SCARD_LEAVE_CARD
card_manager = None
devices_list_manager = None
logging_level = logging.DEBUG
logging_file = None


def setup_parser():
global logging_level
global logging_level, logging_file

DEFAULT_LOGGING_FILE = "smartcard_control.log"
parser = argparse.ArgumentParser(
description='''
smartcard_controler: A python project to debug and work with Smart cards
Expand All @@ -35,13 +41,14 @@ def setup_parser():

parser.add_argument("-v", "--verbose",
action="count",
help="Use (several times) to be more verbose")
# parser.add_argument("-a", "--arg",
# action="store",
# choices=['choice1', 'choice2'],
# default='choice1',
# help="help info (default: %(default)s)")
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
help="use (several times) to be more verbose")
parser.add_argument("-l", "--logfile",
nargs="?",
action="store",
const=DEFAULT_LOGGING_FILE,
# choices=['choice1', 'choice2'],
help="write project logs in a file instead of the current console (default: ./{})".format(DEFAULT_LOGGING_FILE))
parser.add_argument('--version', action='version', version="%(prog)s {}".format(VERSION_STR))

args = parser.parse_args()

Expand All @@ -56,11 +63,17 @@ def setup_parser():
else:
logging_level = logging.DEBUG

if args.logfile is not None:
logging_file = args.logfile


def main():
# Log config
global logging_level
logging.basicConfig(level=logging_level, format="%(asctime)s [%(levelname)s] %(module)s/%(lineno)d - %(message)s")
global logging_level, logging_file
if logging_file is not None:
logging.basicConfig(level=logging_level, filename=logging_file, format="%(asctime)s [%(levelname)s] %(module)s/%(lineno)d - %(message)s")
else:
logging.basicConfig(level=logging_level, format="%(asctime)s [%(levelname)s] %(module)s/%(lineno)d - %(message)s")

global devices_list_manager
global card_manager
Expand Down

0 comments on commit 6ad46d0

Please sign in to comment.