send the log records (created by loggers) to the appropriate destination.
Filters provide a finer grained facility for determining which log records to output.
Formatters specify the layout of log records in the final output.
#!/usr/bin/env python#-*-coding:utf-8-*-#-author-lian import Logging #创建loggerlogger = Logging.getlogger ("Test_ Log ") #创建logger对象 parenthesis Content logger.setlevel (logging.in
OS Module (Supplemental) 1. View current path and switch path>>> Import OS>>> OS.GETCWD () #获取当前文件所在的路径' D:\\python\\lib\\idlelib '>>> Os.chdir ('.. /') #切换当上一层目录, this can be a relative path>>> OS.GETCWD ()' D:\\python\\lib '>>> os.chdir (' D:\Program Files (x86) ') #也可以是绝对路径>>> OS.GETCWD ()' D:\\Program Files (x86) 'Add:Found on Pycharm that OS.GETCWD () and Os.path.realpath ("./") return the absolute pat
Below for you to share a python through the logging write log to file and console instances, has a good reference value, I hope to be helpful. Come and see it together.
As shown below:
Import Logging # Creates a logger logger = Logging.getlogger (' MyLogger ') logger.setlevel (logging. DEBUG) # Creates a handler that
log information is output, the number of milliseconds since logger was created% (asctime) s The current time in string form. The default format is "2003-07-08 16:49:45,896". The comma is followed by milliseconds%(thread) d thread ID. Probably not .%(threadname) s thread name. Probably not .%(process) d ID. Probably not .% (message) s user-output messageparameter ConfigurationLogging Object ConfigurationImportLoggingdefMy_logger (Filename,file=true,stream =True): Logger=Logging.getlogger () Form
created
% (asctime) s The current time in string form. The default format is "2003-07-08 16:49:45,896". The comma is followed by milliseconds
% (thread) d thread ID. Probably not.
% (threadname) s thread name. Probably not.
% (process) d process ID. Probably not.
% (message) s user-output message
Logger object: Can print the file, also can output the screenImport logging# creates a logger object and is named log =
When using Python to write background tasks, it is often necessary to use the output log to record the state of the program running and to save the details of the error when an error occurs, so that you do not debug and analyze it. Python's logging module is a good helper in this case. This article introduces the performance of the log logging module in
Reference: http://blog.csdn.net/zyz511919766/article/details/25136485Logging moduleThe log has 5 levels, debug,info,warning,error,critical, respectively, and the corresponding level numbers are 10,20,30,40,50Output log standards to the screen#!/usr/bin/env python#-*-coding:utf-8-*-ImportLogginglogging.debug ("Welcome to Akon Debug System") Logging.info ("Welcome to Akon Info System") logging.warning ("Welcome to Akon Warning System") Logging.error ("W
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 information to any f
ObjectiveRecently in the Python Project code that maintains the project, the project uses the Python log module logging, which sets the number of saved logs, but does not take effect, and cleans up the data periodically through contab.AnalysisThe project uses the logging Timedrotatingfilehandler:1 #!/user/bin/env pytho
Python's log function, began to run on the python2.4, a variety of error, and later replaced by python2.7.9.Attach the Linux python upgrade process:1. Download the Python installation package---Python-2.7.9. Tar.xz 2, download to download directory, unzip tar -xzvf Python-3.3. 0.tgz 3, enter the uncompressed folder CD
the configuration file2.1.1 View Import configparserconfig=configparser. Configparser () config.read('example.ini')print(' bitbucket.org' in config)print(config[' bitbucket.org'['user'])2.1.2 to traverse the key of a file2.1.3 Increase ImportConfigparserconfig=Configparser. Configparser () Config.read ('Example.ini')Print('bitbucket.org' inchconfig)Print(config['bitbucket.org']['User']) config.add_section ('Haibin') Config.set ('Haibin','K1','value') with open ('Example.ini','W') as
Log processing operations may occur in many programming languages, and python is no exception...
Next let's take a look atModule
The module mainly processes logs. The so-called logs can be understood as some running information recorded during software operation. Software developers can add logs as needed, logs can help software developers understand the running information of software, especially for software maintenance. Log Level: Level When it's u
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 information to any f
In Python,LoggingThe module mainly deals with logs. The so-called log, can be understood as the software in the course of operation, the recorded some of the operational information software developers can add logs according to their own needs, logs can help software developers understand the operation of the software information, the maintenance of the software is particularly important. Log level: Levels when it ' s used DEBUG detailed Informatio
output
The results under grep pysimplelib
The code is as follows:
./client.py:33:logging.basicconfig (format= '% (levelname) s:% (message) s ', level=logging. WARNING)
./simplexml.py:27:logging.basicconfig (format= '% (levelname) s:% (message) s ', level=logging. WARNING)
./transport.py:30:logging.basicconfig (format= '% (levelname) s:% (message) s ', level=loggin
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.