Logging in JxBrowser is based on Java Logging, so you can configure JxBrowser logging using standard Java Logging API. By default, all JxBrowser log messages are printed into console output. The default log level is Level.SEVERE.


You can change default log level using the "jxbrowser.logging.level" VM parameter. For example:

-Djxbrowser.logging.level=ALL


Or, you can change default log level using the com.teamdev.jxbrowser.chromium.LoggerProvider class:  

LoggerProvider.setLevel(java.util.logging.Level.SEVERE);

 

Disabling Logging

To disable JxBrowser logging use the following code: 

LoggerProvider.setLevel(java.util.logging.Level.OFF);

 Redirecting Logging to File

If you want to redirect log message to a file, then you can use the following way: 

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.LoggerProvider;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.logging.*;

/**
 * This sample demonstrates how to redirect all JxBrowser log
 * messages to the '*.log' files.
 */
public class BrowserSample {
    public static void main(String[] args) throws IOException {
        LoggerProvider.setLevel(Level.ALL);
        
        // Redirect Browser log messages to jxbrowser-browser.log
        redirectLogMessagesToFile(LoggerProvider.getBrowserLogger(),
                "D:/jxbrowser-browser.log");

        // Redirect IPC log messages to jxbrowser-ipc.log
        redirectLogMessagesToFile(LoggerProvider.getIPCLogger(),
                "D:/jxbrowser-ipc.log");

        // Redirect Chromium Process log messages to jxbrowser-chromium.log
        redirectLogMessagesToFile(LoggerProvider.getChromiumProcessLogger(),
                "D:/jxbrowser-chromium.log");

        Browser browser = new Browser();
        BrowserView view = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        browser.loadURL("https://google.com");
    }

    private static void redirectLogMessagesToFile(Logger logger, String logFilePath)
            throws IOException {
        FileHandler fileHandler = new FileHandler(logFilePath);
        fileHandler.setFormatter(new SimpleFormatter());

        // Remove default handlers including console handler
        for (Handler handler : logger.getHandlers()) {
            logger.removeHandler(handler);
        }
        logger.addHandler(fileHandler);
    }
}