I am using spring boot project.
Environment:
ch.qos.logback:logback-core:jar:1.1.5 ch.qos.logback:logback-classic:jar:1.1.5 org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE
In my project, I use properties with application.yml (application-dev.yml and application-production.yml)
Since the Logback spring extension starts before spring, I cannot insert the spring.profiles.active file into the logback.xml file.
This is a simpler version of my logback.xml file:
<configuration scan="true"> <property name="LOG_PATH" value="/var/log/" /> <property name="APP_NAME" value="xyz" /> <property name="PROFILE" value="-${spring.profiles.active}" /> <property name="CHARSET" value="utf-8" /> <property name="PATTERN" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" /> <appender name="APP-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${LOG_PATH}${APP_NAME}${PROFILE}.log</file> <encoder> <charset>${CHARSET}</charset> <Pattern>${PATTERN}</Pattern> </encoder> </appender> <logger name="abc" level="INFO"> <appender-ref ref="APP-FILE" /> </logger> <root level="INFO"> <appender-ref ref="APP-FILE"/> </root>
The PROFILE I'm looking for is the spring.profiles.active property.
My goal is to have a log file in the / var / log directory of the xyz-dev or xyz-production files, but I get xyz- spring.profiles.active_IS_UNDEFINED.log .
Approaches:
1 - Use of a component such as:
@Component public class InitializationService implements ApplicationListener<ContextRefreshedEvent> {
doesn't work, of course, because the logback spring extension starts before the spring boot application.
2 - Using a property on logback.xml like this
<file>${LOG_PATH}${APP_NAME}${PROFILE}.log</file>
The result is xyz- spring.profiles.active_IS_UNDEFINED.log