LettError/MutatorMath

Issue with logging

Closed this issue · 2 comments

Issue

Consider the following Code snippet

logPath1 = os.path.join(testRoot,"log.log")
doc = DesignSpaceDocumentReader(documentPath, ufoVersion, roundGeometry=roundGeometry, verbose=True, logPath=logPath1)
doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
#repeat the same for Log file 2
logPath2 = os.path.join(testRoot,"log2.log") 
doc = DesignSpaceDocumentReader(documentPath, ufoVersion, roundGeometry=roundGeometry, verbose=True, logPath=logPath2)
doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
#repeat the same for Log file 3
logPath3 = os.path.join(testRoot,"log3.log") 
doc = DesignSpaceDocumentReader(documentPath, ufoVersion, roundGeometry=roundGeometry, verbose=True, logPath=logPath2)
doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

  • Expected is there should be 3 log files
  • Actual is there is only one log file and contents are append to the same file instead of having 3 separate files.

Workaround

  • Forcefully killing the log handlers
```python
logPath1 = os.path.join(testRoot,"log.log")
doc = DesignSpaceDocumentReader(documentPath, ufoVersion, roundGeometry=roundGeometry, verbose=True, logPath=logPath1)
doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
#Kill Log Session
logger=logging.getLogger("mutatorMath")
if logger.root != None:
        logger.root.handlers=[]
loggger.handlers=[] #It may not be required   for mutatorMath

#repeat the same for Log file 2
logPath2 = os.path.join(testRoot,"log2.log") 
doc = DesignSpaceDocumentReader(documentPath, ufoVersion, roundGeometry=roundGeometry, verbose=True, logPath=logPath2)
doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
#Kill Log Session
logger=logging.getLogger("mutatorMath")
if logger.root != None:
        logger.root.handlers=[]
loggger.handlers=[] #It may not be required   for mutatorMath
#repeat the same for Log file 3
logPath3 = os.path.join(testRoot,"log3.log") 
doc = DesignSpaceDocumentReader(documentPath, ufoVersion, roundGeometry=roundGeometry, verbose=True, logPath=logPath2)
doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
#Kill Log Session
logger=logging.getLogger("mutatorMath")
if logger.root != None:
        logger.root.handlers=[]
loggger.handlers=[] #It may not be required   for mutatorMath

That seems to be a feature of the logging module. What happens if there are more handlers in that list than just the one for MutatorMath?

I tested this by adding the handler removal. This would indeed allow different logging files to be created. However, it also rules out different readers/writers sharing a log file. I think that is actually a more common use case. So I'm going to leave it like this for the time being.