<>logging modular

Functions :
1, Specification of log format
2, Simplification of operation
3, Hierarchical management of logs
# logging Use of modules # The first general configuration type , This method is simple , But the customization is poor . # basicConfig Log cannot be printed on screen and written in file .
import logging logging.basicConfig(level=logging.DEBUG,format='%(asctime)s
%(filename)s[line:%(lineno)d] %(levelname)s %(message)s',datefmt = '%a,%d %b %Y
%H:%M:%S') logging.debug("debug message") # Debug mode logging.info("info message") #
Basic information module logging.warning("warning message") # warning logging.error("error message") #
error logging.critical("critical message") # serious error Wed,13 May 2020 11:35:58
untitled0.py[line:10] DEBUG debug message Wed,13 May 2020 11:35:58 untitled0.py[
line:11] INFO info message Wed,13 May 2020 11:35:58 untitled0.py[line:12]
WARNING warning message Wed,13 May 2020 11:35:58 untitled0.py[line:13] ERROR
error message Wed,13 May 2020 11:35:58 untitled0.py[line:14] CRITICAL critical
message # The second # logger Object to manipulate the log file import logging # Create a logger object log = logging.
getLogger() # Create a file management operator fh = logging.FileHandler('logger.log',encoding =
'utf-8') # Create a screen management operator sh = logging.StreamHandler() # log level log.setLevel(logging
.DEBUG) # Create a log output format format1 = logging.Formatter('%(asctime)s - %(name)s -
%(levelname)s - %(message)s') # File management operators Bind a format fh.setFormatter(format1) #
Screen management operators Bind a format sh.setFormatter(format1) # logger Object binding file management operator log.addHandler(fh)
# logger Object binding screen management operator log.addHandler(sh) log.debug("debug message Eldest disciple ") log.info(
"ingo message chinese ") DEBUG:root:debug message Eldest disciple 2020-05-13 16:17:52,116 - root
- DEBUG - debug message Eldest disciple 2020-05-13 16:17:52,116 - root - DEBUG - debug
message Eldest disciple 2020-05-13 16:17:52,116 - root - DEBUG - debug message Eldest disciple debug
message Eldest disciple INFO:root:ingo message chinese 2020-05-13 16:17:52,128 - root - INFO -
ingo message chinese 2020-05-13 16:17:52,128 - root - INFO - ingo message chinese
2020-05-13 16:17:52,128 - root - INFO - ingo message chinese ingo message chinese

Technology
©2019-2020 Toolsou All rights reserved,
JS How to operate C Language console games , Make bricks use Python Do automated testing (pytest The essence of framework ) First knowledge MySQL Comprehensive review ( dried food )Python+OpenCV Detailed explanation of face recognition technology Baidu , Ali , Tencent's internal position level and salary structure , With job suggestions ! Image explanation of over fitting and under fitting Huawei certification HCIA-AI artificial intelligence New York Youth Project “ Recapture Wall Street ”: Safeguarding the interests of retail investors CSS architecture design