[ Python ] custom logging level 만들기

2019. 9. 11. 20:21분석 Python/구현 및 자료

728x90

logging level 추가하기.
import logging
trace = 15
class user(logging.Logger) :

	def trace(self , msg , *args ,**kwargs ):
    
    		self.log( trace ,msg , *args ,**kwargs )

logging.setLoggerClass(user)
logging.addLevelName(15 , "user")

logger = logging.getLogger("test")
logger.setLevel("user")
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch) 


logger.debug(" debug test")
logger.trace("custom test")
logger.info("info test")

 

728x90