Commit 8fb98234 authored by Marco Mariani's avatar Marco Mariani

refactored setup_logger()

parent 5d47a675
...@@ -242,21 +242,25 @@ def merged_options(args, config): ...@@ -242,21 +242,25 @@ def merged_options(args, config):
def setup_logger(options): def setup_logger(options):
logger = logging.getLogger(__name__)
if options.get('logfile'):
handler = logging.FileHandler(options['logfile'])
else:
handler = logging.StreamHandler()
if options['verbose']: if options['verbose']:
level = logging.DEBUG handler.setLevel(logging.DEBUG)
else: else:
level = logging.INFO handler.setLevel(logging.INFO)
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s',
level=level, formatter = logging.Formatter(fmt='%(asctime)s %(name)-18s: '
datefmt='%Y-%m-%dT%H:%M:%S') '%(levelname)-8s %(message)s',
if options.get('logfile'): datefmt='%Y-%m-%dT%H:%M:%S')
console = logging.FileHandler(options['logfile'])
console.setLevel(level) handler.setFormatter(formatter)
console.setFormatter(logging.Formatter( logger.addHandler(handler)
'%(asctime)s %(name)-18s: %(levelname)-8s %(message)s'))
logging.getLogger('').addHandler(console)
logger = logging.getLogger(__name__)
return logger return logger
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment