From a08c05094e922a4469c835eb66128d13e66420f4 Mon Sep 17 00:00:00 2001 From: Erik van Blokland Date: Fri, 6 Dec 2024 09:30:54 +0100 Subject: [PATCH] loadFonts to check if there is a logger when debug==True For the following use case: UFOProcessor object is initialised with `debug=False`, no logger is started. Then, in a scripted context, the debug flag is set to True. But this is just an attribute, so there is no logger. Then `loadFonts` checks both `debug` and `logger` and calls `startLog` to create one if needed. --- Lib/ufoProcessor/ufoOperator.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/ufoProcessor/ufoOperator.py b/Lib/ufoProcessor/ufoOperator.py index aef0ce9..2bdd5ce 100644 --- a/Lib/ufoProcessor/ufoOperator.py +++ b/Lib/ufoProcessor/ufoOperator.py @@ -399,6 +399,11 @@ def getAxis(self, axisName): # loading and updating fonts def loadFonts(self, reload=False): # Load the fonts and find the default candidate based on the info flag + if self.logger is None and self.debug: + # in some cases the UFOProcessor is initialised without debug + # and then it is switched on afterwards. So have to check if + # we have a logger before proceding. + self.startLog() self.glyphNames = list({glyphname for font in self.fonts.values() for glyphname in font.keys()}) if self._fontsLoaded and not reload: if self.debug: @@ -1761,8 +1766,12 @@ def _copyFontInfo(self, sourceInfo, targetInfo): if ds5Path is None: doc = UFOOperator() else: - doc = UFOOperator(ds5Path, useVarlib=True, debug=debug) + doc = UFOOperator(ds5Path, useVarlib=True, debug=False) + print("Initialised without debug, no logger:", doc.logger) + doc.debug=True + print("Set debug to True, after initialisation:", doc.debug) doc.loadFonts() + print("loadFonts checks and creates a logger if needed:", doc.logger) # test the getLibEntryMutator