Skip to content

Commit

Permalink
Remove existing logging handlers before adding a new one
Browse files Browse the repository at this point in the history
This fixes a bug where log messages are printed multiple times when
xfaster_run() is called multiple times in the same python session.
  • Loading branch information
arahlin committed Oct 27, 2023
1 parent 83483df commit 8eed700
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions xfaster/xfaster_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ def root_notice(msg, *args, **kwargs):

# configure logger
self.logger = logging.getLogger("xfaster")
# replace any existing handlers before adding one
if logger.hasHandlers():
for h in list(logger.handlers):
logger.removeHandler(h)
self.logger.addHandler(handler)

# set logging level
Expand Down

0 comments on commit 8eed700

Please sign in to comment.