3

I am using rdflib-4.0.1 and rdfextras-0.4 in my python modules.

I get the following message while loading data into a rdfstore:

No handlers could be found for logger "rdflib.term"

What is it I am missing??

GJain
  • 5,025
  • 6
  • 48
  • 82

2 Answers2

4

The "No handlers" warning comes from Python's standard logging module. A logger needs a handler to determine what it should do with messages that have been logged -- should the text be sent to disk or to the console, for instance. See Python 2 Logging HOWTO on Handlers. Loggers also have names so that logging messages can be controlled in different ways for separate parts of the program. RDFLib writes to a logger named "rdflib.term" in its term.py.

I've used logging.basicConfig() to setup some reasonable defaults when using RDFLib:

import logging
import rdflib

logging.basicConfig()

# now load your graph
g = rdflib.Graph()
g.load("life_the_universe_everything.rdf")

This time when you load your graph you should see rdflib's log messages in the console instead of the "No handlers" warning.

mellon
  • 56
  • 1
0

The thing about rdflib is that it logs when you import it because it does

if _interactive_mode:
    logger.info("RDFLib Version: %s" % __version__)
else:
    logger.debug("RDFLib Version: %s" % __version__)

in its __init__.py. So whereas many things log, rdflib has the distinction of logging very early, and in unusual contexts. This is fine if there's a handler, even if it's the default handler, but in many cases there's not, so you get this little logspam.

Lest ye be tempted to open a bug, please read this one first.

kojiro
  • 74,557
  • 19
  • 143
  • 201