its actually the same issue as #5271, I think the fix didn't work.
Log4J2LoggingSystem installs a filter that denies all and removes it in Log4J2LoggingSystem#initialize that is invoked in ApplicationEnvironmentPreparedEvent. but if an exception is raised during the preparation of the environment then the filter is not removed yet and the exception is lost. i got it when i had an exception in an EnvironmentPostProcessor.
you can run sample.actuator.log4j2.SampleActuatorLog4J2Application with this application.yml under resources.
---
spring:
profiles:
active: local
---
spring:
profiles: local
a=test
but change the code of sample.actuator.log4j2.SampleActuatorLog4J2Application to look like that:
try {
SpringApplication.run(SampleActuatorLog4J2Application.class, args);
}catch (Throwable e){
LoggerFactory.getLogger(SampleActuatorLog4J2Application.class).error("error ",e);
}
this is actually how our code looks like, we don't always have a main class, we initialize contexts in various ways.
the exception is not logged.
only if i remove the filter the exception is logged:
try {
SpringApplication.run(SampleActuatorLog4J2Application.class, args);
}catch (Throwable e){
try {
Filter filter = ((LoggerContext) LogManager.getContext(false)).getConfiguration().getFilter();
if (filter != null) {
((LoggerContext) LogManager.getContext(false)).getConfiguration().removeFilter(filter);
}
}catch (Throwable t){
}
LoggerFactory.getLogger(SampleActuatorLog4J2Application.class).error("error ",e);
}
Thanks
its actually the same issue as #5271, I think the fix didn't work.
Log4J2LoggingSysteminstalls a filter that denies all and removes it inLog4J2LoggingSystem#initializethat is invoked inApplicationEnvironmentPreparedEvent. but if an exception is raised during the preparation of the environment then the filter is not removed yet and the exception is lost. i got it when i had an exception in anEnvironmentPostProcessor.you can run
sample.actuator.log4j2.SampleActuatorLog4J2Applicationwith thisapplication.ymlunder resources.but change the code of
sample.actuator.log4j2.SampleActuatorLog4J2Applicationto look like that:this is actually how our code looks like, we don't always have a main class, we initialize contexts in various ways.
the exception is not logged.
only if i remove the filter the exception is logged:
Thanks