-
Notifications
You must be signed in to change notification settings - Fork 401
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
Sample log4j2 doesn't work with spring-boot >=2.0.0.RELEASE #59
Comments
Problem is due to a circular reference to The CTOR is called from the appender while initializing the private static final LoggerContext loggerContext =
LogManager.getContext(Log4jLog.class.getClassLoader(), false);
private final ExtendedLogger logger;
public Log4jLog(String name) {
this.logger = loggerContext.getLogger(name);
} We need to defer initializing the |
garyrussell
added a commit
to garyrussell/spring-amqp
that referenced
this issue
Jan 27, 2020
Resolves spring-projects/spring-amqp-samples#59 Defer creation of all Spring static loggers from appender until the appender is initialized. The first logger (e.g. Spring Boot) intializes the static `LoggerContext` field in `LogAdapter.Log4jLog`; this, in turn initializes the appender. However, the appender references Spring objects that have static loggers. This causes the `Log4jLog` CTOR to be called before the field is initialized, causing an NPE. Defer creation of all static loggers until the appender is fully initialized. Tested with the log4j2 sample app.
garyrussell
added a commit
to garyrussell/spring-amqp
that referenced
this issue
Jan 27, 2020
Resolves spring-projects/spring-amqp-samples#59 Defer creation of all Spring static loggers from appender until the appender is initialized. The first logger (e.g. Spring Boot) intializes the static `LoggerContext` field in `LogAdapter.Log4jLog`; this, in turn initializes the appender. However, the appender references Spring objects that have static loggers. This causes the `Log4jLog` CTOR to be called before the field is initialized, causing an NPE. Defer creation of all static loggers until the appender is fully initialized. Tested with the log4j2 sample app. **cherry-pick to 2.1.x**
garyrussell
added a commit
to garyrussell/spring-amqp
that referenced
this issue
Jan 27, 2020
Resolves spring-projects/spring-amqp-samples#59 Defer creation of all Spring static loggers from appender until the appender is initialized. The first logger (e.g. Spring Boot) initializes the static `LoggerContext` field in `LogAdapter.Log4jLog`; this, in turn initializes the appender. However, the appender references Spring objects that have static loggers. This causes the `Log4jLog` CTOR to be called before the field is initialized, causing an NPE. Defer creation of all static loggers until the appender is fully initialized. Tested with the log4j2 sample app. Also add a test for async sends. **cherry-pick to 2.1.x**
This was referenced Jan 27, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reproduce steps:
Start latest windows RabbitMQ on localhost:5672
checkout master branch from this project spring-amqp-samples
Go to module log4j2. You can see the spring-boot version should be 2.2.2.RELEASE in log4j2/pom.xml
Run module log4j2. get error log from stdout
Delete exchange
log4j2Sample
from RabbitMQ management UI, because default value ofdurable
in annotationorg.springframework.amqp.rabbit.annotation.Exchange
are different between differentspring-rabbit
version.Change spring-boot-starter-parent version in log4j2/pom.xml to 1.5.x.RELEASE (I tested 1.5.3, 1.5.10, 1.5.22), run module log4j2, sample works and you can see log
Delete exchange
log4j2Sample
from RabbitMQ management UI, because default value ofdurable
in annotationorg.springframework.amqp.rabbit.annotation.Exchange
are different between differentspring-rabbit
version.Change spring-boot-starter-parent version in log4j2/pom.xml to 2.0.0.RELEASE, run module log4j2, get error log
The text was updated successfully, but these errors were encountered: