Hello, I noticed, that its not possible to provide any kind of default for logging.pattern.console because the property behaves completely different then all other properties.

I maintain some shared libs on top of spring boot that we use in our company to implement some basic features every teams in our company needs.

So i tried to make a library that provides a new default for logging.pattern.console that the teams can use but still have the possibility to overwrite it with their own pattern if necessary.

Normally this is very easy to do:

  1. Create a new Library,
  2. Add a properties file with the property i want to set a default for
  3. add a @Configuration class with a @PropertySource referencing the property file.

But this has no effect for logging.pattern.console. The new value is set, U can access it with @Value but the logging pattern on the console is not changed.

I also tried adding a new custom property like my.logging.pattern.console=test so that the other developers can reference it in their application.properties like this logging.pattern.console=${my.logging.pattern.console} but that does not work as well. The application then just logs

my.logging.pattern.console_IS_UNDEFINEDmy.logging.pattern.console_IS_UNDEFINEDmy.logging.pattern.console_IS_UNDEFINED

I did not find any hint in the documentation that this property works different then other properties so i consider the behavior a bug. I attached a sample project that shows the issue: logging-issue.zip

Comment From: wilkinsona

This is documented in Custom Log Configuration where it says:

Since logging is initialized before the ApplicationContext is created, it is not possible to control logging from @PropertySources in Spring @Configuration files.

Customize the Environment or ApplicationContext Before It Starts describes how to customize the environment in a way that is early enough for the configuration to be picked up by the logging system.

Comment From: mnisius

Thank you! I was not aware of this solution. I tried with a EnvironmentPostProcessor before but I was not aware of this programmatic approach to register properties from files.