Library Version 12.1.6.0

Logging
Prev | Chapter 12. Administering Berkeley DB Java Edition Applications | Next

## Logging

JE uses the java.util.logging package to log operations and trace messages. A distinct logger is defined for each significant component of the system. The use of distinct loggers, along with controllable logging levels, allows the logging output to be tuned to tell you exactly what you need to know (while avoiding a lot of extra information that only gets in the way) in order to monitor your application's activities and/or debug runtime problems.

Logging output can be displayed to the console and the `je.info` file in your application's environment directory. Setting the logger level controls the types of messages that are published to the handlers. Setting the handler level determines if and where the published messages are displayed.

### Managing Logging Levels

The default logging level for JE loggers is `INFO`. At that level, a non-replicated environment issues messages only when critical exceptions are encountered. A replicated environment issues node transition messages which should be comprehensible to the user familiar with the replication group life cycle and can be extremely useful when monitoring your application's activities. The output at the `INFO` is not verbose; it simply details the node start up and shutdown operations. Initial configuration problems, if any, should show up during the startup operation. You are strongly advised to run your production application with this level of logging.

Finer levels of logging are available for debugging purposes. These will generate verbose output that is rich in implementation detail. The output at these levels is only likely to be helpful to people familiar with JE's implementation and the application's use of JE, so you should only configure your logging for these more verbose levels if you are involved in a detailed debugging effort.

To set or change the logger level before the environment is opened, do one of the following:

1. Set logging levels using the standard Java LogManager properties file. For example, you can set:

       com.sleepycat.je.level=INFO

   in the LogManager properties file to set the logger level for all JE loggers.

2. Set logging levels programmatically using the java.util.logging API. For example:

       ...
       // All other imports are omitted for brevity
       import java.util.logging.Logger;
       ...

       Logger parent = Logger.getLogger("com.sleepycat.je");
       parent.setLevel(Level.FINE);  // Loggers will now publish more
                                     // detailed messages.

To set or change the logger level after the environment is opened, do one of the following:

1. Use the standard java.util.logging MBean to set a concrete JE logger.

2. Use the JEDiagnostic MBean to set the parent `com.sleepycat.je` logger. See the JConsole Plugin page for information on this MBean.

3. Use the programmatic java.util.logging API described above to change the logger.

### Managing Handler Levels

Output to the `je.info` file is managed by the JE FileHandler, while output to the console is managed by the JE ConsoleHandler. By default, no output is shown on the console, and only `INFO` level messages are sent to `je.info`.

To set or change the handler level before the environment is opened, do one of the following:

1. Set logging levels using the standard Java LogManager properties file. For example, you can set:

       com.sleepycat.je.util.FileHandler.level=ALL
       com.sleepycat.je.util.ConsoleHandler.level=ALL

   in the LogManager properties file to display all logging output to the console and `je.info` files.

2. The java.util.logging package does not supply an API for setting handler levels. Instead, use the following JE environment parameter:

       ...
       EnvironmentConfig envConfig = new EnvironmentConfig();
       envConfig.setAllowCreate(true);
       envConfig.setConfigParam(EnvironmentConfig.FILE_LOGGING_LEVEL, "ALL");
       envConfig.setConfigParam(EnvironmentConfig.CONSOLE_LOGGING_LEVEL,
                                "ALL");

       ...
       // Open your environment as normal here
       ...

To set or change the handler level after the environment is opened, do one of the following:

1. Use EnvironmentMutableConfig.setConfigParam() to change the handler levels using the JE properties described above.

2. Use the JEDiagnostic MBean to change handler levels. See the JConsole Plugin page for information on this MBean.

Prev | Up | Next
The Command Line Tools | Home | Appendix A. Concurrent Processing in Berkeley DB Java Edition