My logback-spring.xml reads fine from application.properties but not from application.yml. In my project, we have been asked to only use the YAML format as this format is being used in other microservices within the same project, so I cannot add propertes file. please help me why my application.yml is not read in logback.xml
I have tried variety of ways and searched similar questions on stackoverflow but no question has correct answer**. please dont mark this as duplicate**.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<property resource ="application.yml"/>
<property name="LOGS" value="./logs" />
<appender name="Console"
>
<layout >
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="RollingFile"
>
<file>${LOGS}/${spring.application.name}.log</file>
<encoder
>
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
>
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
>
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<!-- LOG "com.baeldung*" at TRACE level -->
<logger name="com.ms" level="trace" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
</configuration>
Above is my logback-spring.xml. Please refer my application.yml below:-
spring:
application:
name: Logbacking-service
CodePudding user response:
You can use below in your logback file as explained in the docs
If you enable trace logging level in your logback for "org.springframework.core.env.PropertySourcesPropertyResolver
" you will see the location of application.yml from where it reads the properties. This will help you understand from where the spring boot is trying to find configuration. Something like below
Searching for key 'spring.profiles.active' in PropertySource 'applicationConfig: [classpath:/application.yml]