One, logging moduleImport logginglogging.debug ('This isdebug message') logging.info (' This is info message ' ) logging.warning ('This waswarning 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.DEBUG: Detailed infor
= 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
Logging, so the name wanton is the log, I 艹, this cultural heritage!Logging is a python built-in log module that facilitates log writing and output for everyday applicationsThe logging is divided into 5 log levels, namely:Debug, info, warning, error, critical (ranked by order)where info is the log level that is often a
my use case reference directory is as follows2. First set the file path address to save log to local, for example: Log_path = "D:\\test\\newp\\report"Third, use case codeThe following is a simple Baidu search case for reference only# Coding:utf-8Import Unittest,timeFrom Common.logger import LogFrom selenium import WebdriverLog = log ()Class Test (UnitTest. TestCase):def setUp (self):Self.driver = Webdriver. Firefox ()Self.driver.get ("https://www.baidu.com")Self.driver.implicitly_wait (30)def t
Python Logging Module TOC
Objective
Design of logging Module
The logical inheritance structure of logger
Log output to multiple I/O devices
Log format and Content rich
The level of logging is also the classification of the log on the level dimension.
You can filter by the
This article mainly introduces the usage examples of the logging module in Python, and introduces the usage of the logging module in the form of instances, which has some practical value, for more information about how to use the logging module, see the examples in this article. The specific method is as follows:
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
#申明: 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
.
% (ThreadName) s
The name of the thread. Probably not.
% (process) d
The process ID. Probably not.
% (message) s
User-Output messages
Python uses the logging module to log logs involving four main classes:Logger provides an interface that the application can use directly;Handler sends the log record (created by logger) to the appropriate de
. Installing Mysql-python0. Get http://softlayer-ams.dl.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/ Mysql-python-1.2.4b4.tar.gz1. Tar zxvf mysql-python-1.2.4b4.tar.gz2. CD mysql-python-1.2.4b4.tar.gz; Python se
Python's logging module provides a common log system, can be convenient for third-party modules or applications, the following article mainly introduces some knowledge about the use of logging library in Python summary, the text gives a detailed example code, the need for friends can reference, Let's take a look below.
Objective
Recently because of the needs of
Python implements the ability to write logs to logging. The logging module is still very useful.1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4 #@Time: 2018/4/25 17:055 #@Author: Zms6 #@Site:7 #@File: log.py8 #@Software: pycharm Community Edition9 Ten Import Time One ImportLogging A ImportOS - fromLogging.handlersImportRotatingfilehandler - theProject_dir = Os.
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
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
For Python, there are 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, and the bottom group is just guessing why Python does not offer __line__ and __func__ like __file__, but it does not find a solution at the end.
2. If a function does not
recently when doing automated testing, want to add a log to him, so use the logging module, the following is the Python add log several waysFirst, the Python code configuration (of course, there is a multi-module common Python code settings, this online there are many examples, it is not here to repeat)Import loggingIm
Label:Debug The first method is simple and straightforward, which is to print print out the variables that might be problematic: >>> def foo (s):
n= Int (s)
print ' >>> n =%d '% n
return 10/n
>>> def main (): C6/>foo (' 0 ')
>>> main ()
>>> n = 0
Traceback (most recent call last):
File " Assertion Where print is used to assist in viewing, you can replace it with an assertion (assert): >>> def foo (s):
N=int (s)
assertn!=0, ' n is zero '
return10/n
>>> def main ():
foo (' 0 ')
>>
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.