matplotlib.font_manager debug messages in log file

Question:

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?

Asked By: cheesus

||

Answers:

The solution was provided by tomjn:

level=logging.DEBUG from the basicConfig was removed and in the line below logger.setLevel(logging.DEBUG)
was added. So that makes

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Answered By: cheesus

With full credit to @SimoX:

Add this line to suppress all that garbage from matplotlib.font_manager:

logging.getLogger('matplotlib.font_manager').disabled = True
Answered By: Michael Currie
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.