From 909a976f728414c31bd959db161f51c9639645c6 Mon Sep 17 00:00:00 2001 From: ismail simsek <6005685+ismailsimsek@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:41:00 +0200 Subject: [PATCH] Avoid adding duplicate log handler (#82) --- pyliquibase/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pyliquibase/__init__.py b/pyliquibase/__init__.py index 0bb9d22..33419f4 100644 --- a/pyliquibase/__init__.py +++ b/pyliquibase/__init__.py @@ -65,11 +65,12 @@ def log(self): if not self._log: self._log = logging.getLogger("pyliquibase") self._log.setLevel(logging.INFO) - handler = logging.StreamHandler(sys.stdout) - handler.setLevel(logging.INFO) - formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') - handler.setFormatter(formatter) - self._log.addHandler(handler) + if not self._log.hasHandlers(): + handler = logging.StreamHandler(sys.stdout) + handler.setLevel(logging.INFO) + formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') + handler.setFormatter(formatter) + self._log.addHandler(handler) return self._log def _cli(self):