How to print log debugging information in Python __python

Source: Internet
Author: User
Tags print format
How to print error tracking:

Method 1. Print to screen
Try
i = 0
Mydbhandler.executemany (SQL, TMP)
Logging.info ("[Total cost Time:" + str (time.time ()-start) *1000) + "Ms]"
Print "Total cost time:", (Time.time ()-start) *1000, "MS"
Except
EType, evalue, tracebackobj = Sys.exc_info () [: 3]
print ' Type: ', etype
Print "Value:", Evalue

TRACEBACK.PRINT_TB (Tracebackobj)


Method 2. Print to 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 should go to the log file ')

Try
i = 0
Mydbhandler.executemany (SQL, TMP)
Logging.info ("[Total cost Time:" + str (time.time ()-start) *1000) + "Ms]"
Print "Total cost time:", (Time.time ()-start) *1000, "MS"
Except
EType, evalue, tracebackobj = Sys.exc_info () [: 3]
print ' Type: ', etype
Print "Value:", Evalue
Logging.exception (' Got exception on main handler ')
Raise


Note: Logging is a
reference that can be configured in print format:
Http://stackoverflow.com/questions/1508467/how-to-log-my-traceback-error
http://groups.google.com/group/python-tornado/browse_thread/thread/acf41c6e03045a4c#

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.