Setting up logging

Setting up logging

The Couchbase Java SDK has no hard dependency on a specific logger implementation. It tries to find a logger on the class path and uses that logger if it is supported by the SDK. If no logger implementation is found, the standard JDK logger is used.

The following loggers are supported (and tried in this order):

  1. SLF4J
  2. Log4J
  3. JDK Logger (java.util.logging)

Configuring SLF4J

To enable SLF4J, put it on the class path, as well as one of the support logger implementations (like logback). If you want to use logback and include logback-classic, it will be pulled in automatically:


By default, the log level for logback is set to DEBUG, but with the addition of a logback configuration this can be configured (for example, as a logback.xml in the resources folder):

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>

    <root level="info">
        <appender-ref ref="STDOUT" />

Consult the SLF4J documentation for advanced configuration.

Configuring Log4J

Log4J is also automatically found when put on the classpath:


If no configuration is applied, the following message appears:

log4j:WARN No appenders could be found for logger (com.couchbase.client.core.logging.CouchbaseLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See for more info.

This log4j.xml sets it to INFO level:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j=''>
    <appender name="CA" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
        <level value="info" />
        <appender-ref ref="CA" />

Alternatively, you can provide a file with similar settings:

log4j.rootLogger=INFO, CA
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Consult the Log4J documentation for more information and advanced configuration options.

Configuring the JDK Logger

If no logging library is found on the class path, the JDK logger (also known as JUL from java.util.logging ) is used as a fallback.

By default it logs INFO level and above. If you want to set it to DEBUG (or the JUL equivalent: Fine) you can do it like this programmatically before initializing the CouchbaseCluster object:

Logger logger = Logger.getLogger("com.couchbase.client");
for(Handler h : logger.getParent().getHandlers()) {
    if(h instanceof ConsoleHandler){

You should not use JUL in production because SLF4J and Log4J provide better configuration options and performance.

Manual Overriding

If different loggers are on the class path and you want to force a different one (for example Log4J instead of SLF4J) you can set the default one directly:

CouchbaseLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());