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

refactored setup_logger()

parent 5d47a675
......@@ -242,21 +242,25 @@ def merged_options(args, config):
def setup_logger(options):
logger = logging.getLogger(__name__)
if options.get('logfile'):
handler = logging.FileHandler(options['logfile'])
else:
handler = logging.StreamHandler()
if options['verbose']:
level = logging.DEBUG
handler.setLevel(logging.DEBUG)
else:
level = logging.INFO
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s',
level=level,
handler.setLevel(logging.INFO)
formatter = logging.Formatter(fmt='%(asctime)s %(name)-18s: '
'%(levelname)-8s %(message)s',
datefmt='%Y-%m-%dT%H:%M:%S')
if options.get('logfile'):
console = logging.FileHandler(options['logfile'])
console.setLevel(level)
console.setFormatter(logging.Formatter(
'%(asctime)s %(name)-18s: %(levelname)-8s %(message)s'))
logging.getLogger('').addHandler(console)
logger = logging.getLogger(__name__)
handler.setFormatter(formatter)
logger.addHandler(handler)
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