You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "schotten (via GitHub)" <gi...@apache.org> on 2023/02/06 13:02:52 UTC

[GitHub] [logging-log4j2] schotten opened a new issue, #1267: Springboot - not replace spring propreties in log4j.xml

schotten opened a new issue, #1267:
URL: https://github.com/apache/logging-log4j2/issues/1267

   ## Description
   
   I use the log4j in the springBoot and i add the artifactId "log4j-spring-boot" for enable the use the springboot properties in the log4j.xml.
   When i use inside the File, it's work very well, but when i try use in the File header, the log4j send the error.
   
   In summary, below i pasted the code, but when i try use the ${spring:log4j.solver.service.path}, the system throw the error (log)
   
   
   ## Configuration
   
   **Version:** 2.19.0
   
   **Operating system:** Windows 10
   
   **JDK:** Java 17 (Adoptium)
   
   application.properties file:
   `log4j.solver.service.name=${LOG4J_SOLVER_SERVICE_NAME:solver-service}
   log4j.solver.service.version=${LOG4J_SOLVER_SERVICE_VERSION:1}
   log4j.solver.service.enviroment=${LOG4J_SOLVER_SERVICE_ENVIROMENT:dev}
   log4j.solver.service.path=${LOG4J_SOLVER_SERVICE_PATH:solver-service.log}`
   
   LOG4J.XML file
   `<?xml version="1.0" encoding="UTF-8"?>
   <Configuration>
       <Appenders>
           <File name="solver-service" fileName="${spring:log4j.solver.service.path}" append="false">
               <EcsLayout serviceName="${spring:log4j.solver.service.name}" serviceVersion="${spring:log4j.solver.service.version}"  serviceEnvironment="${spring:log4j.solver.service.enviroment}"/>
           </File>
           <Console name="STDOUT" target="SYSTEM_OUT">
               <PatternLayout pattern="%level - %m%n"/>
           </Console>
       </Appenders>
       <Loggers>
           <Logger name="propagate-logger" level="INFO" additivity="false">
               <AppenderRef ref="solver-service"/>
           </Logger>
           <Root level="INFO">
               <AppenderRef ref="STDOUT"/>
           </Root>
       </Loggers>
   </Configuration>`
   
   
   
   ## Logs
   `Connected to the target VM, address: '127.0.0.1:52527', transport: 'socket'
   2023-02-06 09:38:15,994 main ERROR FileManager (${spring:log4j.solver.service.path}) java.io.IOException: A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta java.io.IOException: A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta
   	at java.base/java.io.WinNTFileSystem.canonicalize0(Native Method)
   	at java.base/java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:462)
   	at java.base/java.io.File.getCanonicalPath(File.java:626)
   	at java.base/java.io.File.getCanonicalFile(File.java:651)
   	at org.apache.logging.log4j.core.util.FileUtils.makeParentDirs(FileUtils.java:139)
   	at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:436)
   	at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:423)
   	at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:144)
   	at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:100)
   	at org.apache.logging.log4j.core.appender.FileManager.getFileManager(FileManager.java:183)
   [application.properties.txt](https://github.com/apache/logging-log4j2/files/10663203/application.properties.txt)
   
   	at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:99)
   	at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:52)
   	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
   	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
   	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
   	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
   	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
   	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
   	at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:155)
   	at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)
   	at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:89)
   	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
   	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
   	at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:179)
   	at net.weg.solverservice.SolverServiceApplication.main(SolverServiceApplication.java:18)
   
   2023-02-06 09:38:15,997 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.FileAppender for element File: java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory@2b95e48b] unable to create manager for [${spring:log4j.solver.service.path}] with data [org.apache.logging.log4j.core.appender.FileManager$FactoryData@4a3329b9] java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory@2b95e48b] unable to create manager for [${spring:log4j.solver.service.path}] with data [org.apache.logging.log4j.core.appender.FileManager$FactoryData@4a3329b9]
   	at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:146)
   	at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:100)
   	at org.apache.logging.log4j.core.appender.FileManager.getFileManager(FileManager.java:183)
   	at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:99)
   	at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:52)
   	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
   	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
   	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
   	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
   	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
   	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
   	at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:155)
   	at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)
   	at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:89)
   	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
   	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
   	at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:179)
   	at net.weg.solverservice.SolverServiceApplication.main(SolverServiceApplication.java:18)
   
   2023-02-06 09:38:15,998 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.FileAppender for element File: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.FileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.FileAppender
   	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:260)
   	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:136)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
   	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
   	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
   	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
   	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
   	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
   	at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:155)
   	at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)
   	at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:89)
   	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
   	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
   	at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:179)
   	at net.weg.solverservice.SolverServiceApplication.main(SolverServiceApplication.java:18)
   
   2023-02-06 09:38:16,003 main ERROR Null object returned for File in Appenders.
   2023-02-06 09:38:16,008 main ERROR Unable to locate appender "solver-service" for logger config "propagate-logger"
   
     .   ____          _            __ _ _
    /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
   ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
    \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
     '  |____| .__|_| |_|_| |_\__, | / / / /
    =========|_|==============|___/=/_/_/_/
    :: Spring Boot ::                (v2.7.3)
   
   INFO - HV000001: Hibernate Validator 6.2.4.Final
   INFO - Starting SolverServiceApplication using Java 17.0.4.1 on BRJGSD357212 with PID 73264 (C:\Projetos\solver-service\target\classes started by schotten in C:\Projetos\solver-service)
   INFO - The following 1 profile is active: "dev"
   INFO - Multiple Spring Data modules found, entering strict repository configuration mode
   INFO - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
   INFO - Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
   INFO - Tomcat initialized with port(s): 8010 (http)
   INFO - Initializing ProtocolHandler ["http-nio-8010"]
   `
   
   ## Reproduction
   
   Configure the springboot app and use the Log4j.xml and applicatio.proprerties informed in this message and reproduce the error.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [logging-log4j2] ppkarwasz commented on issue #1267: Springboot - not replace spring propreties in log4j.xml

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #1267:
URL: https://github.com/apache/logging-log4j2/issues/1267#issuecomment-1419412636

   @schotten,
   
   Logging in a Spring Boot application is configured at least twice:
   
    * when the `SpringApplication` class is loaded (that is what you see in your stacktrace). This process is described in [automatic configuration](https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration) and does **not** have access to Spring's environment (that didn't start yet),
    * after the `ApplicationEnvironmentPreparedEvent` is fired (cf. [lifecycle of a Spring Boot application](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.spring-application.application-events-and-listeners)). This process is specific to Spring Boot, **has** access to Spring's environment and uses the `log4j2-spring.xml` file (falling back on `log4j2.xml` if such a file does not exist).
   
   If you want to use Spring's enviroment to configure your logging system you have to options:
   
   1. Create two files: `log4j2.xml` and `log4j2-spring.xml`. The first one will be used during the bootstrap phase of your application and can not use Spring's environment. The second one will be used, when your application is up and running.
   2. Stick to a single configuration file and use [arbiters](https://logging.apache.org/log4j/2.x/manual/configuration.html#Arbiters) to provide multiple versions of your "solver-service" appender:
   ```lang-xml
   <Select>
       <SpringProfile name="dev">
           <File name="solver-service" fileName="${spring:log4j.solver.service.path}" append="false">
               <EcsLayout serviceName="${spring:log4j.solver.service.name}" serviceVersion="${spring:log4j.solver.service.version}"  serviceEnvironment="${spring:log4j.solver.service.enviroment}"/>
           </File>
       </SpringProfile>
       <DefaultArbiter>
           <Null name="solver-service"/>
       </DefaultArbiter>
   </Select>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Springboot - not replace spring propreties in log4j.xml (logging-log4j2)

Posted by "SebHeuze (via GitHub)" <gi...@apache.org>.
SebHeuze commented on issue #1267:
URL: https://github.com/apache/logging-log4j2/issues/1267#issuecomment-1659859627

   @ppkarwasz  I have the same problem since I upgraded from 2.17.2 to 2.19 (Spring boot 2.3.9)
   I don't need two log4j files or arbiters to make it work in 2.17.2
   
   But since 2.18 it stopped working because of the new way to load LoggingSystemFactory (spring.factories)
   I still don't understand why spring.factories are not loaded


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Springboot - not replace spring propreties in log4j.xml (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz closed issue #1267: Springboot - not replace spring propreties in log4j.xml
URL: https://github.com/apache/logging-log4j2/issues/1267


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Springboot - not replace spring propreties in log4j.xml (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #1267:
URL: https://github.com/apache/logging-log4j2/issues/1267#issuecomment-1698023896

   I am closing this for lack of activity. I think that:
    * my previous comment solves @schotten's problem,
    * @SebHeuze's problem was discussed in #1652.
    
    Fill free to reopen the issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org