I am trying to add the client IPs to the log files, I have thought about extending the Logger, but not sure how to access the request object and put IP into the record object
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)
OK, after reading some Logger source code, I found out a hacky way to do it
and when logging, pass the request object as second parameter eg.