Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot with LogBack creating LOG_PATH_IS_UNDEFINED folder

I am using SpringBoot with LogBack and using the below configuration in my yml file:

logging:     path: C:/var/log/pincode 

The logging.path Spring Environment Variable is transferred to the LOG_PATH Environment variable and the log file is placed at the correct place, but there is also a directory called LOG_PATH_IS_UNDEFINED created in the root directory of my project.

This seems to be caused by the different phase used by SpringBoot to configure LogBack with its Environment variables.

17:29:21,325 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 17:29:21,337 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern LOG_PATH_IS_UNDEFINED/catalina.out.%d{yyyy-MM-dd} for the active file 17:29:21,340 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'LOG_PATH_IS_UNDEFINED/catalina.out.%d{yyyy-MM-dd}'. 17:29:21,340 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 17:29:21,343 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Mon Aug 11 17:24:07 BRT 2014 17:29:21,346 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - Active log file name: LOG_PATH_IS_UNDEFINED/catalina.out 17:29:21,346 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - File property is set to [LOG_PATH_IS_UNDEFINED/catalina.out] ... 17:29:21,358 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 

And then after that it start configuring logback again but this time using the path i set:

17:29:21,672 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 17:29:21,673 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used 17:29:21,673 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern C:/var/log/pincode//catalina.out.%d{yyyy-MM-dd} for the active file 17:29:21,674 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'C:/var/log/pincode//catalina.out.%d{yyyy-MM-dd}'. 17:29:21,674 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 17:29:21,674 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Mon Aug 11 17:29:21 BRT 2014 17:29:21,674 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - Active log file name: C:/var/log/pincode//catalina.out 17:29:21,674 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - File property is set to [C:/var/log/pincode//catalina.out] ... 17:29:21,685 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 

My logback.xml

<?xml version="1.0" encoding="UTF-8"?> <configuration debug="true"> <include resource="org/springframework/boot/logging/logback/basic.xml" /> <property name="FILE_LOG_PATTERN"     value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%t] --- %-40.40logger{39} : %m%n%wex" />  <appender name="serverConsole"           class="ch.qos.logback.core.rolling.RollingFileAppender">     <Append>true</Append>     <File>${LOG_PATH}/catalina.out</File>     <encoder>         <pattern>${FILE_LOG_PATTERN}</pattern>     </encoder>     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">         <fileNamePattern>${LOG_PATH}/catalina.out.%d{yyyy-MM-dd}         </fileNamePattern>         <maxHistory>15</maxHistory>     </rollingPolicy> </appender>  <!-- Plain Text Rolling Appender --> <appender name="server"     class="ch.qos.logback.core.rolling.RollingFileAppender">     <Append>true</Append>     <File>${LOG_PATH}/pincode.log</File>     <filter class="ch.qos.logback.classic.filter.LevelFilter">         <level>INFO</level>         <onMatch>ACCEPT</onMatch>         <onMismatch>DENY</onMismatch>     </filter>     <encoder>         <pattern>${FILE_LOG_PATTERN}</pattern>     </encoder>     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">         <fileNamePattern>${LOG_PATH}/pincode.log.%d{yyyy-MM-dd}         </fileNamePattern>         <maxHistory>15</maxHistory>     </rollingPolicy> </appender>  <!-- Plain Text Rolling Appender --> <appender name="server-error"     class="ch.qos.logback.core.rolling.RollingFileAppender">     <Append>true</Append>     <File>${LOG_PATH}/pincode-error.log</File>     <filter class="ch.qos.logback.classic.filter.LevelFilter">         <level>ERROR</level>         <onMatch>ACCEPT</onMatch>         <onMismatch>DENY</onMismatch>     </filter>     <encoder>         <pattern>${FILE_LOG_PATTERN}</pattern>     </encoder>     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">         <fileNamePattern>${LOG_PATH}/pincode-error.log.%d{yyyy-MM-dd}         </fileNamePattern>         <maxHistory>15</maxHistory>     </rollingPolicy> </appender>  <logger name="com.app" level="INFO">     <appender-ref ref="server" />     <appender-ref ref="server-error" /> </logger>  <root level="INFO">     <appender-ref ref="serverConsole" /> </root>  

If I remove my logback.xml file from the project it doesn't create the folder, so somewhere Spring is loading the xml before parsing the yml?

How can I avoid Logback to create this LOG_PATH_IS_UNDEFINED directory?

like image 358
Davi Alves Avatar asked Aug 11 '14 20:08

Davi Alves


People also ask

Where does Logback xml go in spring boot?

In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.

Does spring boot support Logback?

Spring Boot provides a number of logback configurations that be included from your own configuration.

How do you use properties in Logback xml?

xml , you can use <springProperty> to access properties from Spring's environment including those configured in application. properties . This is described in the documentation: The tag allows you to surface properties from the Spring Environment for use within Logback.


1 Answers

In your case LOG_PATH is not defined on startup. You should use ${LOG_PATH:-.} instead , See .

But if you define logging.path in your application.properties you will see two log files in . and in ${logging.path} directory.

Spring container set LOG_PATH after Logback initialization... Logback is not supported lazy file creation as far as I know. In this case you should use logback-spring.xml instead logback.xml.

like image 106
Igor Tytar Avatar answered Sep 19 '22 23:09

Igor Tytar