Implemented a simple version of the Logging.config, support the general configuration through the config file.
There is a better way to feel, and it is to use the Logging.config.fileConfig (Log_config_file) method to read it and modify it by modifying the handler mode.
The code is as follows:
"""Project Trace System"""Import SysImport ConfigparserImport loggingImport Logging.configImport warnings
if __name__ = = "__main__":Log_config_file = "Log.conf"Log_data_file = "Logs/run.log"
Level_dic =
For python, two problems have plagued me over the past few days:1. The current row number and function name cannot be obtained directly in python. This is a question raised by someone in the forum. the people below are just wondering why python does not provide _ line _ and _ func __like _ file __, however, no solution was found.2. How can a function call itself
Background
In a new project to join the log function, want to write a, but a chance, through Google found Python built a very powerful log module: logging. A cursory study, here are some of my notes.
Why use Logs
Trace some of the operation information of the program, in order to achieve the time to understand the status of the program, quickly capture program anomalies, timely detection of the purpose of
Overview:Python's logging module provides a standard log interface through which you can store logs in a variety of formats, logging logs can be divided into,,, and debug() info() warning() error()critical()5个级别。Logging simple usage of log informationBy default, the log level is higher than the info level to have content output.Import Logginglogging.debug ("User[
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
In the previous article we learned why Python is debugging, and the two methods of Python debugging, but the debugging method is not finished, so in this article we will talk about the remaining two debugging methods. Hopefully, these kinds of debugging methods will help you get on the path to learning python faster.
Logging
#很多程序都有记录日志的需求, and the information contained in the log is a normal program access log, there may be errors, warnings and other information output, Python logging module provides a standard log interface, you can store the log in various formats, logging log can be divided into debug (), info (), warning (), error () andcritical () 5 levels importlogging #打印日志
: Specify the time format, same as Time.strftime () level: Set the logging level, which defaults to logging. Warningstream: Specifies the output stream that will log, can specify output to Sys.stderr,sys.stdout or file, default output to Sys.stderr, stream is ignored when stream and filename are specified simultaneouslyNote : The log is set by using the Basicconfig () method, and the default way that the lo
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
Python primarily uses the logging module for log processingMany programs have logging requirements, and the log contains information that has a normal program Access log, there may be errors, warnings and other information output, Python's logging module provides a standard log interface,You can store logs in various f
=[log_entry])transport.close()if result == scribe.ResultCode.OK: sys.exit()elif result == scribe.ResultCode.TRY_LATER:print >> sys.stderr, "TRY_LATER" sys.exit(84) # 'T'else: sys.exit("Unknown error code.")
The usage is as follows:
$echo "hello world" | ./scribe_cat [-h host[:port]] category
To make it easier for the program to use the scribe log aggregation architecture, I integrate scribe log processing into Python
Use Python logging to record log information such as DebugDebug above information written to fileInfo above info output in consoleImport Osimport loggingvde_logging_name = "vde_logging" Log_file_path = Os.path.join (Os.path.dirname (__file__), "Vde_ Regression.log ") def logger_initialization (): # 1. Logging logger = Logging.getlogger (vde_logging_name) logger.s
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 in this case.
The
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.