Skip to content

FBibonne/Spring-Boot-Properties-Logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Properties Logger

Properties Logger is an extension for Spring Boot 4+ apps which early logs properties detected by Spring Boot and their values resolved by Spring Boot.

Requirements

The properties Logger module is designed to work with :

  • Spring Boot 4.0+ and java 17+ (have a look to versions 1.x for Spring Boot 3)
  • Servlet web application
  • Reactive web application (not tested)
  • Batch application (not tested)
  • CommandLineRunner application (not tested)

Usage

Usage is simple: add this dependency inside your pom.xml :

<dependency>
    <groupId>io.github.fbibonne</groupId>
    <artifactId>boot-properties-logger-starter</artifactId>
    <version>2.1.0</version>
</dependency>

NB :

The library _Properties Logger_ logs its message with properties and their values
at the info level : so its **log level must be at least INFO**. DEBUG (or TRACE) give (much) more
informations : `logging.level.io.github.fbibonne.springaddons.boot = INFO`

Result

You should see this kind of output in your log (in the console by default in a Spring Boot application) :

2025-08-25T12:01:00.858+02:00  INFO 42091 --- [           main] io.github.fbibonne.springaddons.boot.propertieslogger.EnvironmentPreparedEventForPropertiesLogging           : 
================================================================================
                        Values of properties from sources :
- Config resource 'class path resource [application.properties]' via location 'optional:classpath:/'
                                     ====
logging.level.root = INFO ### FROM "logging.level.root" from property source "commandLineArgs" ###
management.endpoint.health.show-details = always ### FROM class path resource [application.properties] - 10:43 ###
server.forward-headers-strategy = framework ### FROM class path resource [application.properties] - 5:35 ###
springdoc.pathsToMatch = /** ### FROM class path resource [application.properties] - 3:26 ###
springdoc.show-actuator = true ### FROM class path resource [application.properties] - 1:27 ###
springdoc.swagger-ui.oauth.clientId = ### FROM class path resource [application.properties] - 4:39 ###
springdoc.swagger-ui.path = / ### FROM class path resource [application.properties] - 2:29 ###
springdoc.swagger-ui.syntax-highlight.activated = false ### FROM class path resource [application.properties] - 9:51 ###
spring.application.pid = 379695 ### FROM "spring.application.pid" from property source "applicationInfo" ###
spring.datasource.password = ****** ### FROM System Environment Property "spring.datasource.password" ###
spring.datasource.username = user ### FROM class path resource [application.properties] - 7:30 ###
spring.security.oauth2.resourceserver.jwt.jwk-set-uri = ### FROM class path resource [application.properties] - 6:57 ###
================================================================================

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::             (v4.0.2)

The first part of the log message generated by the library (before the separator ==== ) lists the sources from wich properties keys are collected: only the property sources which are enumerable and which are not excluded are listed there.

The second part of the log message (after the separator ==== ) lists collected properties key which starts with one element of the prefix list and its value resolved by Spring Boot followed by its origin. The displayed value is not necessarily the one that is defined in the property source where Spring Boot encoutered the key, but the real one that Spring Boot would provide to your application (for example, in a @Value annotation) following its property resolver algorithm

For example, given the property key spring.datasource.username. If it is defined in the application.properties file with user_dev value :

spring.datasource.username=user_dev

But the environement variable SPRING_DATASOURCE_USERNAME is also defined with the value user_prod.

The Properties Logger library will display the property spring.datasource.username (because by default the keys listed in the application.properties file ar listed) but with the value of user_prod as resolved by Spring Boot due to the environment variable. The environment variable is not listed because by default the property keys in the system environment property source (systemEnvironment) are not displayed.

By the way, it will display the origin of the value as FROM System Environment Property "SPRING_DATASOURCE_USERNAME"

Values of properties with secrets are hidden when they are printed : ****** is displayed instead. For example spring.datasource.password = ******. To be hidden, the property key must contain (case is ignored) one of the words from the list properties with secrets.

Configuration

We describe here configurations which can be applied to the library Properties Logger via properties prefixed by properties.logger. They are three of them:

Excluded properties sources

Related Property Default value
properties.logger.sources-ignored systemProperties, systemEnvironment

At starting, Spring Boot can process many property sources and not all of them provide values for the properties used in your application. Particularly the system properties (java properties which can be read with System#getProperty) and the OS environment variables (can be read with System#getenv) contain many key-value pairs which you do not directly use in your application : displaying them make the log too much verbose. So you can exclude the properties key exclusively defined by these property sources listing them in the properties.logger.sources-ignored.

By default the system properties (systemProperties) and the environment variables(systemEnvironment) are excluded. You can exclude more properties source by adding their names to the list.

For example, to not not take into account property keys from :

  1. the file application.properties
  2. a file with a relative path ../secrets/secret.properties
  3. the command line arguments
  4. the properties attribute of @SpringBootTest and others @*Test annotations, > you should set these values :
properties.logger.sources-ignored=systemProperties, systemEnvironment,\
[application.properties],\
../secrets/secret.properties,\
commandLineArgs,\
Inlined\ Test\ Properties

At first line, set default exclusions (RECOMMENDED) then add others exclusions :

  1. at second line, for the the application.properties file,
  2. at third line for ../secrets/secret.properties file
  3. at fourth line for command line arguments
  4. at fifth line for then properties attributes for tests

NB :

When you exclude a property source, you do not exclude property values of this source since if the property is present in an other source not excluded and if the value for this property is resolved to the value of the excluded source, the value of the excluded source will be displayed in logs. Furthermore, when you exclude a property source you do not exclude properties which are also listed at least in one another not excluded property source.

Prefix list for displayed properties

Related Property Default value
properties.logger.prefix-for-properties debug, trace, info, logging, spring, server, management, springdoc, properties

Only the properties whose keys start with one of the prefix listed in properties.logger.prefix-for-properties will be displayed (if they ar also in a non excluded property source). If you set properties.logger.prefix-for-properties to empty, no property will be displayed. It is recommended to set the value of properties.logger.prefix-for-properties to the default plus the beginning of your company name to display the properties for your application.

Properties with hidden values

Related Property Default value
properties.logger.with-hidden-values password, pwd, token, secret, credential, pw

When a property is displayed, there is a filter which avoid to leak secrets in logs : all properties whose key contains one of the token in properties.logger.with-hidden-values will be displayed with the value ****** instead of the actual value. The default value of properties.logger.with-hidden-values contains the most common tokens for secrets but you should add the specific ones you may have in your application.

Disabling library

Related Property Default value
properties.logger.disabled false

If you want to temporarily disable the library and suspend displaying of properties without modifying the classpath and other settings, set this property to true. By default, the library is enabled.

Origins of values

While displaying the actual value of a property, the library also displays the origin of the property: that is the source (file, system propeties, environment variables ...) the value comes from. Origin is displayed with the following format after the value of the property : ### FROM System Environment Property "SPRING_DATASOURCE_USERNAME" ###

Warnings

Properties which will not be displayed

The Properties-Logger library cannot display properties or values provided by some sources which are processed after the environment preparation phase. That is the case for mechanisms like beans factory post processors or application context customizers for tests. In any case, because these mechanisms are involved after the library runs, it cannot discover the properties or values they provide since they are valued after.

from files from @PropertySource annotations

@PropertySource annotations over @Configuration classes let define properties source files whose parsing is triggered by a factory post processor. Factory post processors run after the library, so properties and/or values in these files cannot be displayed

from @DynamicPropertySource annotated methods

@DynamicPropertySource methods are a specific mecanism dedicated to test which let you define or overrride properties values very late so it is not in the scope of the Properties Logger library which aims to display properties at the earliest time in the application lifecycle. It is strongly recommended to not define in other place properties from @DynamicPropertySource methods. If you have no other choice (make sure you had a complete look to the numerous ways to override properties in Spring Boot ) that defining @DynamicPropertySource methods to override properties in a test and you want to check the value of the overrided property, consider logging it yourself or write an assertion in your test

Maintainers notes

  • to update pom.xml if one can't get dependabot, find updates with :
    mvn -ntp org.codehaus.mojo:versions-maven-plugin:2.21.0:display-property-updates
    mvn -ntp org.codehaus.mojo:versions-maven-plugin:2.21.0:display-parent-updates
    

About

Library to log actual properties read by Spring Boot when starting

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages