Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib.font_manager debug messages in log file

Tags:

python

logging

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?

like image 455
cheesus Avatar asked Oct 10 '19 10:10

cheesus


1 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)
like image 51
cheesus Avatar answered Nov 04 '22 12:11

cheesus