Python's logging module

Source: Internet
Author: User

Logging

Module for easy logging and thread-safe

Importlogging logging.basicconfig (filename='Log.log', Format='% (asctime) s-% (name) s-% (LevelName) s-% (module) s:% (message) s', Datefmt='%y-%m-%d%h:%m:%s%p', level=10) Logging.debug ('Debug') Logging.info ('Info') logging.warning ('Warning') Logging.error ('Error') logging.critical ('Critical') Logging.log (10,'Log')

Log level:

CRITICAL = = ==+ = == =0

Note: log files are logged only if the current write level is greater than the log level.

2. Multi-File Log

For the above logging functionality, only the log can be recorded in a single file, if you want to set up multiple log files, Logging.basicconfig will not complete, you need to customize the file and Log action objects.

#definition fileFile_1_1 = logging. Filehandler ('L1_1.log','a', encoding='Utf-8') FMT= Logging. Formatter (fmt="% (asctime) s-% (name) s-% (LevelName) s-% (module) s:% (message) s") File_1_1.setformatter (FMT) file_1_2= Logging. Filehandler ('L1_2.log','a', encoding='Utf-8') FMT=logging. Formatter () file_1_2.setformatter (FMT)#Defining LogsLogger1 = logging. Logger ('S1', level=logging. ERROR) Logger1.addhandler (file_1_1) Logger1.addhandler (file_1_2)#Write LogLogger1.critical ('1111')
Log One
# definition file file_2_1 = logging. Filehandler ('l2_1.log'a'= logging. Formatter () file_2_1.setformatter (FMT)#  defines the log Logger2 = logging. Logger ('s2', level=logging.info) Logger2.addhandler (file_2_1)
log (ii)

such as the two log objects created above

    • When the log is written using "Logger1", the corresponding content is written to the L1_1.log and L1_2.log files
    • When the log is written using "Logger2", the corresponding content is written to the L2_1.log file

Python's logging module

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.