-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Log4j2 prints error when log4j2-spring.xml is used #4809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It does work but logs this error on startup
I assume that's what confused you in the first place, I don't know if this is new or not at this point but that extra statement is the only problem as far as I can see. |
Any updates? I could only suppress this error print by adding:
|
get the same problem @RestController
@EnableAutoConfiguration
@SpringBootApplication
public class Example {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(Example.class).listeners(new LoadAdditionalProperties()).run(args);
}
@Bean
public EmbeddedServletContainerFactory servletContainer() {
JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory("/project", 9000);
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
return factory;
}
}
//copy from https://github.com/spring-projects/spring-boot/issues/6220
@Component
public class LoadAdditionalProperties implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
private ResourceLoader loader = new DefaultResourceLoader();
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
try {
Resource resource = loader.getResource("file:conf/project/application.yml");
PropertySource<?> propertySource = new PropertySourcesLoader().load(resource);
event.getEnvironment().getPropertySources().addLast(propertySource);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
} My application.yml: logging:
config: file:conf/project/log4j2.xml my log4j.xml: <?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60">
<Appenders>
<Console name="Console-Appender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>
%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
</pattern>>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console-Appender"/>
</Root>
</Loggers>
</Configuration> run with this error on startup:
and spring uses default logger like:
then I set properties to springApplicationBuilder: new SpringApplicationBuilder(Example.class)
.properties("logging.config=file:conf/project/log4j2.xml")
.listeners(new LoadAdditionalProperties()).run(args); log4j2 works but also the same error on startup:
|
If you don't want to use a system property, you can suppress the error with a file named
|
@philwebb Perhaps we could include such a properties file in our log4j2 starter? The value can be a comma-separated list so it could be:
|
@wilkinsona That would be nice. I'll target this to 1.5 to investigate since it seems to be causing grief for people. |
Hello, After this patch my |
@yeta-io If you've got time to test the latest snapshot, I'd appreciate it. |
According to doc https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html the name shall work with "log4j2-spring.xml". but only does with "log4j2.xml"
as proposed from spring-cloud/spring-cloud-commons#72 (comment)
The text was updated successfully, but these errors were encountered: