Many of the modules in Python are very bull X, previously mentioned in the logging module (which is similar to the Java log4j), since a recent script involving network troubleshooting requires log output, which is used in Python's logging module to implement. When the logs are all written to a file, the files become more and more over time, and you can use the Ti
= Logging.getlogger ("example01")Logger.debug (' This is Debug message ')Logger.info (' This is Info message ')Logger.warning (' This is warning message ')
In Example 4:
Import loggingImport Logging.configLogging.config.fileConfig ("logger.conf") logger = Logging.getlogger ("Example02")Logger.debug (' This is Debug message ')Logger.info (' This is Info message ')Logger.warning (' This is warning message ')
6.logging
#申明: This article refers to http://www.cnblogs.com/dahu-daqing/p/7040764.htmlLogging Module Introduction# The logging module is a python built-in standard module that is used primarily for output program run logs # you can set the output log level, log save path, log file rollback, etc. # The following advantages than print # 1. You can set different log levels, output only important information, without ha
Several learning connections:Official Python Link:Https://docs.python.org/3.4/library/logging.html?highlight=loggingTranslation (2.3 version only)http://crazier9527.iteye.com/blog/290018Another person's summary:http://blog.csdn.net/fxjtoday/article/details/6307285Best to understand, write the best:Http://bbs.chinaunix.net/thread-3590256-1-1.htmlMy study summary is based on http://bbs.chinaunix.net/thread-3590256-1-1.html
Take a simple log system
http://www.cnblogs.com/dkblog/archive/2011/08/26/2155018.htmlMulti-module problem: Multiple modules use the Logginglogging module to ensure that within the same Python interpreter, multiple calls to Logging.getlogger ('log_name' ) will return the same logger instance,Even in the case of multiple modules. So the typical multi-module scenario using logging is to configure the
This chapter describes the Python built-in module: The log module, for more information, refer to: Python Learning Guide
Simple to useIn the beginning, we experienced the basic function of logging with the shortest code.import= logging.getLogger()logging.basicConfig()logger.setLevel('DEBUG')logger.debug('logsomething')#输出out>>DEBG:root:logsomething
leap!change the format of display informationTo change the default display format, you must specify the display format you want.Import logginglogging.basicconfig (format= '% (levelname) s:% (message) s ', level=logging. DEBUG) Logging.debug (' This message should appear on the console ') Logging.info ("So should this") logging.warning (' and this , too ')Execution resultsDebug:this message should appear on the consoleinfo:so should thiswarning:and th
First, starting from a usage scenarioDevelop a log system that outputs logs to the console and to log filesPython code
Import logging
# Create a Logger
Logger = Logging.getlogger (' MyLogger ')
Logger.setlevel (logging. DEBUG)
# Create a handler to write to the log file
FH = logging. Filehandler (' Test.log ')
Fh.setlevel (
Recently wrote a crawler system, need to use the Python logging module, so they learned a bit.The log system in the Python standard library is supported from Python2.3. As long as import logging This module can be used. If you want to develop a log system, you need to output the log to the console and write to the log
be added through the AddHandler () methodHandler.setlevel (LEL): Specifies the level of information being processed, and information below the LEL level is ignoredHandler.setformatter (): Choose a format for this HandlerHandler.addfilter (filt), Handler.removefilter (filt): Add or remove a filter objectMultiple handler can be attached to each logger. Next, let's introduce some common handler:1) logging. StreamhandlerUsing this handler, you can output
First introduce how to find out, the line of the project log is through the logging module to the Syslog, ran for a period of time to find the syslog UDP connection over 8W, yes 8 W. The main logging module is wrong.
One of the requirements we had before is to output the current connection information for each connection log, so each connection creates a log instance, assigns a Formatter, and creates a log
Log for the program to run and technical personnel is very necessary and very important, troubleshooting is generally from the analysis program to run the log, and then the complexity of the large program must have a log input, otherwise, even if the program is not qualified. Python provides a handy logging module for technicians to define and output logs.Let's take a look at the log level and the simple ou
Log for the program to run and technical personnel is very necessary and very important, troubleshooting is generally from the analysis program to run the log, and then the complexity of the large program must have a log input, otherwise, even if the program is not qualified. Python provides a handy logging module for technicians to define and output logs.Let's take a look at the log level and the simple ou
#!/usr/bin/env python# Encoding:utf-8import logging# defines the handler output format formatter=logging. The Formatter ('% (asctime) s--% (name) s--% (filename) s--% (message) s ') #创建一个handler to write to the log file, outputting only log fh=logging above the debug level. The Filehandler (' Test.log ') fh.setformatte
. Timedrotatingfilehandler (' Web.log ', when= ' s ', interval=3,backupcount=5) Logger.addhandler (File_handler) file_ Formatter = logging. Formatter ('% (name) s-% (asctime) s-% (levelno) s-% (message) s ') File_handler.setformatter (file_formatter) logger.debug (' The Debug ') logger.info (' the info ') logger.warning (' The Warning ') logger.error (' the error ') logger.critical (' The Critical ')Generates one every 5 seconds and needs to be run be
]format=% (name) -12s:% (levelname) -8s% (message) sdatefmt=
Example 3:
Import loggingImport Logging.configLogging.config.fileConfig ("logger.conf")Logger = Logging.getlogger ("example01")Logger.debug (' This are debug message ')Logger.info (' This is info ')Logger.warning (' This are warning message ')
Example 4:
Import loggingImport Logging.configLogging.config.fileConfig ("logger.conf")Logger = Logging.getlogger ("Example02")Logger.debug (' This are
Import Logging ''' Log Level: critical> error> warning> info> Debug. The higher the notset level, the fewer logs are printed, and vice versa. That is, debug: prints all logs (notset is equivalent to debug) info: print info, warning, error, and critical-level logs warning: Print warning, error, and critical-level log error: print error, critical-level log critical: print the critical-level log ''' Handler = Lo
The logging module is a built-in module of Python, the main feature of logging is that it can be shared between modules, and provides different log levels, each module sends logs to the same file or other place, and the most common scenario is to record the information in log files.
1. Logging Log level
"PythonIn [6]
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.