我正在尝试将客户端 IP 添加到日志文件中,我曾考虑扩展 Logger,但不确定如何访问请求对象并将 IP 放入记录对象
from logging.handlers import RotatingFileHandler
class RequestRotatingFileLogger(RotatingFileHandler, object):
def emit(self, record):
"""
code to manipulate the record to add an attribute to have client IP
record.ip = '123.123.123.123'
"""
super(RequestRotatingFileLogger,self).emit(record)