Pivotal Knowledge Base


How to Manage Log-Level p\Per Package/Class


Pivotal GemFire 8.2.x and 9.x


Starting with 8.2.0, Pivotal GemFire started using Apache Log4j 2 as the basis for its logging system.

The purpose of this article is to explain how the Log4j configuration can be used to change the log-level only for the packages or classes we are interested in, leaving the default log-level to be used by the rest of the components.

Whenever we are troubleshooting a certain feature within GemFire or even just digging deeper and learning how the product works under the hood, it is useful to have the fine log-level enabled for all of our members. However, the downside of this approach is that the logs get filled very fast and most of the messages might not even be related to what we are trying to debug or learn. We will end up spending a lot of time in filtering the logs to actually get what we need instead of just focusing on what we want.

Considering that GemFire uses Log4j to register execution logs, we can customize the logging framework to meet our needs using a higher log-level as a default (CONFIG being the preferred one or TRACE, FIN, FINEST) for the packages and classes we want to monitor. 

In order to do so, we need to create a custom Log4j configuration file as described in the Log4j 2 section of the "Users Guide" and make use of the Logger element to register the packages or classes we are interested in.


The following sample configuration is the default used by GemFire, plus two custom Loggers used to configure the "Debug log-level" for the package org.eclipse.jetty (Server internally used by the Pulse and the Rest API) and the PartitionedRegion class. We could redirect these loggers to another output stream or even change the output pattern for the messages.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="FATAL" shutdownHook="disable" packages="com.gemstone.gemfire.internal.logging.log4j">
    <Property name="gemfire-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} &lt;%thread&gt; tid=%tid] %message%n%throwable%n</Property>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="${gemfire-pattern}"/>
    <Logger name="com.gemstone" level="INFO" additivity="true">
        <MarkerFilter marker="GEMFIRE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
<Logger name="org.eclipse.jetty" level="DEBUG" additivity="true">
<Logger name="com.gemstone.gemfire.internal.cache.PartitionedRegion" level="DEBUG" additivity="true">
    <Root level="ERROR">
      <AppenderRef ref="STDOUT"/>

To override the default configuration used by GemFire, you need to start up the servers using the system property log4j.configurationFile pointing to a local log4j configuration file.


gfsh start server --name=name --J=-Dlog4j.configurationFile=/config/log4j2-custom.xml.

Additional Information

More information about Log4j can be found from the Apache Log4J project.

GemFire logging details can be found in the Logging chapter within the User's Guide.


Powered by Zendesk