Skip to content

Commit c2d1fbf

Browse files
committed
🐛 reset logger (relevant for GUI)
- logging.basicConfig only has an effect the first time - executed from GUI, the logs were created but empty the second time
1 parent 41363b1 commit c2d1fbf

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/vuegen/utils.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,17 +690,22 @@ def init_log(
690690
else:
691691
handlers = [file_handler]
692692

693-
# logger configuration
694-
logging.basicConfig(
695-
# level=logging.DEBUG,
696-
format="[%(asctime)s] %(name)s: %(levelname)s - %(message)s",
697-
handlers=handlers,
698-
)
699-
logging.getLogger("matplotlib.font_manager").disabled = True
700-
701693
# instantiate the logger
702694
logger = logging.getLogger(logger_id)
703695
logger.setLevel(logging.DEBUG)
696+
# logger configuration
697+
# ! logging.basicConfig has no effect if called once anywhere in the code
698+
# ! set handlers and format for the logger manually
699+
# Reset any existing handlers
700+
for handler in logging.root.handlers[:]:
701+
logger.removeHandler(handler)
702+
703+
# Set up the new handlers and format
704+
formatter = logging.Formatter("[%(asctime)s] %(name)s: %(levelname)s - %(message)s")
705+
for handler in handlers:
706+
handler.setFormatter(formatter)
707+
logger.addHandler(handler)
708+
logging.getLogger("matplotlib.font_manager").disabled = True
704709

705710
return logger
706711

0 commit comments

Comments
 (0)