This topic explains how to configure Log4J 2 for VMware Tanzu GemFire.

Basic Tanzu GemFire logging configuration is set in the gemfire.properties file. This topic is intended for advanced users who need increased control over logging due to integration with third-party libraries.

An example log4j2.xml can be located within the product distribution at $GEMFIRE/config/log4j2.xml.

To specify your own log4j2.xml configuration file, or anything else supported by Log4j 2 such as .json or .yaml, use the following flag when starting up your JVM or Tanzu GemFire member:

-Dlog4j.configurationFile=<location-of-your-file>

If the Java system property log4j.configurationFile is specified, then Log4j will not use the log4j2.xml included in gemfire-log4j-<version>.jar.

Using Different Front-End Logging APIs to Log to Log4j2

You can also configure Log4j 2 to work with various popular and commonly used logging APIs. To obtain and configure the most popular front-end logging APIs to log to Log4j 2, see Logging Services on the Apache Log4j 2 website.

For example, if you are using:

  • Commons Logging, download “Commons Logging Bridge” (log4j-jcl-2.18.0.jar)
  • SLF4J, download “SLFJ4 Binding” (log4j-slf4j-impl-2.18.0.jar)
  • java.util.logging, download the “JUL adapter” (log4j-jul-2.18.0.jar)

For more examples, see Frequently Asked Questions on the Apache Log4j 2 website.

All three of the above JAR files are in the full distribution of Log4J 2.18.0 which can be downloaded from Download Apache Log4j™ 2 on the Apache Log4j 2 website. Download the appropriate bridge, adapter, or binding JARs to ensure that Tanzu GemFire logging is integrated with every logging API used in various third-party libraries or in your own applications.

Note: VMware Tanzu GemFire has been tested with Log4j 2.18.0. As newer versions of Log4j 2 come out, you can find 2.18.0 under Previous Releases on that page.

Customizing Your Own log4j2.xml File

Advanced users may want to move away entirely from setting log-* gemfire properties and instead specify their own log4j2.xml using -Dlog4j.configurationFile.

Custom Log4j 2 configuration in Tanzu GemFire comes with some caveats and notes:

  • Do not use "monitorInterval=" in your log4j2.xml file, because doing so can have significant performance impact. This setting instructs Log4j 2 to monitor the log4j2.xml config file at runtime and automatically reload and reconfigure if the file changes.
  • Tanzu GemFire’s default log4j2.xml specifies status=“FATAL” because Log4j 2’s StatusLogger generates warnings to standard out at ERROR level anytime Tanzu GemFire stops its AlertAppender or LogWriterAppender. Tanzu GemFire uses a lot of concurrent threads that are executing code with log statements; these threads may be logging while the Tanzu GemFire appenders are being stopped.
  • Tanzu GemFire’s default log4j2.xml specifies shutdownHook="disable" because Tanzu GemFire has a shutdown hook which disconnects the DistributedSystem and closes the Cache, which is executing the code that performs logging. If the Log4J2 shutdown hook stops logging before Tanzu GemFire completes its shutdown, Log4j 2 will attempt to start back up. This restart in turn attempts to register another Log4j 2 shutdown hook which fails resulting in a FATAL level message logged by Log4j 2.
  • The GEODE_VERBOSE marker can be used to enable additional verbose log statements at TRACE level. For more information about Log4J2 Markers, see Markers on the Apache Log4j 2 website. Many log statements are enabled simply by enabling DEBUG or TRACE. However, even more log statements can be further enabled by using MarkerFilter to accept GEODE_VERBOSE. The default Tanzu GemFire log4j2.xml deactivate GEODE_VERBOSE with this line:

    <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
    

    You can enable the GEODE_VERBOSE log statements by changing onMatch="DENY" to onMatch="ACCEPT". Typically, it is more useful to simply enable DEBUG or TRACE on certain classes or packages instead of for the entire Tanzu GemFire product. However, this setting can be used for internal debugging purposes if all other debugging methods fail.

  • The usage of filters can have an impact on performance. Tanzu GemFire has some logging optimizations that are deactivated when filters are used (except for the GEODE_VERBOSE marker mentioned previously).

  • Geode’s custom Log4j 2 Appenders can be used in a custom log4j2.xml. Specify GeodeConsole, GeodeLogWriter, and or GeodeAlert in the Appenders section:

    <Properties>
      <Property name="gemfire-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property>
    </Properties>
    
    <Appenders>
      <GeodeConsole name="STDOUT" target="SYSTEM_OUT">
        <PatternLayout pattern="${gemfire-pattern}"/>
      </GeodeConsole>
      <GeodeLogWriter name="LOGWRITER">
        <PatternLayout pattern="${gemfire-pattern}"/>
      </GeodeLogWriter>
      <GeodeAlert name="ALERT"/>
    </Appenders>
    

    (Note that GeodeAlert does not use a PatternLayout)

    See the default log4j2.xml in your GemFire distribution’s config directory as a reference for creating a custom configuration.

check-circle-line exclamation-circle-line close-line
Scroll to top icon