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 XML configuration, API configuration or JVM system property.
<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>
Config cfg = new Config() ;
cfg.setProperty("hazelcast.logging.type", "log4j");
System Property
java -Dhazelcast.logging.type=slf4j
System.setProperty("hazelcast.logging.type", "none");
To use custom logging feature 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 LogListener
s to LoggingService
.
LogListener listener = new LogListener() {
public void log(LogEvent logEvent) {
// do something
}
}
LoggingService loggingService = Hazelcast.getLoggingService();
loggingService.addLogListener(Level.INFO, listener):
Through the LoggingService
, you can get the current used ILogger implementation and log your own messages, too.