Example of using the logging module in Python, pythonlogging

Source: Internet
Author: User

Example of using the logging module in Python, pythonlogging

The examples in this article describe how to use the logging module and share them with you for your reference. The specific method is as follows:

Import logging import OS log = logging. getLogger () formatter = logging. formatter ('[% (asctime) s] [% (name) s] % (levelname) s: % (message) s') stream_handler = logging. streamHandler () file_handler = logging. fileHandler (OS. path. join ("c: \", "analysis. log ") file_handler.setFormatter (formatter) stream_handler.setFormatter (formatter) log. addHandler (file_handler) log. addHandler (stream_handler) log. setLevel (logging. DEBUG) log. warn ("a warning % s" % "c :\\")

The program running result is as follows:

[10:23:58, 905] [root] WARNING: a warning c :\

I hope this article will help you with Python programming.


What is the concept of a module in python? Can I use a simple example?

A module is a file, and the imported file is imported into the corresponding module. You can use the classes, functions, variables, and other information defined in the module. If there are many modules, you can use packages to manage them. You can put the files into a folder and add a _ init _. py file.

Where is the default log file stored in the logging module of python?

When configuring log file objects, you need to fill in the location of the log file. I put them all according to project requirements.
No research is performed by default.

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.