How to print Error Tracking:
Method 1. Print to the screen
Try:
I = 0
Mydbhandler.exe cute.pdf (SQL, tmp)
Logging.info ("[total cost time:" + str (time. time ()-start) * 1000) + "ms]")
Print "total cost time:", (time. time ()-start) * 1000, "ms"
Except t:
Etype, evalue, tracebackObj = sys. exc_info () [: 3]
Print "Type:", etype
Print "Value:", evalue
Traceback. print_tb (tracebackObj)
Method 2: print to a file
Import logging
LOG_FILENAME = '/tmp/logging_example.out'
Logging. basicConfig (filename = LOG_FILENAME, level = logging. DEBUG ,)
# Log print format Configuration
# Logging. basicconfig (filename = log_filename, level = logging. debug, format = '[% (asctime) S] % (levelname) S: % (filename) S: % (funcname) S: % (Message) s ',)
Logging. debug ('this message shocould go to the log file ')
Try:
I = 0
Mydbhandler.exe cute.pdf (SQL, TMP)
Logging.info ("[total cost time:" + STR (Time. Time ()-Start) * 1000) + "ms]")
Print "total cost time:", (Time. Time ()-Start) * 1000, "Ms"
Except t:
Etype, evalue, tracebackobj = SYS. exc_info () [: 3]
Print "type:", etype
Print "value:", evalue
Logging. Exception ('got exception on main handler ')
Raise
Note: You can configure the printing format for logging.
Refer:
Http://stackoverflow.com/questions/1508467/how-to-log-my-traceback-error
Http://groups.google.com/group/python-tornado/browse_thread/thread/acf41c6e03045a4c #