Permalink
Browse files

Print logger to file and screen, and execute stuff including capturing

exceptions exception
  • Loading branch information...
1 parent b8a2949 commit bdc071cd02484fbdab19a8a24e35bc0286387d9d @ik5 committed Feb 5, 2013
Showing with 18 additions and 2 deletions.
  1. +18 −2 convert_quotes.py
View
@@ -18,9 +18,23 @@ def init_logger() :
# even our editors/ide support this :P
#
logger = logging.getLogger('convert_quotes')
+
+ # place output to file
handler = logging.FileHandler('log/convert.log')
formatter = logging.Formatter(('[%(asctime)s - %(levelname)s] '
'%(message)s'))
+ handler.setLevel(logging.DEBUG)
+ handler.setFormatter(formatter)
+ logger.addHandler(handler)
+
+ # place output to screen
+ ch = logging.StreamHandler()
+ ch.setLevel(logging.DEBUG)
+ ch_format = logging.Formatter('%(levelname)s %(message)s')
+ ch.setFormatter(ch_format)
+
+ logger.addHandler(ch)
+
return logger
@@ -155,7 +169,9 @@ def run(con, logger = LOGGER) :
try :
run()
- except Exception as e :
- LOGGER.critical('Unexpected exception was raised: %s', e)
+ except :
+ LOGGER.critical('Unexpected exception was raised: %s',
+ sys.exc_info()[0])
finalize(con)
+ sys.exit()

0 comments on commit bdc071c

Please sign in to comment.