Skip to content

Instantly share code, notes, and snippets.

@jacobtolar
Last active December 11, 2017 20:43
Show Gist options
  • Save jacobtolar/979b6f56a2cfd6eb45e996ab4e494c11 to your computer and use it in GitHub Desktop.
Save jacobtolar/979b6f56a2cfd6eb45e996ab4e494c11 to your computer and use it in GitHub Desktop.
verification for LOG4J2-2123
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Loggers>
<Root level="debug">
<RegexFilter regex=".*filter.*" onMatch="DENY" onMismatch="ACCEPT"/>
</Root>
</Loggers>
</Configuration>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Log4JTest {
private static final Logger logger = LogManager.getLogger("Log4JTest");
public static void main(String[] args) {
logger.info("this is a normal message and will appear before and after the fix");
logger.info("filter -- this message should not appear after LOG4J2-2123");
}
}
$ ./test.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 249k 100 249k 0 0 548k 0 --:--:-- --:--:-- --:--:-- 549k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1561k 100 1561k 0 0 1408k 0 0:00:01 0:00:01 --:--:-- 1409k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 249k 100 249k 0 0 766k 0 --:--:-- --:--:-- --:--:-- 766k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1561k 100 1561k 0 0 1983k 0 --:--:-- --:--:-- --:--:-- 1981k
> compiling with 2.10.1-17 ...
> executing with 2.10.1-17 ...
2017-12-11 14:40:42,163 main ERROR A regular expression must be provided for RegexFilter
14:40:42.231 [main] INFO Log4JTest - this is a normal message and will appear before and after the fix
14:40:42.233 [main] INFO Log4JTest - filter -- this message should not appear after LOG4J2-2123
> compiling with 2.10.1-20 ...
> executing with 2.10.1-20 ...
14:40:43.419 [main] INFO Log4JTest - this is a normal message and will appear before and after the fix
completed
#!/bin/bash
BASE=https://repository.apache.org/content/groups/snapshots/org/apache/logging/log4j
mkdir -p 2.10.1-17 2.10.1-20
curl $BASE/log4j-api/2.10.1-SNAPSHOT/log4j-api-2.10.1-20171207.071045-17.jar > 2.10.1-17/log4j-api.jar
curl $BASE/log4j-core/2.10.1-SNAPSHOT/log4j-core-2.10.1-20171207.071132-17.jar > 2.10.1-17/log4j-core.jar
curl $BASE/log4j-api/2.10.1-SNAPSHOT/log4j-api-2.10.1-20171211.065249-20.jar > 2.10.1-20/log4j-api.jar
curl $BASE/log4j-core/2.10.1-SNAPSHOT/log4j-core-2.10.1-20171211.065335-20.jar > 2.10.1-20/log4j-core.jar
for version in 2.10.1-17 2.10.1-20 ; do
echo '> ' compiling with $version ...
javac -cp "$version/log4j-api.jar:$version/log4j-core.jar" Log4JTest.java
echo '> ' executing with $version ...
java -cp "$version/log4j-api.jar:$version/log4j-core.jar:." -Dlog4j.configurationFile=conf-parent.xml,conf-child.xml Log4JTest
done
echo completed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment