Skip to content

Commit e970419

Browse files
committed
Update logging framework for new HAM impl
1 parent 670fece commit e970419

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

src/main/java/com/denimgroup/threadfix/cli/endpoints/EndpointMain.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@
3838
import com.denimgroup.threadfix.framework.engine.full.EndpointSerialization;
3939
import com.denimgroup.threadfix.framework.engine.full.TemporaryExtractionLocation;
4040
import com.denimgroup.threadfix.framework.util.EndpointUtil;
41+
import com.fasterxml.jackson.databind.ObjectMapper;
4142
import org.apache.commons.io.FileUtils;
4243
import org.apache.commons.io.FilenameUtils;
4344
import org.apache.commons.io.IOUtils;
4445
import org.apache.commons.lang3.StringUtils;
45-
import org.apache.log4j.ConsoleAppender;
46-
import org.apache.log4j.Level;
47-
import org.apache.log4j.Logger;
48-
import org.apache.log4j.PatternLayout;
49-
import org.codehaus.jackson.map.ObjectMapper;
46+
import org.apache.logging.log4j.Level;
47+
import org.apache.logging.log4j.LogManager;
48+
import org.apache.logging.log4j.core.LoggerContext;
49+
import org.apache.logging.log4j.core.config.Configuration;
50+
import org.apache.logging.log4j.core.config.LoggerConfig;
5051

5152
import java.io.*;
5253
import java.net.UnknownHostException;
@@ -648,18 +649,16 @@ private static Endpoint.Info[] getEndpointInfo(List<Endpoint> endpoints) {
648649
}
649650

650651
private static void resetLoggingConfiguration() {
651-
ConsoleAppender console = new ConsoleAppender(); //create appender
652-
String pattern = "%d [%p|%c|%C{1}] %m%n";
653-
console.setLayout(new PatternLayout(pattern));
652+
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
653+
Configuration config = ctx.getConfiguration();
654+
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
654655

655656
if (logging == Logging.ON) {
656-
console.setThreshold(Level.DEBUG);
657+
loggerConfig.setLevel(Level.DEBUG);
657658
} else {
658-
console.setThreshold(Level.ERROR);
659+
loggerConfig.setLevel(Level.ERROR);
659660
}
660661

661-
console.activateOptions();
662-
Logger.getRootLogger().removeAllAppenders();
663-
Logger.getRootLogger().addAppender(console);
662+
ctx.updateLoggers();
664663
}
665664
}

src/main/java/com/denimgroup/threadfix/cli/endpoints/EndpointValidation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import com.denimgroup.threadfix.data.interfaces.Endpoint;
3131
import com.denimgroup.threadfix.framework.engine.full.EndpointSerialization;
3232
import com.denimgroup.threadfix.framework.util.EndpointUtil;
33-
import org.apache.log4j.Logger;
33+
import org.apache.logging.log4j.LogManager;
34+
import org.apache.logging.log4j.Logger;
3435

3536
import java.io.File;
3637
import java.io.IOException;
@@ -43,7 +44,7 @@
4344

4445
public class EndpointValidation {
4546

46-
private static Logger logger = Logger.getLogger(EndpointValidation.class);
47+
private static Logger logger = LogManager.getLogger(EndpointValidation.class);
4748

4849
public static boolean validateSerialization(File sourceCodeFolder, List<Endpoint> endpoints) {
4950
List<Endpoint> allEndpoints = EndpointUtil.flattenWithVariants(endpoints);

src/main/resources/log4j2.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Configuration>
3+
<Appenders>
4+
<Console name="CONSOLE" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d [%p|%c|%C{1}] %m%n" />
6+
</Console>
7+
</Appenders>
8+
9+
<Loggers>
10+
<Root level="DEBUG">
11+
<AppenderRef ref="CONSOLE"/>
12+
</Root>
13+
</Loggers>
14+
</Configuration>

0 commit comments

Comments
 (0)