[JAVA-1845] Expand logging reference documentation Created: 28/May/15  Updated: 24/May/22  Resolved: 24/May/22

Status: Closed
Project: Java Driver
Component/s: Documentation
Affects Version/s: 3.0.1
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-1746 Improve documentation of SLF4J logging Closed
Related

 Description   

Now that the driver supports both SLF4J and JUL, we can avoid confusion by giving examples of logging configuration for the popular SLF4J implementations (Log4J, Logback, etc).



 Comments   
Comment by Jeffrey Yemin [ 24/May/22 ]

Looking pretty good now: https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/logging/

Comment by Jeffrey Yemin [ 28/May/15 ]

Log4J 1.2:

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
 
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.12</version>
        </dependency>

and an example log4j.xml configuration file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
        </layout>
    </appender>
 
    <logger name="org.mongodb.driver">
        <level value="warn"/>
    </logger>
 
    <root>
        <priority value="debug"/>
        <appender-ref ref="console"/>
    </root>
 
</log4j:configuration>

Log4J 2:

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.3</version>
        </dependency>
 
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.3</version>
        </dependency>
 
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.3</version>
        </dependency>

and an example log4j2.xml configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="org.mongodb.driver" level="info"/>
        <Root level="error">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

For Logback:

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.1</version>
        </dependency>

and a logback.xml configuration file:

<configuration>
 
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
 
    <logger name="org.mongodb.driver" level="WARN"/>
 
    <root level="DEBUG">
        <appender-ref ref="STDOUT"/>
    </root>
 
</configuration>

Generated at Thu Feb 08 08:55:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.