Add memory info to python logging: several options?
Our program is using a lot of memory. Too much of memory, maybe. So I want to write memory of current process in logging information.
Getting the memory size of current process is the easy part (in Linux):
resource.getrusage(resource.RUSAGE_SELF).ru_maxrssI can think of several ways to add this into logging system: Adding a handler (derive the handler from either StreamHandler or FileHandler), or change the Formatter. Finally I decided to add a filter:
def filter(self, record):
record.mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss