Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request

jobs:
build:
check_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -15,6 +15,6 @@ jobs:
distribution: 'temurin'
# overrides the file ~/.m2/settings.xml with data to publish to maven pkg server with id github
overwrite-settings: true
- name: Build
- name: Verify
run: |
mvn -B verify
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: 'Build and Deploy'
name: 'Build and Deploy new releases'

on:
push:
branches: master
tags: '*'
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]

jobs:
build:
BuildThenDeployRelease:
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -17,10 +16,19 @@ jobs:
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
# overrides the file ~/.m2/settings.xml with data to publish to maven pkg server with id github
overwrite-settings: true
- name: Build
run: mvn install --no-transfer-progress
- name: Build and Sign*
env:
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
MAVEN_GPG_KEY: ${{ secrets.MAVEN_GPG_KEY }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
run: mvn install gpg:sign --no-transfer-progress
- name: Get current version
id: version
run: echo "::set-output name=prop::$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)"
Expand Down
19 changes: 4 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,15 @@ Usage is simple : just add this dependency inside your pom.xml :
<dependency>
<groupId>io.github.fbibonne</groupId>
<artifactId>boot-properties-logger-starter</artifactId>
<version>1.1.0</version>
<version>1.4.0</version>
</dependency>
```

NB :

1. the lib is not deployed on maven central for the moment so you must install
it locally before using it :

```shell
$ git clone https://github.com/FBibonne/Properties-Logger.git --depth=1 --branch=master
$ mvn install -f Properties-Logger/pom.xml
```

Now ou can also download it
from [the github project packages](https://github.com/FBibonne/Properties-Logger/packages/2229078)

2. The module module _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.
The module module _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.

## Result

Expand Down
68 changes: 62 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.github.fbibonne</groupId>
<artifactId>boot-properties-logger-starter</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -21,12 +21,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<contributors>
<contributor>
<name>Spring Boot Properties Logger</name>

<developers>
<developer>
<name>Fabrice Bibonne</name>
<url>https://github.com/Fbibonne</url>
</contributor>
</contributors>
</developer>
</developers>

<issueManagement>
<url>https://github.com/FBibonne/Properties-Logger/issues</url>
Expand All @@ -37,10 +39,20 @@
and their values resolved by Spring Boot.
</description>

<url>https://github.com/FBibonne/Properties-Logger?tab=readme-ov-file#readme</url>
<url>https://github.com/FBibonne/Properties-Logger</url>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>


<scm>
<developerConnection>scm:git:https://github.com/FBibonne/Properties-Logger.git</developerConnection>
<connection>scm:git:git://github.com/FBibonne/Properties-Logger.git</connection>
<url>https://github.com/FBibonne/Properties-Logger/tree/master</url>
</scm>

<distributionManagement>
Expand Down Expand Up @@ -92,6 +104,50 @@
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.8</version>
<configuration>
<signer>bc</signer>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.8.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<deploymentName>Properties-Logger</deploymentName>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
import java.util.Optional;
import java.util.Set;

/**
* Spring ApplicationListener which triggers on {@link ApplicationEnvironmentPreparedEvent} to start properties logging process.
* If the logging is enabled (with property {@code properties.logger.disabled} at {@code false} (which is default value) ) and the
* environment associated with the applicationEnvironmentPreparedEvent is an {@link ConfigurableEnvironment}, then the listener
* will log properties using provided configuration. The responsibility of this class is only to trigger the process and collect the
* configuration for logging properties (properties starting with {@code properties.logger}) in the environment. It delegates the
* logging process to an instance of {@link PropertiesLogger}
*/
public record EnvironmentPreparedEventForPropertiesLogging() implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

private static final LocalLogger log = new LocalLogger(EnvironmentPreparedEventForPropertiesLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
import java.util.function.UnaryOperator;
import java.util.stream.Stream;

/**
* Class doing the real stuff for logging properties. The collect of properties to log, their value and the logging is done
* inside the {@link this#doLogProperties(EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment)} method.
* The state of the class stores {@link PropertySource} found, and a reference to an operator providing the origin of a property
* which is found while scanning propertySources
*/
class PropertiesLogger {

public static final String SEPARATION_LINE = "================================================================================";
Expand All @@ -35,6 +41,22 @@ class PropertiesLogger {
this.ignoredPropertySources = ignoredPropertySources;
}

/**
* This method :
* <ol>
* <li>lists all propertySources of the environment and exclude all those which cannot be processed (see method {@link this#isEnumerable(PropertySource)}
* or are listed to be ignored (see property {@code properties.logger.sources-ignored}</li>
* <li>for each propertySource not excluded, list all property keys then exclude {@code null} keys and non-allowed prefixed ones (see property {@code properties.logger.prefix-for-properties}</li>
* <li>order distinct keys with alphabetical order (natural order of {@link String}</li>
* <li>for each key, compute an expression {@code key = value ### FROM value_origin ###} where {@code value} is the value of the key resolved against
* the environment (or masked if key is listed in property {@code properties.logger.with-hidden-values}) and {@code value_origin} is the
* propertySource which contains the value to which the key is resolved (if field {@link this#originFinder} can resolve it)</li>
* <li>log the list of used propertySources to find keys, the ordered list of properties and their values and origin when available</li>
* </ol>
*
* @param abstractEnvironment : the environment of the application wrapped as an {@link io.github.fbibonne.springaddons.boot.propertieslogger.EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment}
* to safely resolve properties with unknown placeholders
*/
public void doLogProperties(final EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment abstractEnvironment) {
log.debug(() -> "Start logging properties with prefix " + allowedPrefixForProperties + " for all properties sources except " + ignoredPropertySources + ". Values masked for properties whose keys contain " + propertiesWithHiddenValues);

Expand Down Expand Up @@ -102,6 +124,16 @@ private Stream<String> toPropertyNames(EnumerablePropertySource<?> propertySourc
return Arrays.stream(propertySource.getPropertyNames());
}

/**
* Method which filter propertySource which can be processed to find properties to log.
* propertySource which can be processed are a subtype of {@link EnumerablePropertySource} : if not method log a
* debug message or a warning message for cases not implemented yet (AnsiPropertySource and JndiPropertySource). If
* propertySource is of type {@link org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource},
* it will be referenced to resolve origin of property values later (see {@link this#originFinder}. If propertySource
* has an unknown type, a warning is logged.
* @param propertySource : instance of {@link PropertySource} which is checked for being processed or not.
* @return true if the propertySource can be processed.
*/
private boolean isEnumerable(PropertySource<?> propertySource) {
if (propertySource instanceof AnsiPropertySource ansiPropertySource) {
log.warn(()->"Processing of AnsiPropertySource "+ ansiPropertySource+" not yet implemented : properties exclusively from this property source will be ignored");
Expand Down