The python logging module may be confusing.The python logging module is mainly a general-purpose log system provided by python. The method used is actually quite simple. The following describes how to call multiple python files wh
. Formatter ('% (asctime) s-% (name) s-% (levelname) s-% (message) s') Handler.setformatter (formatter)#Output to consoleconsole = logging. Streamhandler ()#because it is output to the console, no parameters are requiredConsole.setlevel (Logging.info)#If you do not specify a format, only normal strings are outputConsole.setformatter (Formatter)#specify format, output by formatLogger.addhandler (console) Logger.addhandler (handler) Logger.info ('Ancien
Recently modified the logging related functions in the project and used the logging module in the Python standard library to make some records here. Mainly from official documents and StackOverflow to find some of the content.
Official documents
Technical Blog
Basic usageThe following code shows the most basic usage of
= SmartBufferHandler(num_buffered=2, target=logging.StreamHandler(), flushLevel=logging.ERROR)logger = logging.getLogger(__name__)logger.setLevel("DEBUG")logger.addHandler(handler)logger.error("Hello1")logger.debug("Hello2") # This line won't be loggedlogger.debug("Hello3")logger.debug("Hello4")logger.error("Hello5") # As error will flush the buffered logs, the two last debugs will be logged
Summary
The above section describes the flexibility and con
,' Encoding ': ' Utf-8 ',},}, ' loggers ': {# Logging.getlogger (__name__) received the configuration #把上面定义的两个Handler加到这里 , log is written to the file and hit the terminal. ' handlers ': [ ' default ', ' console ') , ' level ': ' DEBUG ', # Up (higher level logging) pass ' propagate ': true,},},}def load_my_logging_cfg (): Logging.config.dictConfig (logging_dic) #生成个log实例, __name __ The current mo
For Python, there have been two problems that have plagued me these days:There is no way to get the current line number and function name directly in 1.python. This is a question raised in the Forum, a group of people are just guessing why Python does not provide __line__ and __func__ like __file__, but ultimately did not find a solution.2. If a function does not
Recently, in writing a program that uses Python to generate apps, it is found that printing information directly with print is less convenient and prescriptive, so using the logging log module, simply record the usage, The Logging.config configuration log should be used in a formal project to achieve log file size limits like log4j, format control, output location, and so on.1. Simply print the log to the s
Tags: style blog class code java cFirst, PDB useThe PDB is a Python-brought package that provides an interactive source code debugging feature for Python programs, including setting breakpoints, stepping through debugging, entering function debugging, viewing current code, viewing stack fragments, dynamically changing the values of variables, and more.Insert a program in the middle of the program (import PD
logger name% (levelname) s text form of log level% (message) s user output messages" " defInit_logger (self): Self.logger.setLevel (logging. DEBUG) File_handler= Logging. Filehandler ('D:/tmp/test.log') Stream_handler=logging. Streamhandler () Formatter= Logging. Formatt
Gdal_retile.bat in that window will fail because fwtools The Shell sets 6 important environment variables before opening the DOS window, respectively:
---------
Path=c:/progra~1/fwtool~1.7/bin; C:/progra~1/fwtool~1.7/python;
Set Pythonpath=c:/progra~1/fwtool~1.7/pymod
Set fwtools_dir=c:/progra~1/fwtool~1.7
Set Gdal_data=c:/progra~1/fwtool~1.7/data
Set Gdal_driver_path=c:/progra~1/fwtool~1.7/gdal_plugins
Set Geotiff_csv=c:/progra~1/fwtool~1.7/data
Se
filter conditionlogger.debug("test ....")logger.info("test info ....")logger.warning("start to run db backup job ....")logger.error("test error ....")A complete example of output to screen, file, with filter at the same timeImport loggingClassIgnorebackuplogfilter(Logging. Filter):"" Ignores logs with DB backup ""DefFilter(Self, record):#固定写法Return"DB Backup"NotIn record. getMessage()#console Handlerch= Logging
ObjectiveWhen the script runs, sometimes do not know the implementation of use cases, this time can join the log, so that the problem is easy to review, it is easy to check which use cases executed, which did not execute.First, package logging module1. About Logging Log introduction, I do not explain in detail here, there are two major functions, one is the output of the console, one is saved to a local fil
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
future (for Example. Low disk space "). The software will work as Expected.ERROR: a more serious problem, the software does not perform some functionsCRITICAL: a serious error that indicates that the program itself may not continue to runThese 5 levels, also correspond to 5 kinds of methods to hit the Log: debug, info, warning, error, critical. The default is warning, which is tracked only when it is warning or above.2. Log OutputThere are two ways t
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.