A newer version of Hazelcast Platform is available.

View latest

Configuring Logging

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

Logging for Member

By default, a Hazelcast member writes logs into the logs directory of the distribution. The logs are configured to roll over daily. You can change the logging configuration by modifying config/log4j.properties.

To use the built-in adapters, set the hazelcast.logging.type property to one of the predefined types below:

  • jdk: JDK logging (default)

  • log4j: Log4j

  • log4j2: Log4j2

  • slf4j: Slf4j

  • none: disable logging

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

If you choose to use log4j, log4j2, or slf4j, you should include the proper dependencies in the classpath.

Declarative Configuration:

  • XML

  • XML

  • Java member API

  • JVM

  • System Property

<hazelcast>
    ...
    <properties>
        <property name="hazelcast.logging.type">log4j2</property>
    </properties>
    ...
</hazelcast>
Config config = new Config() ;
config.setProperty( "hazelcast.logging.type", "log4j2" );
java -Dhazelcast.logging.type=log4j
System.setProperty( "hazelcast.logging.type", "log4j" );

Logging Pattern

The default log output resembles the following example:

2022-02-16 11:40:52,463 [ INFO] [main] [c.h.system]: [172.18.0.2]:5701 [hello-world] [5.0.5] Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
2022-02-16 11:40:52,463 [ INFO] [main] [c.h.system]: [172.18.0.2]:5701 [hello-world] [5.0.5] Hazelcast Platform 5.0.5 (20220210 - 1d718cf) starting at [172.18.0.2]:5701
2022-02-16 11:40:52,463 [ INFO] [main] [c.h.system]: [172.18.0.2]:5701 [hello-world] [5.0.5] Cluster name: hello-world

The logging pattern is shown below.

[Date and time] [Log level] [Thread name] [Logger Class Name] [Member IP and port] [Cluster name] [Platform version] [Log message]

You can customize the default logging pattern using the LOGGING_PATTERN environment variable while starting a member.

Here is an example usage.

  • CLI

Here is an example usage.

CLI

Provide the file’s relative or absolute path, or a file in the <HAZELCAST HOME>/config directory.

LOGGING_CONFIG=config/myHzConfig.properties bin/hz start
Docker

Provide the file’s relative or absolute path.

docker run \
    -e LOGGING_CONFIG=config/myHzConfig.properties \
    hazelcast/hazelcast:5.0.5

You can also provide a properties file having a path of your choice. For Log4j2, you can specify this using the following JVM argument (which is the only way for Log4j2).

-Dlog4j.configurationFile=/path/to/properties/log4j2.properties

== Modifying the Default Logging

If you do not need detailed logs, the default settings are enough. Using the Hazelcast specific lines in the default configuration file, you can select to see specific logs (cluster, partition, hibernate, etc.) in desired levels:

...
...
#Hazelcast specific logs.
#logger.com.hazelcast=debug

#logger.com.hazelcast.cluster=debug
#logger.com.hazelcast.partition=debug
...
....

To enable the debug logs for all Hazelcast operations, uncomment the below line in the configuration file:

logger.com.hazelcast=debug

You can also use the hazelcast.logging.details.enabled property to specify whether the name, IP address and version of the cluster are included in the logs. When there are lots of log lines, it may be hard to follow. When set to false, those information will not appear.

== Using JSON Template

You can use JSON templates for the member log files. The JSON logging configuration file built on the default JSON template layout is <HAZELCAST HOME>/config/log4j2-json.properties.

You can use a different JSON template via the LOGGING_JSON_TEMPLATE environment variable. Here is an example usage.

CLI
LOGGING_CONFIG=log4j2-json.properties LOGGING_JSON_TEMPLATE="classpath:EcsLayout.json" bin/hz start
Docker
hazelcast:
  properties:
    hazelcast.logging.type: log4j

Programmatic Configuration

Config config = new Config() ;
config.setProperty( "hazelcast.logging.type", "log4j" );

System Property

  • using the java -Dhazelcast.logging.type=slf4j JVM parameter

  • using the System.setProperty( "hazelcast.logging.type", "none" ); system class

Logging for Client and Embedded Mode

When using Hazelcast through the client or in embedded mode, Hazelcast doesn’t automatically add any dependencies to any logging framework and allows configuration of which facade the logging should be done through.

To configure the logging facade to use, you need to set a property in the configuration file:

hazelcast-client:
  properties:
    hazelcast.logging.type: log4j2

Alternatively, you can use the system property -Dhazelcast.logging.type to configure the logging framework to use.

Using a Custom Logger

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

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

Listening to Logging Events

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 currently used ILogger implementation and log your own messages too.

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.