and how to output it.
There are many important levels to choose from, Debug, info, warning, error, and critical. By giving logger or handler different levels, you can output only error messages to a particular record file, or only debug information when debugging. Let's change the logger level to DEBUG and look at the output:
Logging.basicconfig (level=
consider encapsulating it as a class to use
#! /usr/bin/env python #coding =gbk import Logging,os class Logger:def __init__ (self, path,clevel = logging. Debug,flevel = logging. DEBUG): Self.logger = Logging.getlogger (path)
encapsulating it as a class to use
#! /usr/bin/env python#coding=gbkimport logging,osclass logger:def __init__ (self, path,clevel = logging. Debug,flevel = logging. DEBUG): Self.logger = Logging.getlogger (path) self.logger.setLe
directly in this module--production environments are encapsulated into function callsMylogger.info(' Foorbar ')Mylogger.debug (' Just a test ')$ python demo.py2015-10-30 15:44:01,722-mylogger-test1.py-info-foorbar2015-10-30 15:44:01,723-mylogger-test1.py-debug-just a testhttp://www.php101.cn/2015/03/05/Python%E4%B8%AD%E7%9A%84Logging%E7%AE%80%E4%BB%8B/Wonderful
Use python's logging module and pythonlogging Module
I. Starting from a use case
To develop a log system, you must output logs to the console and write log files.
Python code
Import logging
# Create a logger
Logger = logging. getLogger ('mylogger ')
Logger. setLevel (loggin
name% (Lineno) d Call Log output function The statement that is located in the line% ( Created) F current time, the current time in the number of milliseconds (asctime) s string as a percentage of the time that the UNIX standard represents a floating-point (relativecreated) d output log information, since logger was created. The default format is "2003-07-08 16:49:45,896". The comma is followed by the millisecond% (thread) d thread ID. There may not be a% (threadname) s thread name. There may n
timesERROR:root:select db is timeoutCRITICAL:root:server is downFind out why there is no debug and info logs? Originally, by default, logging prints logs to the screen with a log level of warning. Debug and info are below the warnning level, so do not print. We can adjust the terminal output level, for beauty, custom log format#!/usr/bin/env
The log system in the python standard library is supported from Python2.3. You only need to use importlogging. I recently wrote a crawler system and needed the python logging module. so I learned about it.
The log system in the python standard library is supported from Python2.3. You only need to import the
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]
Python logging and pythonlogging1. Simply print logs to the screen
Import logginglogging. debug ('this is debug message') logging.info ('this is info message') logging. warning ('this is warning message'): WARNING: root: This is warning message
By default,
Learn a new technique or language, we must first learn how to adapt to this new technology, which in the adaptation process, we have to learn how to debug the program and play the corresponding log information, is called "as long as the log is good, no bugs can not solve", in our well-known information technology, The Log4xxx series, as well as the Android.util.Log packages for Android apps, are all for developers to get a better log information servi
Introduction to the python logging Module
Use python to write programs, and sometimes use the log system. Especially for dynamic languages like python, many errors can only be found during running. A good log system is very important to Python programs.
The simplest solution
#!/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.
I recently wrote a crawler system and needed the python logging module. So I learned about it.The log system in the python standard library is supported from Python2.3. You only need to import the logging module. If you want to develop a log system, you need to output logs to the console and write log files as long as
This article mainly introduces the log module logging in Python, including the log level under Python and the use of commonly used methods in the module, friends can refer to the following
A log module is used in many applications to record key information during the operation of the system so that it can track the health of the system. In the. NET platform, the
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
Many programmers have the need to log, and the log contains information that has normal program access logs, there may be errors, warnings and other information output, Python logging module provides a standard log interface, you can store a variety of logs through it, you can store various forms of log , the logging log can be divided into five levels:
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.