Python Logging ModuleIn view of the complexity of recent projects, the simple print debugging method has been unable to meet the growing bug, so bloggers turned to logging.First, basic usageCan be used directly as print# coding=utf-8import logginglogging.debug("debug message")logging.info("info message")logging.warning("warning message")logging.error("error message")logging.critical("critical message")‘‘‘WA
In Python,LoggingThe module mainly deals with logs. The so-called log, can be understood as the software in the course of operation, the recorded some of the operational information software developers can add logs according to their own needs, logs can help software developers understand the operation of the software information, the maintenance of the software is particularly important. Log level: Levels when it ' s used DEBUG detailed Informatio
Links:Http://www.cnblogs.com/anpengapple/p/5048123.htmlJsonImport JSONThe list of objects that are serialized.JSON, though it looks like a dictionary, is a string.The quotation marks in the JSON standard format are double quotes.This process is serialized and written to the file.Deserialization:Serialization stringAnother way to apply dumpWrite the content and, F is equivalent to adding a write operationAnother way to apply loadEquivalent to read and loadsPickleThe Pickle module has the advanta
logs are also exported to three destinations defined by handler. If you call Logging.getloggeer (' Simpleexample '), the logger instance that matches the name ' Simpleexample ' in the configuration file is created, and its handler is console, which is the output log on the console.Logging.handlers.RotatingFileHandler can implement automatic log file coverage, if you need to implement log file changes (such as deleted) automatically generated, you need to use Logging.handlers.WatchedFileHandler,
='Myapp.log',7Filemode='W')8 9 #################################################################################################Ten #define a Streamhandler, print info-level or higher log information to a standard error, and add it to the current log processing object # Oneconsole =logging. Streamhandler () A console.setlevel (logging.info) -Formatter = logging. Formatter ('% (name) -12s:% (levelname) -8s%
The example of this article tells the usage example of logging module, share for everybody reference. The specific methods are as follows:
Import logging
import os
log = Logging.getlogger ()
formatter = logging. Formatter (' [% (asctime) s] [% (name) s]% (levelname) s:% (message) s ')
Stream_handler = logging
Python's logging module is used to write logs and is a standard Python module.Structure of the logging
View logging python source code, there are four main classes to realize the function;
Loggers: Provides interfaces directly used by the application,
If you're still having headaches with Python's various urllib and urlibs,cookielib, or are still mad about Python's emulation of logging in and crawling data, take a look at our recommended Requests,python acquisition data emulation login Essentials!
This is also the recommended HTTP client library for Python:
This article is an example of a simulation login t
document introduction, wrote a small demo, by the way also learned about os.path.*, and the time module, good good!Function Description: Get input, write to file, enter "Q", exit. A small script that can be used as a loggingGenerate the Logt.txt file in the current directoryThe effect is as follows:2018/07/18 18:36:46 Hello world!2018/07/18 18:37:00 life are short, you need python!2018/07/18 18:37:02 log.py2018/07/18 18:37:02/home/kali/desktop2018/07
located
% (created) f
Current time, represented by the UNIX standard floating-point number representing the time
% (relativecreated) d
The number of milliseconds since logger was created when the log information is output
% (Asctime) s
The current time in string form. The default format is "2003-07-08 16:49:45,896". The comma is followed by milliseconds
% (thread) d
1, Introduction of logging PackageImport logging2, define a logging objectLogger = Logging.getlogger (' logger_name ') #给该对象分配一个对象名: Logger_name3. Set the log level for the Logger object:Logger.setlevel (logging. Debug) # Log level: CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET4, create a file handler, write the log to the fileFH =
I have several projects that use Sentry to capture the ERROR level of the log and now have a problem: when debugging locally, all handler (including root) in the log settings are only hit on the console, but exceptions that are not caught in local debugging will hit the line sentry Above, and the caught exception follows my log settings and only hits the console. I wonder if the uncaught exception is not the root handler of the walk?My solution is to read through the
In addition to using the Basicconfig method in the logging module to configure the log, the Dictconfig and Fileconfig methods in Python's Logging.config module support the configuration of Logger, Handl, and files by dictionary and file respectively. ER and Formatter. Here is an example of how to use the file configuration log, more detailed usage reference: https://docs.python.org/2/library/logging.config.htmlLogging.conf#############################
be used to throw exceptions and abstract classes + abstract methods to constrainSecond, the encryption mechanismOur password only we know others do not know, but in Python the existence of the password is too exposed, we need a way to make the password complex can not be cracked1 ImportHashlib#to import the encryption module first2 3obj = Hashlib.md5 (b"ASDAOIJSO")#add salt to prevent the collision of the library, resulting in password leakage4Obj.up
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.