Skip to content

Commit 0bbb25d

Browse files
GitHub Issue 796: JSON logging stopped after Tomcat/Spring update (#1265)
1 parent 2c20c70 commit 0bbb25d

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

server/embedded/src/org/labkey/embedded/LabKeyServer.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.io.File;
1717
import java.util.ArrayList;
18+
import java.util.Arrays;
1819
import java.util.HashMap;
1920
import java.util.List;
2021
import java.util.Map;
@@ -92,6 +93,32 @@ public static void main(String[] args)
9293

9394
application.setDefaultProperties(new HashMap<>()
9495
{{
96+
// GitHub Issue 796: JSON logging stopped after Tomcat/Spring update
97+
// Propagate log4j configuration to Spring Boot config, which is necessary with Spring Boot 4.x
98+
String log4JConfig = System.getProperty("log4j.configurationFile");
99+
if (log4JConfig != null)
100+
{
101+
String[] log4JConfigParts = log4JConfig.split(",");
102+
if (log4JConfigParts.length > 0)
103+
{
104+
if ("log4j2.xml".equals(log4JConfigParts[0]))
105+
{
106+
// Assume this is the one packaged with our embedded build and on the classpath
107+
put("logging.config", "classpath:log4j2.xml");
108+
}
109+
else
110+
{
111+
put("logging.config", log4JConfigParts[0]);
112+
}
113+
if (log4JConfigParts.length > 1)
114+
{
115+
put("logging.log4j2.config.override", String.join(",", Arrays.asList(log4JConfigParts).subList(1, log4JConfigParts.length)));
116+
}
117+
else
118+
throw new IllegalArgumentException("log4j.configurationFile must be in the form log4j2.xml[,secondaryFile]");
119+
}
120+
}
121+
95122
put("server.tomcat.basedir", ".");
96123
put("server.tomcat.accesslog.directory", logHome);
97124

0 commit comments

Comments
 (0)