Pivotal Knowledge Base

Follow

How to manage Log-Level per Package/Class

Environment

 Product  Version
 Pivotal GemFire  8.2.x, 9.x

Purpose

Starting with version 8.2.0, Pivotal GemFire began 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.

Description

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 FINE log-level enabled for all of our members. The downside of this approach, however, 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/learn. Even worse, 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.

The downside of this approach, however, 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/learn. Even worse, 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 now customize the logging framework to meet our needs, using a higher log-level as default (CONFIG being the preferred one) and a more verbose one (like TRACE, FINE or FINEST) for the packages and/or classes we want to monitor. 

In order to do so, we need to write 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/classes we're 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 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">
  <Properties>
    <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>
  </Properties>
  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="${gemfire-pattern}"/>
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="com.gemstone" level="INFO" additivity="true">
      <filters>
        <MarkerFilter marker="GEMFIRE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
      </filters>
    </Logger>
<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"/>
    </Root>
  </Loggers>
</Configuration>

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; example:

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

References

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.

Comments

Powered by Zendesk