Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

exceptions exception
  • Loading branch information...
commit bdc071cd02484fbdab19a8a24e35bc0286387d9d 1 parent b8a2949
@ik5 authored
Showing with 18 additions and 2 deletions.
  1. +18 −2 convert_quotes.py
View
20 convert_quotes.py
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.