Skip to content

Instantly share code, notes, and snippets.

@nealeu
Created June 6, 2024 13:05
Show Gist options
  • Save nealeu/493641d7f4967acaac35269811ee33d6 to your computer and use it in GitHub Desktop.
Save nealeu/493641d7f4967acaac35269811ee33d6 to your computer and use it in GitHub Desktop.
Setting log level for com.mongodb.internal.diagnostics.logging.SLF4JLogger doesn't work

Problem

Running with Spring Boot, I get logs like this

c.m.i.d.l.SLF4JLogger : Command "insert" started on database "test" using a connection with driver-generated ID 3 and server-generated ID 13 to localhost:32795. The request ID is 13 and the operation ID is 11. Command: {"insert": "jobExecution", "ordered": true, "txnNumber": 1, "$db": "test", "$clusterTime": {"clusterTime": {"$timestamp": ...}

where c.m.i.d.l.SLF4JLogger refers to com.mongodb.internal.diagnostics.logging.SLF4JLogger.

I want to disable this logging, but if I change log4j2.xml to add:

    <Logger level="INFO" name="com.mongodb.internal.diagnostics.logging"/>

it still shows, and the same applies if I set log levels via application-test.yml (for integration tests) as follows:

debug: false
logging:
  level:
    com.mongodb.internal.diagnostics.logging: INFO # Doesn't work
    org.springframework.data.mongodb.core: INFO    # Works

Solution

It turns out that there is some magic going on where the logger name logged, is not the same as what is used to enable or disable it.

debug: false
logging:
  level:
    org.mongodb: INFO # Works (what...!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment