Skip to content

GSIP 167

Jody Garnett edited this page Oct 23, 2018 · 9 revisions

GSIP 167 - Log4j Upgrade

Overview

Review our logging dependencies, part of updating libraries for Java 9 compatibility:

Proposed By

Jody Garnett

Assigned to Release

This proposal is for GeoServer 2.14

State

  • Under Discussion
  • In Progress
  • Completed
  • Rejected
  • Deferred

Motivation

We are using log4j 1 series which has ended, Log4J 2.8.2 and newer is compatible with Java jigsaw.

Proposal

Updating the following:

library version upgrade
log4j 1.2.17 2.11.1
org.slf4j 1.6.4
commons-logging 1.1.1
"java utility logging" built-in

Upgrading to log4j 2 provides:

  • XML, JSON, YAML, or Java properties syntax (included nested properties)
  • Compatibility with log4j 'chainsaw" GUI
  • Log4j 1.2 as a small incompatibility with Java 11 that may or may not affect us.

For more information https://logging.apache.org/log4j/2.x/manual/configuration.html

Backwards Compatibility

GeoServer data directory contains named log4j configuration files, these log4j properties files are by their nature brittle and we should not expect to reuse them (they contain the class names of specific appenders which may of changed for log4j 2.x).

When configured with an empty data directory there is a series of "named" log4j property file configurations that are unpacked into the data directory folder.

Using this functionality:

  • each time we can detect an old named "built-in" log4j properties file we could replace it with the one baked into the WAR.
  • If the user has a custom configuration we will will not be able to load it

For information on configuration migration:

Feedback

Voting

Project Steering Committee:

  • Alessio Fabiani:
  • Andrea Aime:
  • Ben Caradoc-Davies:
  • Brad Hards:
  • Christian Mueller:
  • Ian Turton:
  • Jody Garnett: +1
  • Jukka Rahkonen:
  • Kevin Smith:
  • Simone Giannecchini:

Links

Reference

Log4j 1.2 DEFAULT_LOGGING.properties

## This log4j configuration file needs to stay here, and is used as the default logging setup
## during data_dir upgrades and in case the chosen logging config isn't available.

log4j.rootLogger=WARN, geoserverlogfile, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM HH:mm:ss} %p [%c{2}] - %m%n


log4j.appender.geoserverlogfile=org.apache.log4j.RollingFileAppender
# Keep three backup files.
log4j.appender.geoserverlogfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.geoserverlogfile.layout=org.apache.log4j.PatternLayout
log4j.appender.geoserverlogfile.layout.ConversionPattern=%d %p [%c{2}] - %m%n

log4j.category.log4j=FATAL

log4j.category.org.geotools=WARN
log4j.category.org.geotools.factory=WARN
log4j.category.org.geoserver=INFO
log4j.category.org.vfny.geoserver=INFO

log4j.category.org.springframework=WARN

log4j.category.org.geowebcache=INFO
log4j.category.org.geowebcache.seed.TruncateTask=WARN

Log4j 2.1 DEFAULT_LOGGING.xml Migration

  • XML is the most common example
  • Loggers are declared in the reverse order from most specific to least specific by convention, additivity controls if the logger passes the message up to its parent
  • Could not sort out exactly how geoserver.log RollingFileAppender defaults worked previously
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">

  <Appenders>
    <Console name="stout" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{dd MMM HH:mm:ss} [%t] %-5level %logger{2} - %m%n"/>
    </Console>
    <RollingFile name="geoserverlogfile" fileName="logs/geoserver.log"
      filePattern="logs/geoserver%i.log">
        <PatternLayout>
            <Pattern>%d %p [%c{2}] - %m%n</Pattern>
        </PatternLayout>
        <Policies>
            <SizeBasedTriggeringPolicy size="50 MB" />
        </Policies>
        <DefaultRolloverStrategy max="3" />
    </RollingFile>
  </Appenders>

  <Loggers>

    <Logger name="log4j.category.org.geowebcache.seed.TruncateTask" additivity="false" level="warn">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>
    <Logger name="log4j.category.org.geowebcache" additivity="false" level="info">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>

    <Logger name="log4j.category.org.springframework" additivity="false" level="warn">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>

    <Logger name="log4j.category.org.vfny.geoserver" additivity="false" level="info">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>
    <Logger name="log4j.category.org.geoserver" additivity="false" level="info">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>
    <Logger name="log4j.category.org.geotools.factor" additivity="false" level="warn">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>
    <Logger name="log4j.category.org.geotools" additivity="false" level="warn">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>

    <Logger name="log4j.category.log4j" additivity="false" level="fatal">
      <AppenderRef ref="traceLog" />
      <AppenderRef ref="Console" />
    </Logger>

    <Root level="warn">
      <AppenderRef ref="stout"/>
      <AppenderRef ref="geoserverlog"/>
    </Root>
  </Loggers>
</Configuration>
Clone this wiki locally