IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Boot Java Discussion :

Spring-boot avec log4j2 -- Fichier de log créé à la compilation, mais ignoré ensuite (pas de logs)


Sujet :

Spring Boot Java

  1. #1
    Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Août 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Août 2007
    Messages : 59
    Points : 69
    Points
    69
    Par défaut Spring-boot avec log4j2 -- Fichier de log créé à la compilation, mais ignoré ensuite (pas de logs)
    Bonjour,
    je vous expose le problème que je rencontre :

    (1.)L'application sur laquelle je travaille :
    C'est une application web, avec des services REST.
    Les technologies utilisées :
    • La base de données : mysql
    • Le serveur d'application : tomcat
    • Le logueur : log4j2
    • Le gestionnaire de dépendances : maven
    • Le framework : spring-boot


    (2.)Le fichier pom.xml de mon application :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    <project xmlns="http://maven.apache.org/POM/4.0.0" 
    		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     
    	<modelVersion>4.0.0</modelVersion>
     
    	<groupId>afpa.cdi.banque</groupId>
    	<artifactId>GestionBancaireSpringBoot</artifactId>
    	<packaging>war</packaging>
    	<version>1.0-SNAPSHOT</version>
     
    	<name>GestionBancaireSpringBoot Maven Webapp</name>
    	<description>Gestion d'activités bancaires</description>
    	<url>http://maven.apache.org</url>
     
    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>1.5.1.RELEASE</version>
    		<relativePath/> <!-- lookup parent from repository -->
    	</parent>
     
    	<properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    		<java.version>1.8</java.version>
    	</properties>
     
    	<dependencies>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-data-jpa</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-data-rest</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-thymeleaf</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    		</dependency>
     
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-tomcat</artifactId>
    			<scope>provided</scope>
    		</dependency>
     
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    			<scope>runtime</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-test</artifactId>
    			<scope>test</scope>
    		</dependency>
     
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-api</artifactId>
    		</dependency>
    		<dependency>
    		    <groupId>org.apache.logging.log4j</groupId>
    		    <artifactId>log4j-slf4j-impl</artifactId>
    		</dependency>
     
    		<dependency>
    		    <groupId>org.apache.logging.log4j</groupId>
    		    <artifactId>log4j-api</artifactId>
    		</dependency>		
    		<dependency>
    		    <groupId>org.apache.logging.log4j</groupId>
    		    <artifactId>log4j-core</artifactId>
    		</dependency>
    		<dependency>
    		    <groupId>org.apache.logging.log4j</groupId>
    		    <artifactId>log4j-jcl</artifactId>
    		</dependency>		
     
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter</artifactId>
    			<exclusions>
    				<exclusion>
    					<groupId>org.springframework.boot</groupId>
    					<artifactId>spring-boot-starter-logging</artifactId>
    				</exclusion>
    			</exclusions>
    		</dependency>		
     
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-log4j2</artifactId>
    		</dependency>		
     
    		<!-- dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-security</artifactId>
    		</dependency -->
     
    		<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity4 -->
    		<!-- dependency>
    			<groupId>org.thymeleaf.extras</groupId>
    			<artifactId>thymeleaf-extras-springsecurity4</artifactId>
    			<version>2.1.2.RELEASE</version>
    		</dependency -->
    	</dependencies>
     
    	<build>
    		<finalName>GestionBancaireSpringBoot</finalName>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-maven-plugin</artifactId>
    			</plugin>
     
    			<plugin>
    			    <artifactId>maven-compiler-plugin</artifactId>
    			    <configuration>
    			        <source>1.8</source>
    			        <target>1.8</target>
    			    </configuration>
    			</plugin>			
    		</plugins>
    	</build>
    </project>
    (3.)Le fichier application.properties de mon application :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    spring.datasource.url=jdbc:mysql://localhost:3306/banquedb?createDatabaseIfNotExist=true
    spring.datasource.username=root
    spring.datasource.password=root
    spring.datasource.driverClassName=com.mysql.jdbc.Driver
     
    spring.jpa.show-sql=true
    spring.jpa.hibernate.ddl-auto=create
    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
     
    logging.config=classpath:log4j2-spring.xml
    (4.)L'emplacement des fichiers évoqués précédemment :
    • Le fichier pom.xml : à la racine du projet.
    • Le fichier application.properties : dans le répertoire "src\main\resources".
    • Le fichier log4j2-spring.xml : dans le répertoire "src\main\resources".


    (5.)La compilation du projet :
    • Le projet est compilé avec maven : "mvn clean install -e -X"
    • Le fichier exécutable est généré : "GestionBancaireSpringBoot.war"
    • Les 2 fichiers de log sont créés et remplis : "banquedb-application.log" et "banquedb-springboot.log".

    (6.)L'exécution du projet :
    • L'application est déployée sur tomcat.
    • Les appels REST sont reçus par l'application.
    • Les logs produits par mon code : ils sont affichés dans la console.
    • Le fichier de log "banquedb-springboot.log" : il continue de se remplir (mais les logs ne proviennent pas de mon code).
    • Le fichier de log "banquedb-application.log" : il ne se remplit pas (je m'attendais à y voir les logs provenant de de mon code).


    (7.)Le comportement espéré :
    Les logs produits par mon code : je souhaiterais qu'ils soient logués dans le fichier "banquedb-application.log".
    Cela ne se fait pas (les logs sont affichés dans la console uniquement).
    Y a-t-il un moyen de corriger ce comportement indésirable ?
    Pourriez-vous me donner des pistes pour que je cherche l'erreur, SVP ?
    Merci d'avance pour vos aides...
    chat_roux

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Les logs que tu vois sur le console, tu peux le voir dans catalina.out.

    Pour ton problème, ajoute
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    logging.path=logs
    logging.file=logs/banquedb-application.log
    dans ton fichier application.properties.
    Sinon, montre nous le fichier log4j2-spring.xml

    A+.

  3. #3
    Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Août 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Août 2007
    Messages : 59
    Points : 69
    Points
    69
    Par défaut Comportement indésirable : cause trouvée, mais cela pose un autre problème
    Re-bonjour,

    (1.)Le comportement indésirable :
    (décrit en détails dans mon post précédent)
    Les logs générés par mon application web :
    • durant la compilation : ils sont logués dans mon fichier de log.
    • durant l'exécution (lorsque l'application est déployée sur le serveur) : ils ne sont plus logués dans mon fichier de log.

    (2.)La cause de ce comportement :
    Le fichier "log4j2-spring.xml" contient une erreur.

    Le bloc de code (extrait du fichier) qui définit l'emplacement du fichier de log :
    Il est contient une erreur. Le voici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        
        <Properties>
            <Property name="log-path">log</Property>
        </Properties>
    L'erreur :
    La propriété : "log-path"
    La valeur qui lui est affectée : log

    Le problème :
    • durant la compilation : cette valeur est interprétée comme un chemin de répertoires relatif par rapport à la racine du projet. Et celui-ci est trouvé dans le projet.
    • durant l'exécution : cette valeur est interprétée comme un chemin de répertoires relatif par rapport au répertoire "tomcat\bin". Et le répertoire de log est créé à cet emplacement (pas du tout l'emplacement souhaité !!!!!). Et le fichier de log est créé à cet emplacement. Et les logs y sont logués.


    (3.)Solution proposée :
    La propriété "log-path" : je lui affecte la valeur "${sys:catalina.base}/logs"

    Et là, je devrais obtenir le comportement suivant :
    • durant la compilation : les logs seront écrits dans le fichier de log qui se trouve dans "tomcat\logs" (nouveau comportement indésirable !!!).
    • durant l'exécution : les logs seront écrits dans le fichier de log qui se trouve dans "tomcat\logs" (comportement correct souhaité).


    (4.)Conclusion:
    La solution proposée produit :
    • durant la compilation : un comportement incorrect.
    • durant l'exécution : le comportement correct souhaité.

    Si quelqu'un a une solution qui produit un comportement correct dans les 2 phases (compilation et exécution), je serais preneur.
    Sinon, je me contenterais de cette demi-solution.
    J'attendrai quelques jours vos réactions avant de décider de mettre cette discussion à "résolue". Au cas où quelqu'un trouverait une solution meilleure !!!

  4. #4
    Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Août 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Août 2007
    Messages : 59
    Points : 69
    Points
    69
    Par défaut Fichier log4j2-spring.xml
    Re-bonjour,

    Excusez-moi, j'avais oublié de fournir mon fichier log4j2-spring.xml.

    Le voici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Configuration>
     
    <Configuration monitorInterval="60">
     
        <Properties>
            <Property name="log-path">log</Property>
        </Properties>
     
        <Appenders>
            <Console name="Console-Appender" target="SYSTEM_OUT">
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>>
                </PatternLayout>
            </Console>
            <File name="Application-File-Appender" fileName="${log-path}/banquedb-application.log" >
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
                </PatternLayout>
            </File>
            <File name="SpringBoot-File-Appender" fileName="${log-path}/banquedb-springboot.log" >
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
                </PatternLayout>
            </File>
        </Appenders>
     
        <Loggers>
            <Logger name="org.springframework.web" level="info" additivity="true">
                <AppenderRef ref="SpringBoot-File-Appender" level="all"/>
                <AppenderRef ref="Console-Appender"/>
            </Logger>
            <Logger name="afpa.cdi.banque.service" level="all" additivity="true">
                <AppenderRef ref="Application-File-Appender" level="all"/>
                <AppenderRef ref="Console-Appender"/>
            </Logger>
            <Root>
                <AppenderRef ref="Console-Appender" level="all"/>
            </Root>
        </Loggers>
     
    </Configuration>
    Avec la valeur défectueuse du log-path (c'est-à-dire "log"). Afin que les gens comprennent le comportement indésirable.

    A andry.aime : merci, je vais compléter mon fichier application.properties avec les valeurs que vous m'avez fournies. Je vous tiens au courant du résultat...
    chat_roux

  5. #5
    Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Août 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Août 2007
    Messages : 59
    Points : 69
    Points
    69
    Par défaut La solution "${sys:catalina.home}" : elle ne fonctionne pas
    Bonjour,

    (1.)Le comportement incorrect :
    Les logs ne sont pas logués dans le fichier prévu pour cela.
    (détaillé dans les post précédents)

    (2.)La solution proposée :
    Corriger le fichier "log4j2-spring.xml".
    (proposée dans un post précédent)

    (3.)Le fichier log4j2-spring.xml corrigé:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Configuration>
     
    <Configuration monitorInterval="60">
     
        <Properties>
            <Property name="log-path">"${sys:catalina.home}/logs"</Property>
        </Properties>
     
        <Appenders>
            <Console name="Console-Appender" target="SYSTEM_OUT">
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>>
                </PatternLayout>
            </Console>
            <File name="Application-File-Appender" fileName="${log-path}/banquedb-application.log" >
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
                </PatternLayout>
            </File>
            <File name="SpringBoot-File-Appender" fileName="${log-path}/banquedb-springboot.log" >
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
                </PatternLayout>
            </File>
        </Appenders>
     
        <Loggers>
            <Logger name="org.springframework.web" level="info" additivity="true">
                <AppenderRef ref="SpringBoot-File-Appender" level="all"/>
                <AppenderRef ref="Console-Appender"/>
            </Logger>
            <Logger name="afpa.cdi.banque.service" level="all" additivity="true">
                <AppenderRef ref="Application-File-Appender" level="all"/>
                <AppenderRef ref="Console-Appender"/>
            </Logger>
            <Root>
                <AppenderRef ref="Console-Appender" level="all"/>
            </Root>
        </Loggers>
     
    </Configuration>
    (4.)Résultat :
    Durant la compilation (mvn clean install -e -X), j'obtiens une exception. La voici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    Forking command line: cmd.exe /X /C "E:\_SOFTWARE\11_ApplicationDevelopmentTools\_JDK\jdk8\jre\bin\java -jar G:\_DEVLOPMT\10-ProgrammationWebServices\01-SpringREST\GestionBancaireSpringBoot\target\surefire\surefirebooter6924963682719501635.jar G:\_DEVLOPMT\10-ProgrammationWebServices\01-SpringREST\GestionBancaireSpringBoot\target\surefire\surefire3645294213669373707tmp G:\_DEVLOPMT\10-ProgrammationWebServices\01-SpringREST\GestionBancaireSpringBoot\target\surefire\surefire_02239540232066352643tmp"
    Running afpa.cdi.banque.BanqueApplicationTests
    2017-03-09 13:16:44,884 main ERROR FileManager ("${sys:catalina.home}/logs"/banquedb-application.log) java.io.FileNotFoundException: "${sys:catalina.home}\logs"\banquedb-application.log (La syntaxe du nom de fichier, de r걥rtoire ou de volume est incorrecte) java.io.FileNotFoundException: "${sys:catalina.home}\logs"\banquedb-application.log (La syntaxe du nom de fichier, de r걥rtoire ou de volume est incorrecte)
    	at java.io.FileOutputStream.open0(Native Method)
    	at java.io.FileOutputStream.open(FileOutputStream.java:270)
    	at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    	at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:258)
    	at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:238)
    	at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:112)
    	at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
    	at org.apache.logging.log4j.core.appender.FileManager.getFileManager(FileManager.java:110)
    	at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:89)
    	at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:51)
    	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:942)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:882)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:498)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:227)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:239)
    	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:530)
    	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:258)
    	at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:176)
    	at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:167)
    	at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
    	at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56)
    	at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:148)
    	at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308)
    	at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
    	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
    	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
    	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
    	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    	at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)
    	at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)
    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
    Cette erreur est décrite dans une autre discussion déjà présente dans "developpez.com", mais qui n'a pas été résolue (pas encore).
    L'intervenant expliquait que l'expression "${sys:catalina.home}" n'est pas résolue (=remplacée par le chemin de répertoire absolu).
    Pourquoi ? Quelqu'un a-t-il une réponse ?
    Je continue de chercher et vous tiens au courant. Bon courage à toute la communauté "developpez.com".

  6. #6
    Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Août 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Août 2007
    Messages : 59
    Points : 69
    Points
    69
    Par défaut Fichier log4j2-spring.xml -- Variable "${sys:catalina.home}" -- Les logs sont logués correctement
    Re-Bonjour,

    Après avoir longuement testé, je récapitule les étapes à effectuer pour que les logs soient logués correctement :

    (1.)Créer la variable d'environnement "CATALINA_HOME" :
    par exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    set CATALINA_HOME=C:\apache-tomcat
    (2.)Le fichier application.properties :
    Les valeurs que j'ai renseignées dedans ("logging.path" et "logging.file") ont été ignorées. (pas grave, la présente procédure fonctionne quand même !).

    (3.)Renseigner le fichier log4j2-spring.xml :
    par exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Configuration>
     
    <Configuration monitorInterval="60">
     
        <Properties>
            <Property name="log-path">${sys:catalina.home}/logs/GestionBancaire</Property>
        </Properties>
     
        <Appenders>
            <Console name="Console-Appender" target="SYSTEM_OUT">
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>>
                </PatternLayout>
            </Console>
            <File name="Application-File-Appender" fileName="${log-path}/GestionBancaire-application.log" >
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
                </PatternLayout>
            </File>
            <File name="SpringBoot-File-Appender" fileName="${log-path}/GestionBancaire-springboot.log" >
                <PatternLayout>
                    <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
                </PatternLayout>
            </File>
        </Appenders>
     
        <Loggers>
            <Logger name="org.springframework.web" level="info" additivity="true">
                <AppenderRef ref="SpringBoot-File-Appender" level="all"/>
                <AppenderRef ref="Console-Appender"/>
            </Logger>
            <Logger name="afpa.cdi.banque.service" level="all" additivity="true">
                <AppenderRef ref="Application-File-Appender" level="all"/>
                <AppenderRef ref="Console-Appender"/>
            </Logger>
            <Root>
                <AppenderRef ref="Console-Appender" level="all"/>
            </Root>
        </Loggers>
     
    </Configuration>
    (4.)Compiler le projet :
    Avec maven :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mvn clean install -e -X
    (5.)Déployer l'application sur le serveur :
    Fichier à déployer : "GestionBancaire.war"

    (6.)Observations
    Dans le serveur tomcat :
    Dans le sous-répertoire "logs", mon sous-répertoire "GestionBancaire" est crée.
    Et dans ce sous-répertoire "GestionBancaire", mes 2 fichiers de logs sont créés et remplis.

    Conclusion : les logs sont logués dans le bon fichier, au bon emplacement.
    Donc pour moi le problème est résolu.

    Merci à tous pour vos contributions. Et bon courage à toute la communauté "développez.com".
    ()

  7. #7
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Mettre le fichier log dans le répertoire de l'application est une mauvaise idée. Si tu feras un nouveau déploiement, les anciens log seront supprimés.
    Pense aussi à découper ton fichier log à chaque intervalle de temps ou limiter la taille du fichier log pour éviter de te trouver avec un seul fichier log très énorme et aussi de te permettre de trouver des traces plus facilement.
    Pourquoi mettre aussi les logs de compilation dans le même fichier que celui de l'application, ceux sont deux choses différent, et que tu utiliseras probablement de machines différents pour le build et le déploiement (différent variable d'environnement).

    A+.

  8. #8
    Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Août 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Août 2007
    Messages : 59
    Points : 69
    Points
    69
    Par défaut Logs de compilation (avec MAVEN) / Logs de déploiement et d'exécution (sur TOMCAT)
    Bonjour,

    merci pour tes explications détaillées.

    Je récapitule la manière de procéder :
    (je me suis appuyé sur tes explications, j'espère ne pas m'être trompé !!)

    ->(01.)LA COMPILATION :

    Le fichier de log (de compilation) est généré avec le nom et l'emplacement suivants :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Fichier    : "mvnCleanInstall-%DATE%-%TIME%.log" (la date et l'heure sont rajoutées dans le nom du fichier)
    Répertoire : "GestionBancaire\log"               ("GestionBancaire" est le répertoire racine de l'application)
    ->(02.)LE DEPLOIEMENT ET L'EXECUTION :

    Les fichiers de log (de déploiement et d'exécution) sont générés avec le nom et l'emplacement suivants :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Fichier1   : "GestionBancaire-springboot.log"            (contient uniquement les logs provenant de spring-boot)
    Fichier2   : "GestionBancaire-application.log"           (contient uniquement les logs provenant de mon code)
    Répertoire : "${sys:catalina.home}/logs/GestionBancaire" (Le répertoire "${sys:catalina.home}/logs" existe par défaut dans TOMCAT)
    ->(03.)REMARQUE :
    Concernant les logs de compilation :
    • Si tu préconises un autre emplacement, cela m'intéresse.
    • Hors du répertoire de l'application ?
    • Commun à toutes les applications ?
    • N'hésites pas à le préciser.


    Merci pour ton aide.
    En souhaitant bon courage à tous !!!
    chat_roux

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Spring boot: Externaliser un fichier properties
    Par sqlCEDRIC dans le forum Spring Boot
    Réponses: 0
    Dernier message: 08/12/2016, 10h43
  2. Problème avec le fichier de log de la base tempdb
    Par Abac_Angelique dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 01/10/2009, 07h46
  3. problème avec les fichiers logs
    Par kaele dans le forum Administration
    Réponses: 0
    Dernier message: 02/01/2009, 14h29
  4. Problème avec les fichiers log
    Par gosu14 dans le forum Administration
    Réponses: 1
    Dernier message: 04/08/2008, 19h07
  5. [SQL Server 2005] Base avec 2 fichiers LOG
    Par peluche13000 dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 03/04/2008, 09h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo