Skip to content
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

Masquage des logs d'information spring - affichage des variables d'environnement utiles prise en compte au lancement #20

Closed
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
12 changes: 9 additions & 3 deletions batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
<version>5.3.8</version>
</dependency>
<!-- ************** RETRY *************************** -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -68,9 +77,6 @@
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>

Expand Down
27 changes: 26 additions & 1 deletion batch/src/main/java/fr/abes/item/batch/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,36 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import java.util.Arrays;

@SpringBootApplication
public class Application {
private static Environment env;

public Application(Environment environment) {
env = environment;
}

public static void main(String[] args) {
SpringApplication.exit(SpringApplication.run(Application.class, args));
SpringApplication app = new SpringApplication(Application.class);
app.setAdditionalProfiles("batch"); // Activer le profil "batch"
app.run(args);
System.out.println("App launched." +
" | Env:" + Arrays.toString(env.getActiveProfiles()) +
" | Port:" + env.getProperty("server.port") +
" | Module:" + "batch"

);
System.out.println("Connected to." +
" | BDD:" + env.getProperty("spring.datasource.item.jdbcurl") +
" | XMLBase:" + env.getProperty("spring.datasource.basexml.jdbcurl")

);
System.out.println("Level of log." +
" | App: " + env.getProperty("logging.level.fr.abes") +
" | Spring: " + env.getProperty("logging.level.root")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,4 @@ protected JobParametersIncrementer incrementer() {
return new TimeIncrementer();
}

}
}
5 changes: 5 additions & 0 deletions batch/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ batch.min.hour=8
batch.max.hour=20

spring.batch.jdbc.initialize-schema=always

# Configuration des logs
logging.config=classpath:log4j2-dev.xml
logging.level.root=WARN
logging.level.fr.abes=INFO
5 changes: 5 additions & 0 deletions batch/src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ batch.min.hour=8
batch.max.hour=20

spring.batch.jdbc.initialize-schema=never

# Configuration des logs
logging.config=classpath:log4j2-dev.xml
logging.level.root=ERROR
logging.level.fr.abes=WARN
5 changes: 5 additions & 0 deletions batch/src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ batch.min.hour=8
batch.max.hour=20

spring.batch.jdbc.initialize-schema=never

# Configuration des logs
logging.config=classpath:log4j2-dev.xml
logging.level.root=ERROR
logging.level.fr.abes=WARN
9 changes: 8 additions & 1 deletion batch/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ mail.ws.url=https://apicom.sudoc.fr/wsmail/
mail.admin=item@abes.fr

files.upload.path=/workdir/
files.upload.statistiques.path=/stat/
files.upload.statistiques.path=/stat/

# Configuration des logs
log4j2.logdir=logs

#spring logging configuration
spring.main.banner-mode=OFF
spring.output.ansi.enabled=ALWAYS
34 changes: 3 additions & 31 deletions batch/src/main/resources/log4j2-dev.xml
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Doc : http://logging.apache.org/log4j/2.x/manual/appenders.html#CustomDeleteOnRollover -->

<Configuration>
<Properties>
<!-- Les proprietes suivantes correspondent a des cles dans les fichiers application.properties -->
<Property name="logBaseDir">${bundle:application:application.basedir}/${bundle:application:log4j2.logdir}</Property>
<Property name="logFileName">${bundle:application:application.name}</Property>
<Property name="errorFileName">${bundle:application:application.name}_error</Property>
<Property name="debugFileName">${bundle:application:application.name}_debug</Property>

<!-- Politique de gestion des fichiers -->
<Property name="sizeTriggerPolicy">200 MB</Property>
<Property name="deleteAgeFile">15d</Property>
<Property name="keepMostRecentFile">10</Property>
<Property name="keepMostRecentSize">100 MB</Property>
</Properties>
<Appenders>

<!-- CONSOLE -->
<Appenders>
<Console name="Console">
<PatternLayout
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{dark,yellow}: %msg%n%throwable" />
<PatternLayout pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{dark,yellow}: %msg%n%throwable" />
</Console>

<!-- LOG FILE -->
<RollingFile name="LogFile"
fileName="${logBaseDir}/${logFileName}.log"
filePattern="${logBaseDir}/$${date:yyyy-MM}/${logFileName}_%d{dd-MM-yyyy}_%i.log.gz">
<PatternLayout>
<pattern>%5p %d{ISO8601} [%t][%x] %c - %m%n</pattern>
</PatternLayout>
<Policies>
<!-- On exécute les stratégies de création de nouveaux fichiers et de suppresion :
- Au démarrage de l'application
- Si l'un des fichiers atteint ${sizeTriggerPolicy}
- Si la date du filePattern nécessite un nouveau fichier -->
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="${sizeTriggerPolicy}" />
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${logBaseDir}" maxDepth="2">
<IfFileName glob="*/${logFileName}_*.log.gz">
<!-- On supprime les fichiers de plus de ${deleteAgeFile}
mais on garde les ${keepMostRecentFile} fichiers plus récent ou les ${keepMostRecentSize} plus récent-->
<IfLastModified age="${deleteAgeFile}" />
<IfAny>
<IfAccumulatedFileCount exceeds="${keepMostRecentFile}" />
Expand All @@ -53,29 +42,21 @@
</DefaultRolloverStrategy>
</RollingFile>

<!-- ERROR FILE -->
<RollingFile name="ErrorFile"
fileName="${logBaseDir}/${errorFileName}.log"
filePattern="${logBaseDir}/$${date:yyyy-MM}/${errorFileName}_%d{dd-MM-yyyy}_%i.log.gz">
<!-- ErrorFile ne recoit que le niveau error -->
<LevelRangeFilter minLevel="ERROR" maxLevel="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout>
<pattern>%5p %d{ISO8601} [%t][%x] %c - %m%n</pattern>
</PatternLayout>
<Policies>
<!-- On exécute les stratégies de création de nouveau fichier et de suppresion :
- Au démarrage de l'application
- Si l'un des fichiers atteint 10 MB
- Si la date du filePattern nécessite un nouveau fichier -->
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="${sizeTriggerPolicy}" />
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${logBaseDir}/" maxDepth="2">
<IfFileName glob="*/${errorFileName}_*.log.gz">
<!-- On supprime les fichiers de plus de ${deleteAgeFile}
mais on garde les ${keepMostRecentFile} fichier plus récent ou les ${keepMostRecentSize} plus récent-->
<IfLastModified age="${deleteAgeFile}" />
<IfAny>
<IfAccumulatedFileCount exceeds="${keepMostRecentFile}" />
Expand All @@ -86,29 +67,21 @@
</DefaultRolloverStrategy>
</RollingFile>

<!-- DEBUG FILE -->
<RollingFile name="DebugFile"
fileName="${logBaseDir}/${debugFileName}.log"
filePattern="${logBaseDir}/$${date:yyyy-MM}/${debugFileName}_%d{dd-MM-yyyy}_%i.log.gz">
<!-- DebugFile ne recoit que le niveau debug et trace -->
<LevelRangeFilter minLevel="DEBUG" maxLevel="TRACE" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout>
<pattern>%5p %d{ISO8601} [%t][%x] %c - %m%n</pattern>
</PatternLayout>
<Policies>
<!-- On exécute les stratégies de création de nouveau fichier et de suppresion :
- Au démarrage de l'application
- Si l'un des fichiers atteint 10 MB
- Si la date du filePattern nécessite un nouveau fichier -->
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="${sizeTriggerPolicy}" />
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${logBaseDir}/" maxDepth="2">
<IfFileName glob="*/${debugFileName}_*.log.gz">
<!-- On supprime les fichiers de plus de ${deleteAgeFile}
mais on garde les ${keepMostRecentFile} fichiers plus récent ou les ${keepMostRecentSize} plus récent-->
<IfLastModified age="${deleteAgeFile}" />
<IfAny>
<IfAccumulatedFileCount exceeds="${keepMostRecentFile}" />
Expand All @@ -129,5 +102,4 @@
<AppenderRef ref="ErrorFile" />
</Root>
</Loggers>

</Configuration>
132 changes: 0 additions & 132 deletions batch/src/main/resources/log4j2-prod.xml

This file was deleted.

Loading
Loading