Logging Configuration

Hazelcast has a flexible logging configuration and does not depend on any logging framework except JDK logging. It has in-built adaptors for a number of logging frameworks and also supports custom loggers by providing logging interfaces.

To use built-in adaptors, you should set hazelcast.logging.type property to one of predefined types below.

  • jdk: JDK logging (default)

  • log4j: Log4j

  • slf4j: Slf4j

  • none: disable logging

You can set hazelcast.logging.type through declarative configuration, programmatic configuration or JVM system property.

NOTE: If you choose to use log4j or slf4j, proper dependencies should be included in the classpath.

  • Declarative Configuration
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config
    http://www.hazelcast.com/schema/config/hazelcast-config-3.0.xsd"
    xmlns="http://www.hazelcast.com/schema/config"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  ....

  <properties>
    <property name="hazelcast.logging.type">jdk</property>
    ....
  </properties>
</hazelcast>
  • Programmatic Configuration
Config config = new Config() ;
config.setProperty( "hazelcast.logging.type", "log4j" );
  • System Property

    • Using JVM parameter: java -Dhazelcast.logging.type=slf4j
    • Using System class: System.setProperty( "hazelcast.logging.type", "none" );

If provided logging mechanisms are not satisfactory, you can implement your own using the custom logging feature. To use it, you should implement com.hazelcast.logging.LoggerFactory and com.hazelcast.logging.ILogger interfaces and set system property hazelcast.logging.class as your custom LoggerFactory class name.

-Dhazelcast.logging.class=foo.bar.MyLoggingFactory

You can also listen to logging events generated by Hazelcast runtime by registering LogListeners to LoggingService.

LogListener listener = new LogListener() {
  public void log( LogEvent logEvent ) {
    // do something
  }
}
HazelcastInstance instance = Hazelcast.newHazelcastInstance();
LoggingService loggingService = instance.getLoggingService();
loggingService.addLogListener( Level.INFO, listener ):

Through the LoggingService, you can get the current used ILogger implementation and log your own messages, too.

NOTE: If you are not using command line for configuring logging, you should be careful about Hazelcast classes. They may be defaulted to jdk logging before newly configured logging is read. When logging mechanism is selected, it will not change.