Original Address:https://www.cnblogs.com/nancyzhu/p/8551506.htmlLogA log is a way to track events that occur when the software is running. The software developer calls the log function in the code to indicate that a particular event has occurred. an event is described by a descriptive message that can optionally contain variable data (that is, potentially different data for each occurrence of an event). events also have the importance of developers attributing events, and importance can also be
1. Simply print the log to the screen
importlogginglogging.debug(‘This is debug message‘)logging.info(‘This is info message‘)logging.warning(‘This is warning message‘)屏幕上打印:WARNING:root:This is warning message
By default, logging prints the log to the screen with a log level of warning;Log level size relationships are: CRITICAL > ERROR > WARNING > INFO >
python logging modules can be confusing placesfind some interesting phenomena by seeing the code of the Python logging module:1. The logging object is actually a tree structure, and each created logging object is the child node of
This article mainly introduces how to solve the memory leakage caused by misuse of the logging module in Python and the problems caused by excessive UDP connections, if you need it, refer to the following section to describe how to find it. the online project log is sent to syslog through the logging module, after running for a while, we found that the syslog UDP
TCP
6000
TCP
9000
You can also consider the following two methods:1. python-logstashUse logstash to open the UDP or TCP Service port of logstash to accept data directly. The received data can be imported to ElasticSearch or directly output to the file.2. Customize the new handler to store log records in a queue of redis, and then start an additional process to read data from redis into the file.2. Log Level
This article describes the rapid use of the logging module, If you need in-depth customization, please refer to (http://docs.python.org/2/howto/logging-cookbook.html)
Import logging. basicconfig (format = '[% (asctime) S]' + logging. basic_format) # logging. basic_forma
Python's logging module is used to write logs and is a standard Python module.Structure of the logging
View logging python source code, there are four main classes to realize the function;
Loggers: Provides interfaces directly used by the application,
My scheduled task will be 5 o'clock in the morning every day to adjust a transaction, trading logs with the logging module, today found that log has a problem, the following troubleshooting.
When viewing the log, I found that I should have logged 5, and the log time was displayed as2016-09-12 21:00:02,379-info-novel.py[line:82]-Select day
Checked the code, did not find the problem, and then found 21 points and 5 spreads 8 hours, that is, the
Python has a logging module to facilitate the recording of program action logs, this article is a simple example of the use of the logging module:
First introduce logging:
Import xlrdImport MySQLdbImport OSImport logging
First initialize the configuration in the main prog
Running the program is like walking life, some beautiful, not beautiful things need to record down, slowly weighing ~
The logging module is born and records what you want to record.
First, print the log to the screen
Import Logging
Logging.debug (' This is a bug information ')
logging.info (' The ' is a info information ')
Logging.warning (' This is a warning information ')
logging.error (' The ' is a err
1. Simply print the log to the screenImport logginglogging.debug ('This isdebug message') logging.info ( 'this wasinfo message') logging.warning ('This iswarning message ' is warning messageBy default, logging prints the log to the screen with a log level of warning;Log level size relationships are: CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET, and of course you can define the log level yourself.2.
Python's logging module one, simple to print the log to the screenImport LoggingLogging.debug (' This is debug message ')Logging.info (' This is Info message ')Logging.warning (' This is warning message ')The output is WARNING:root:This is warning message.By default, logging prints the log to the screen with a log level of WARNING and a log-level size relationshi
This article is suitable for just contact with the logging module, want to quickly use and see the effect of children's shoes. If you want to fully understand the logging module, please go todirectly on the code + comment#1. Import Module LoggingImportLogging#2. Create a Logger instanceLogger = Logging.getlogger (__name__)#3. Configure log properties (the level of logs that need to be printed)Logger.setleve
The example in this article describes how Python logging the console and file output logs at the same time. Share to everyone for your reference. Specifically as follows:
Python provides a very convenient log module that enables simultaneous output logs to the console and files.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#-*-
1. Simply print the log to the screen
Import loggingLogging.debug (' This are debug message ')Logging.info (' This is info ')Logging.warning (' This are warning message ')Print on screen:WARNING:root:This is WARNING message
By default, logging prints the log to the screen with a log level of warning;The log level size relationship is: CRITICAL > ERROR > WARNING > INFO >
1. Logging module Log levelA simple example of using the logging module:>>>import logging>>>logging.debug ("This ' s a Test Logging") >>>loggin.info ("Still a test Logging ") # The above two lines do not have output by default, you need to specify the log level to line >>>lo
1. Simply print the log to the screen
importlogginglogging.debug(‘This is debug message‘)logging.info(‘This is info message‘)logging.warning(‘This is warning message‘)屏幕上打印:WARNING:root:This is warning message
By default, logging prints the log to the screen with a log level of warning;Log level size relationships are: CRITICAL > ERROR > WARNING > INFO >
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.