From f5112227056127d34a72a1e3708fa11d6010d7ae Mon Sep 17 00:00:00 2001 From: Sharvil Patankar Date: Tue, 6 Feb 2024 11:03:44 -0500 Subject: [PATCH] Made the log method a weakreference --- lib/extras.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/extras.py b/lib/extras.py index 36e8ef9a..b05b9d9c 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -29,8 +29,8 @@ and classes until a better place in the distribution is found. import os as _os import time as _time import re as _re +import weakref as _weakref from collections import namedtuple, OrderedDict - import logging as _logging import psycopg2 @@ -401,9 +401,15 @@ class LoggingConnection(_connection): self._logobj = logobj if _logging and isinstance( logobj, (_logging.Logger, _logging.LoggerAdapter)): - self.log = self._logtologger + self._log = _weakref.WeakMethod(self._logtologger) else: - self.log = self._logtofile + self._log = _weakref.WeakMethod(self._logtofile) + + def log(self, *args, **kwargs): + """ + Public interface of the log method defined in initialize + """ + return self._log()(*args, **kwargs) def filter(self, msg, curs): """Filter the query before logging it.