hi mongo devs,
wondering if someone could confirm if I am doing
something wrong, or if this is possibly a bug in the mongo driver. I am using the
mongo java client in a scala application (using casbah as a
java->scala wrapper). The scala application uses the slf4j api (with
logback as the logging backend). I am trying to enable mongo query
tracing, but am unable to get the trace statements logged.
in my
scala application, I set the system property:
System.setProperty("DB.TRACE","true") - I do this before initializing
the driver.
According to the DBApiLayer source, and
http://stackoverflow.com/questions/9545341/configure-logging-for-the-mongodb-java-driver,
this should be sufficient to enable trace logging. However, when SLF4j
initializes, TRACE_LOGGER.isLoggable returns false:
// enable tracing
System.setProperty("DB.TRACE","true")
// initialize the client
mongoClient = MongoClient(List(new ServerAddress(host,port),clientOptions))
// initialize database
mongoDb = mongoClient(dbName)
// get an instance of the com.mongodb.TRACE logger and check if it's
loggable - this is the same logic used by the willTrace() method in
DBApiLayer...
java.util.logging.Logger.getLogger("com.mongodb.TRACE").isLoggable(
java.util.logging.Level.INFO) // returns false
// workaround: manually set loglevel for the logger, so that isLoggable returns true.
java.util.logging.Logger.getLogger("com.mongodb.TRACE").setLevel(
java.util.logging.Level.INFO) // messages now logged to stdout, no logback config applied.
So
I am not able to get trace logs from the Mongo client into my logging
framework. I have been able to work around this be manually setting the
logger level to INFO after the database & slf4j has been
initialized. This results in mongo logging via JUL with a default
configuration (i.e. I have no control via logback / log4j
configurations, as the messages are not being logged via the slf4j api).
Is there something I am overlooking, or is there another way to configure this?