GSIP 167
Update log4j 1 to log4j 2 library.
Jody Garnett (GeoCat)
Proposed for 2.21.
- Under Discussion
- In Progress
- Completed
- Rejected
- Deferred
We are using log4j 1 series which has ended, Log4J 2.17.2 is the latest release compatible of jigsaw module system.
Updating the following:
library | version | upgrade |
---|---|---|
log4j | 1.2.17 | 2.17.2 |
org.slf4j | 1.6.4 | |
commons-logging | 1.1.1 | |
"java utility logging" | built-in |
-
Upgrading to log4j 2 provides: Supported library with active (recently very active) security patches. Use of XML, JSON, YAML, or Java properties syntax (included nested properties). Compatibility with log4j "chainsaw" GUI. For more information https://logging.apache.org/log4j/2.x/manual/configuration.html
-
Update LoggingUtils with new configuration files (DEFAULT_LOGGING, GEOSERVER_DEVELOPER_LOGGING, GEOTOOLS_DEVELOPER_LOGGING, PRODUCTION_LOGGING, QUIET_LOGGING, TEST_LOGGING, VERBOSE_LOGGING) for log4j use.
Log4j properties representation is less verbose, using naming conventions to infer the list of appenders, filters and loggers used.
-
Update the GlobalSettings to allow selection of log4j configuration file, taking care to allow XML, JSON, YAML or properties file.
-
Related: The GeoTools log4j bridge will need to be updated to log4j 2.
Financial proposal provided: geoserver-log4j-upgrade.pdf
initial:
75% of funds raised to a maximum of €5000 Feb 11, to allow time to complete upgrade for 2.21-RC
updated:
75% of funds raised to a maximum of €5000 Feb 18, may delay 2.21-RC
GeoServer data directory contains named log4j configuration files, these log4j properties files are by their nature brittle and we should not 100% reuse (they contain the class names of specific appenders which may of changed for log4j 2.x).
Mitigation:
-
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.
- DEFAULT_LOGGING.properties
- GEOSERVER_DEVELOPER_LOGGING.properties
- PRODUCTION_LOGGING.properties
- PRODUCTION_LOGGING.properties
- VERBOSE_LOGGING.properties
Each time we can detect an old named "built-in" log4j properties file (same filename and content) we can replace with the log4j equivalent.
This update in place can be done as needed, or as part of a data directory migration (DefaultGeoServerLoader) or logging configuration (LoggingUtils).
-
If the user has a custom configuration use the Log4j 1.x bridge should allow loading of existing configuration.
-
Provide information on configuration migration as part of the upgrade instructions:
Project Steering Committee:
- Alessio Fabiani:
- Andrea Aime: +1
- Ian Turton: +1
- Jody Garnett: +1
- Jukka Rahkonen: +1
- Kevin Smith:
- Simone Giannecchini:
- Torben Barsballe:
- Nuno Oliveira: +1
- https://osgeo-org.atlassian.net/browse/GEOS-10426
- https://interviewbubble.com/log4j-1-2-is-broken-on-java-9-java-logging/
- Log4j upgrade... like right now... yep, I mean it (geoserver-devel)
- https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout
- https://stackify.com/log4j2-java/
- https://howtodoinjava.com/log4j2/log4j-2-xml-configuration-example/
## 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
XML configuration of DEFAULT_LOGGING.properties:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="fatal" name="GeoServer" packages="">
<Filter type="ThresholdFilter" level="trace"/>
<Appenders>
<Console name="stout" target="SYSTEM_OUT">
<PatternLayout pattern="%d{dd MMM HH:mm:ss} %p [%c{2}] - %m%n"/>
</Console>
<RollingFile name="geoserverlogfile" fileName="logs/geoserver.log" ignoreExceptions="false">
<PatternLayout>
<Pattern>"%d %p [%c{2}] - %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
<DefaultRolloverStrategy max="3"/>
</RollingFile>>
</Appenders>
<Loggers>
<Logger name="log4j.category.org.geotools" level="WARN"/>
<Logger name="log4j.category.org.geotools.factory" level="WARN"/>
<Logger name="log4j.category.org.geoserver" level="INFO"/>
<Logger name="log4j.category.org.vfny.geoserver" level="INFO"/>
<Logger name="log4j.category.org.springframework" level="WARN"/>
<Logger name="log4j.category.org.geowebcache" level="INFO"/>
<Logger name="log4j.category.org.geowebcache.seed.TruncateTask" level="WARN"/>
<Root level="warn">
<AppenderRef ref="geoserverlogfile"/>
<AppenderRef ref="stout"/>
</Root>
</Loggers>
</Configuration>
PropertiesFile configuration of DEFAULT_LOGGING.properties:
## This log4j 2 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.
status=FATAL
name=GeoServerLog
appender.console.type = Console
appender.console.name = stout
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{dd MMM HH:mm:ss} %p [%c{2}] - %m%n
appender.rolling.type = RolingFile
appender.rolling.name = geoserverlogfile
appender.rolling.fileName = geoserver.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d %p [%c{2}] - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size = 20MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 3
logger.geotools.name = org.geotools
logger.geotools.level = warn
logger.geotools-factory.name = org.geotools.factory
logger.geotools-factory.level = warn
logger.geoserver.name = org.geoserver
logger.geoserver.level = INFO
logger.vfny.name = org.vfny.geoserver
logger.vfny.level = info
logger.spring.level = org.springframework
logger.spring.name = warn
logger.gwc.name = org.geowebcache
logger.gwc.level = INFO
logger.gwc-truncate.name = org.geowebcache.seed.TruncateTask
logger.gwc-truncate.level = WARN
rootLogger.level=WARN
rootLogger.appenderRef.stout.ref = stout
rootLogger.appenderRef.geoserverlogfile.ref = geoserverlogfile
©2022 Open Source Geospatial Foundation