Redirecting JxBrowser Logs With SLF4J

This tutorial shows how to redirect JxBrowser logs with SLF4J.


To go through this tutorial you will need:

  • Git.
  • Java 8 or higher.
  • A valid JxBrowser license. It can be either Evaluation or Commercial. For more information on licensing please see the Licensing guide.

Why Redirect Logs

JxBrowser logging is based on java.util.logging, a logging framework that comes with JDK.

By default, JxBrowser logs aren’t captured by other, more advanced, logging libraries and may be lost.

In this tutorial, we’re going to demonstrate how to redirect and capture JxBrowser logs with the help of SLF4J.

Setting Up a Project

The code of the example application for this tutorial is available along with other examples from a GitHub repository as a Gradle-based project.

Getting the Code

To get the code please execute the following commands:

$ git clone
$ cd JxBrowser-Examples/tutorials/jul-logs-redirect

Adding the License

To run this tutorial you need to setup a license key.

Adding Gradle Dependencies

In this example, we use Log4j library with SLF4J facade.

In the build.gradle.kts, we add the following dependencies:

dependencies {
    // Adds a dependency to the SLF4J API.
    // Adds a dependency to the Log4j binding for SLF4J.

    // Adds a dependency with SLF4J handler for JUL.

Configuring Log4J

The next step is to add file to configure Log4j. Let’s configure logging levels and the path to the log file:

# Define the root logger with the appender file.
log4j.rootLogger = ALL, FILE

# Define the file appender.

# Define the layout for file appender.

Application Code

Add the following code to the main() method:


java.util.logging.Logger jxBrowserLogger =

jxBrowserLogger.addHandler(new SLF4JBridgeHandler());

Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);

Now let’s see what we’ve done here:

  1. Set JxBrowser logging level to DEBUG. For more information about JxBrowser logging please see the Logging guide.

  2. We use SLF4JBridgeHandler. It routes logs from JUL to SLF4J. Add the SLF4JBridgeHandler to the JxBrowser logger:

     java.util.logging.Logger jxBrowserLogger =
     jxBrowserLogger.addHandler(new SLF4JBridgeHandler());
  3. To make JxBrowser write log records, create an Engine:

     Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);

Here is the complete Java code:

import static com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED;

import com.teamdev.jxbrowser.browser.Browser;
import com.teamdev.jxbrowser.engine.Engine;
import com.teamdev.jxbrowser.logging.Level;
import com.teamdev.jxbrowser.logging.Logger;
import java.util.logging.LogManager;
import org.slf4j.bridge.SLF4JBridgeHandler;

 * This example demonstrates how to capture JxBrowser logs using SLF4J API.
public final class LoggingRedirectExample {

    public static void main(String[] args) {

        // Configure JxBrowser logging level.

        // Get the JxBrowser logger.
        java.util.logging.Logger jxBrowserLogger =

        // Add SLF4JBridgeHandler to the JxBrowser logger to route log records to the SLF4j.
        jxBrowserLogger.addHandler(new SLF4JBridgeHandler());

        // Creating and running Chromium engine.
        Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);

All JxBrowser logs will be saved in the log/log.out file that was configured in our file.


In this tutorial, we have demonstrated how you can redirect JxBrowser logs with SLF4J API by configuring Log4j.

Go Top