Python's Print log logging

Source: Internet
Author: User

1 ImportLogging2 3 4 #Simple Print Log Example5Logging.basicconfig (level=logging. DEBUG)#set the log level, WARN6Logging.warning ('Watch out!')#Would print a message to the console7Logging.info ('I told')#Would not print anything8 9 Ten #Print the log to a file, note that you want to start a new file, or you cannot save the file One defLog_to_file (logs_dir="D:\\test_data\\logs\\log_debug.txt"): ALogging.basicconfig (Filename=logs_dir, level=logging. DEBUG) -Logging.debug ('This message should go to the log file') -Logging.info ('So should this') theLogging.warning ('and this, too') -  -  - Log_to_file () +  - #Multi-parameter logging +Logging.warning ('%s before you%s',' Look','leap!') A  at #print time in log -Logging.basicconfig (format='% (asctime) s% (message) s') -Logging.warning ('is while this event was logged.') -  - #Specify a time format -Logging.basicconfig (format='% (asctime) s% (message) s', datefmt='%y-%m-%d%i:%m:%s%p') inLogging.warning ('is while this event was logged.')
Note: The logging parameter settings are only valid until the first run, and can only be set once, and subsequent settings are not valid.

Specify the time format to run the result:
1 # Specify a time format 2  is while this event was logged.

Python's Print log logging

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.