1 回答

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
您必須覆蓋該函數(shù)。應(yīng)用篩選器時(shí),記錄已創(chuàng)建。makeRecord
import logging
import copy
class CopyLogger(logging.Logger):
def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None):
args = copy.deepcopy(args) # <- this is the line you care about
return super().makeRecord(name, level, fn, lno, msg, args, exc_info, func, extra, sinfo)
logging.setLoggerClass(CopyLogger)
log = logging.getLogger('mylogger')
data1 = 'hello'
data2 = 'world'
log.warning('my message, %s, %s', data1, data2)
添加回答
舉報(bào)