Import Logging ''' Log Level: critical> error> warning> info> Debug. The higher the notset level, the fewer logs are printed, and vice versa. That is, debug: prints all logs (notset is equivalent to debug) info: print info, warning, error, and critical-level logs warning: Print warning, error, and critical-level log
Https://docs.python.org/3/howto/logging.html#logging-basic-tutorialMore and better examples:Https://docs.python.org/3/howto/logging-cookbook.html#logging-cookbookImportLogging#set up logging to File-see previous sections for more detailsLogging.basicconfig (level=logging.
Implement a simple version of the Logging.config, support the general configuration through config file.A better way to feel is to use the Logging.config.fileConfig (Log_config_file) method to read it and modify the handler.
Copy Code code as follows:
"""
Project Trace System
"""
Import Sys
Import Configparser
Import logging
Import Logging.config
Import warnings
if __name__ = = "__main__":Log_config_file = "Log.conf"Log_data_fi
#-*-Coding:utf-8-*-Import loggingImport Sys# Gets the logger instance and returns root if the argument is empty loggerLogger = Logging.getlogger ("AppName")# Specify logger output formatFormatter = logging. Formatter ('% (asctime) s% (levelname) -8s:% (message) s ')# file LogFile_handler = logging. Filehandler ("Test.log")File_handler.setformatter (Formatter) # can specify output format by Setformatter# con
The logging Module Interface of python is similar to log4j. It is similar in concept and convenient to use. Logging. config. fileconfig () can be used to describe the log configuration in a file, which simplifies log initialization.
Routine:
# test.pyimport loggingimport logging.configlogging.config.fileConfig("logging.conf")#create loggerlogger = logging.getLogg
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 =
One, logging moduleFunction: Manually add log function in logic error-prone location, record error message to file to be wrongFeatures: Non-automatic recording, specify the location for manual, specify the error message contentCriticalThe default output starts from warning, and can be based on demandAdjust default Write file is append a modeTwo modes of operation of logging module
The first approac
Common modules1 Logging ModuleLog level: Noset (not set)Debug---(debug information)----can also be expressed as 10info--(Message information)----can also be expressed as 20Warning---(warning message)----can also be expressed as 30The error----------can also be expressed as 40Critical---(Critical error)---can also be expressed as 50Default level is warning, defaul
. 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
A simple version of logging. config is implemented, which generally supports configuration through the config file.Another better way is to use the logging. config. fileConfig (log_config_file) method to read in and modify the handler method.
Copy codeThe Code is as follows:"""Project trace system"""Import sysImport ConfigParserImport loggingImport logging. confi
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.
1. Simply print the log to the screenImport logginglogging.debug ('This isdebug message') logging.info (' This is info message ' ) logging.warning ('This iswarning message') on-screen printing : 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
Logging.basicconfig (level=log_level, format='% (asctime) s% (filename) s[line:% (Lineno) d ]% (levelname) s% (message) s', datefmt='%a,%d%b%Y%h:%m:%s' , filename='parser_result.log', filemode= ' W ')logging.basicconfig function Parameters: FileName: Specifies the log file name FileMode: The same as the file function, specify the open mode of the log files,'W'Or'a'Format : Specifies the formats and contents of the output
less convenient, can be configured to use logging:Import logginglogging.basicconfig (FileName='/users/wenli.xu/desktop/log1.log', Level=logging.info)where filename indicates the log path, level indicates that only the severity is greater than or equal to info to be logged (the logging default is warning).The severity is lighter to heavy: debug,info,warning,error,criticalThe following methods can then be us
One, simple to print the log to the screen>>> Import Logging>>> Logging.debug ("This is Debug message")>>> Logging.info ("This is Info message")>>> logging.warning ("This is warning message")WARNING:root:This is WARNING message>>> Logging.error ("This is error message")ERROR:root:This is error message>>> logging.critical ("This is critical message")CRITICAL:root:This is CRITICAL messageLog level size relati
Describe:Many programs have logging requirements, and the information contained in the log is 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 use it to store various formats of the log.The logging log can be divided into 5 levels:
I. Introduction and use of logging modulePython uses the logging module to log logs involving four main classes, each of which uses the following functions:
Logger: Provides an interface that the application can use directly
Handler: Send (logger created) log records to the output of the appropriate destination
SetLevel: Provides a fine-grained device to determine which level 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.