I want to log the progress of my optimization in a log file, but my log file gets filled with stuff from the matplotlib font manager, e.g.:
DEBUG:matplotlib.font_manager:findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0.)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'STIXSizeThreeSym' (STIXSizThreeSymBol.ttf) normal normal bold normal>) = 10.335)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'cmmi10' (cmmi10.ttf) normal normal 400 normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'STIXSizeTwoSym' (STIXSizTwoSymReg.ttf) normal normal regular normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'cmsy10' (cmsy10.ttf) normal normal 400 normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans' (DejaVuSans-BoldOblique.ttf) oblique normal bold normal>) = 1.335)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans Mono' (DejaVuSansMono-BoldOblique.ttf) oblique normal bold normal>) = 11.335)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'STIXSizeOneSym' (STIXSizOneSymReg.ttf) normal normal regular normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans Mono' (DejaVuSansMono.ttf) normal normal 400 normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans' (DejaVuSans-Bold.ttf) normal normal bold normal>) = 0.33499999999999996)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans Mono' (DejaVuSansMono-Bold.ttf) normal normal bold normal>) = 10.335)
I'm using the logger as follows:
import logging
logger=logging.getLogger(__name__)
logging.basicConfig(filename='logfile.log',level=logging.DEBUG,
format='%(levelname)s:%(name)s:%(message)s)')
def objective(x):
obj=model(x)
logger.debug('objective = {}'.format(obj))
return obj
How can I keep matplotlib from crapping all over my log file?
level=logging.DEBUG
from thebasicConfig
and adding a line below that islogger.setLevel(logging.DEBUG)
. Does that work? – PhenibasicConfig
, you can also change the logging level ofmatplotlib.font_manager
:logging.getLogger('matplotlib.font_manager').setLevel(logging.WARNING)
– Mahoutlogging.getLogger('matplotlib').setLevel(logging.WARNING)
– Bendick