Hazelcast has a flexible logging configuration and doesn't 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 configuration xml, configuration API or JVM system property.
Configuration xml
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-2.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>
Configuration API
Config cfg = new Config() ; cfg.setProperty("hazelcast.logging.type", "log4j");
System Property
Using JVM parameter:
java -Dhazelcast.logging.type=slf4j
Using System class:
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
to
your custom
LoggerFactory
class name.
java -Dhazelcast.logging.class=foo.bar.MyLoggingFactory
You can also listen logging events generated by Hazelcast runtime by registeringLogListener
s
toLoggingService
.
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.