是的,您可以通过创建一个自定义Formatter
类来做到这一点:
class MyFormatter(logging.Formatter):
def format(self, record):
#compute s according to record.levelno
#for example, by setting self._fmt
#according to the levelno, then calling
#the superclass to do the actual formatting
return s
然后将一个MyFormatter
实例附加到您的处理程序。