Configuring Logging
Overview
GridGain supports a number of logging libraries and frameworks:
-
JUL (default),
-
Log4j,
-
Log4j2,
-
JCL,
-
SLF4J.
This page will show you how to set up the logger.
When a node starts, it outputs start-up information to the console, including the information about the configured logging library. Each logging library has its own configuration parameters and should be set up according to its official documentation. Besides library-specific configuration, there is a number of system properties that allow you to tune logging. These properties are presented in the following table.
System Property | Description | Default Value |
---|---|---|
IGNITE_LOG_INSTANCE_NAME |
If the property is set, GridGain include its instance name in log messages. |
Not set |
IGNITE_QUIET |
Set to |
|
IGNITE_LOG_DIR |
The directory where GridGain will write log files. |
|
IGNITE_DUMP_THREADS_ON_FAILURE |
Set to |
|
Default Logging
By default, GridGain uses the java.util.logging (JUL) framework with the configuration file $IGNITE_HOME/config/java.util.logging.properties
and output all messages to log files in the $IGNITE_HOME/work/log
directory. You can override the logging directory by sepecifying the IGNITE_LOG_DIR
system property.
Using Log4j
To enable Log4j logger, set the gridLogger
property of IgniteConfiguration
, as shown in the following example:
<bean class="org.apache.ignite.configuration.IgniteConfiguration" id="ignite.cfg">
<property name="gridLogger">
<bean class="org.apache.ignite.logger.log4j.Log4JLogger">
<!-- log4j configuration file -->
<constructor-arg type="java.lang.String" value="log4j-config.xml"/>
</bean>
</property>
<!-- other properties -->
</bean>
IgniteConfiguration cfg = new IgniteConfiguration();
IgniteLogger log = new Log4JLogger("log4j-config.xml");
cfg.setGridLogger(log);
// Start a node.
try (Ignite ignite = Ignition.start(cfg)) {
ignite.log().info("Info Message Logged!");
}
In the above example, the path to log4j-config.xml
can be either an absolute path, a local path relative to META-INF in classpath or to IGNITE_HOME
. An example log4j configuration file can be found in the distribution package ($IGNITE_HOME/config/ignite-log4j.xml
).
Using Log4j2
To enable Log4j2 logger, set the gridLogger
property of IgniteConfiguration
, as shown below:
<bean class="org.apache.ignite.configuration.IgniteConfiguration" id="ignite.cfg">
<property name="gridLogger">
<bean class="org.apache.ignite.logger.log4j2.Log4J2Logger">
<!-- log4j2 configuration file -->
<constructor-arg type="java.lang.String" value="log4j2-config.xml"/>
</bean>
</property>
<!-- other properties -->
</bean>
IgniteConfiguration cfg = new IgniteConfiguration();
IgniteLogger log = new Log4J2Logger("log4j2-config.xml");
cfg.setGridLogger(log);
// Start a node.
try (Ignite ignite = Ignition.start(cfg)) {
ignite.log().info("Info Message Logged!");
}
In the above example, the path to log4j2-config.xml
can be either an absolute path, a local path relative to META-INF in classpath or to IGNITE_HOME
. An example log4j2 configuration file can be found in the distribution package ($IGNITE_HOME/config/ignite-log4j2.xml
).
Using JCL
To enable Log4j2 logger, set the gridLogger
property of IgniteConfiguration
, as shown below:
<bean class="org.apache.ignite.configuration.IgniteConfiguration" id="ignite.cfg">
<property name="gridLogger">
<bean class="org.apache.ignite.logger.jcl.JclLogger">
</bean>
</property>
<!-- other properties -->
</bean>
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setGridLogger(new JclLogger());
// Start a node.
try (Ignite ignite = Ignition.start(cfg)) {
ignite.log().info("Info Message Logged!");
}
Using SLF4J
To enable the SLF4J logger, set the gridLogger
property of IgniteConfiguration
, as shown below:
<bean class="org.apache.ignite.configuration.IgniteConfiguration" id="ignite.cfg">
<property name="gridLogger">
<bean class="org.apache.ignite.logger.slf4j.Slf4jLogger">
</bean>
</property>
<!-- other properties -->
</bean>
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setGridLogger(new Slf4jLogger());
// Start a node.
try (Ignite ignite = Ignition.start(cfg)) {
ignite.log().info("Info Message Logged!");
}
Refer to the SLF4J user manual for more information.
Logging Configuration Example
The following steps will guide you through the process of configuring logging. This should be suitable for most cases.
-
Use either Log4j or Log4j2 as the logging framework. To enable it, follow the instructions provided in the corresponding section above.
-
If you use the default configuration file (either
ignite-log4j.xml
orignite-log4j2.xml
), uncomment the CONSOLE appender. -
In the log4j configuration file, set the path to the log file. The default location is
${IGNITE_HOME}/work/log/ignite.log
. -
Start the nodes in verbose mode:
-
If you use
ignite.sh
to start nodes, specify the-v
option. -
If you start nodes from Java code, use the
IGNITE_QUIET=false
system variable.
-
© 2020 GridGain Systems, Inc. All Rights Reserved. Privacy Policy | Legal Notices. GridGain® is a registered trademark of GridGain Systems, Inc.
Apache, Apache Ignite, the Apache feather and the Apache Ignite logo are either registered trademarks or trademarks of The Apache Software Foundation.