Skip to content
Advertisement

Spring boot with log4j2. Configure log4j2 Spring-lookup

According to log4j2 documentation:

The Spring Boot Lookup retrieves the values of Spring properties from the Spring configuration. This Lookup will return null values until Spring Boot initializes application logging.

JavaScript

This Lookup requires log4j-spring-cloud-config-client be included in the application.

What is the proper way to configure such a lookup?

I tried to assemble the following application:

build.gradle

JavaScript

main

JavaScript

application.yml

JavaScript

log4j-spring.xml

JavaScript

I expect the resolver to properly substitute “Demo” as the application name, however this does not happen. Does spring-boot-starter-log4j2 missing some dependencies for this to work out of the box ?

Edit This is the most simplified case. In reality, I want to pass the application-name to the gelf graylog appender. And I would like to share the same logging configuration within multiple components. So workarounds, like defining a log4j property, or using spring logging configuration, are not suitable.

Advertisement

Answer

Update 14.05.2021: Starting from log4j 2.14.0 there is a separate module for spring-lookup. Unfortunately, spring-boot still does not have high-enough dependency of log4j. But at least one can avoid using whole cloud-config-dependency.

JavaScript

+++++++++++++++++++

Based on @rgoers input I was able to assemble minimal configuration to run log4j2 Spring lookup:

build.gradle

JavaScript

Additionally, to disable cloud-config (which is required for look up, but might not be needed for the application):

bootstrap.yml (separate file additional to application.yml)

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement