Reprint: http://www.cnblogs.com/goodhacker/p/3355660.htmlThe 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 file, as long as you use:1ImportLogging23#Create a Logger4 Logger = Logging.getlogger (‘MyLogger‘)5Logger.setlevel (
as follows:
$ python logging_level_example.py Debug
DEBUG:root:This is a debug message
INFO:root:This is a info message
WARNING:root:This is a WARNING message
ERROR:root:This is a error message
CRITICAL:root:This is a CRITICAL error message
$ python logging_level_example.py InfoINFO:root:This
One solution:
Debug the script with the PYTHON-M PDB logger.py statement, and after executing the instance = Test () statement, pass print ' \ n '. Join (['%s:%s '% item for item in Self.data_logg Er.__dict__.items ()]) The debug statement saw that the value of the Disable property of Data_logger was changed from 0 to true, and the corresponding property of logg
The logging encapsulation of python is updated. Currently, it supports outputting data to the console, file, and socket at the same time. At the same time, you can clear all the handler of the root logger When configuring config_logging or config_logging_plus, avoid repeated output in some cases.DetailsCodeAs follows:
# -*-Coding: UTF-8 -*- ''' Modified on 2012-11-27 @ Summary: Clear old root logger ha
Module-level functionsLogging.getlogger ([name]): Returns a Logger object that returns root if no name is specified loggerLogging.debug (), Logging.info (), logging.warning (), Logging.error (), logging.critical (): Set the log level for root loggerLogging.basicconfig (): Establishes a streamhandler for the logging system with the default formatter, sets the base configuration and adds it to root loggerLog levelLogging.basicconfig (): Establishes a st
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
Objective
It is believed that every programmer should know that when using Python to write background tasks, it is often necessary to use an output log to record the state of the program running, and to save the details of the error in case of an error to debug and analyze. The Python logging module is a good helper i
.
% (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
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
For ease of debugging, the python logging module is encapsulated to support simultaneous output to the console and file, and log file rollback.(1) myloggingconfig. py
View code
# -*-Coding: UTF-8 -*- ''' Created on 2011-8-24Main purpose:PairProgramGeneral configuration of the loggong mode used in@ Author: jerrykwan ''' Import Logging Import
1.logging ModuleThe logging module is the log module used to record the state of the program's operation.There are five levels:
Debug
Info
Warning
Error
Critical
Logging.debug ('Debug Message') #logging. info ('Info Message') logging.warning ('
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
[Blog recommendation] logging module of python Howto (1)
This blog post is from Bkjia. If you have any questions, go to the blog page for an interactive discussion!Blog: http://xdzw608.blog.51cto.com/4812210/1608718
This article comes from the understanding of the source code added to the howto-logging section in py2.7.9 docs. The official do
= 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 ('
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.
Python logging modulePython logging provides a standard logging interface, and the Python logging log is divided into 5 levels:debug(), info(), warning(), error() and critical()Simple usageimport logginglogging.warning("warning...
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
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.