Merge logging config of Spring boot and Logback - spring

I have a following situation: A spring boot app using logback and several logging properties configured already in application.yml
I would like to add other config options that are only available via logback.xml file but as soon as i add this file to the classpath (does not matter if it is named logback.xml or logback-spring.xml) it overrides everything from application.yml and all logging levels/patterns and other options defined there stop having effects - it seems that after adding logback.xml all options from appication.yml are ignored and i would need to readd them in the xml file instead of yml.
My question is: is it possible to merge these two configs? I mean i only need to add one option to logback.xml and i do not want to force every other developer to learn logback.xml syntax while they are already familiar with application.yml way of configuring logging.
UPDATE1
One of things i am trying to do is to enable logback JMX access, therefore i create a logback-spring.xml file with following contents:
<configuration debug="true">
<jmxConfigurator />
</configuration>
Right after i introduce this file i lose all logging from the webapp even if i have logging.level.root: info in the application.yml file.
I would also like to keep using root logging level and pattern as it is defined in the application.yml. I also want to configure several turboFilters which are specific to logback and, from my knowledge, can only be degined via logback configuration file.
UPDATE 2
Both #devatherock and #Ashish Patil asnwers helped me with the issue, i have been aware of the possibility to include spring configuration elements in logback.xml via springProperty but i have not seen it as a viable solution since i would have to rewrite multiple elements this way making the logback.xml harder to read.
But as #devatherock mentioned - by default the config files ARE merged it is that logback requires the existence of appender and root logger in its configuration. Even when present in the logback.xml file the root logger level will still be overwritten by application.yml setting (which is desired) but the pattern property will not and we have to use springProperty for that.
So while both answers were helpful but actually #devatherock's insignts were more helpful for me i am included to accept his answer.

I created a sample project, spring-boot-logback which specifies logging config in both logback.xml and application.yml
The root log level gets set to WARN in the logback.xml which looks like below:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>
There is a controller method that handles /hello, with a DEBUG and a INFO log line. The log level for the controller class is set to DEBUG in the application.yml file which looks like below:
logging:
level:
io.github.devatherock.demo.controller: DEBUG
I started the application and hit the /hello controller endpoint. Below are the log lines that I saw:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.7)
08:41:45.051 [http-nio-8080-exec-1] DEBUG i.g.d.d.controller.HelloController - Debug log in sayHello method
08:41:45.052 [http-nio-8080-exec-1] INFO i.g.d.d.controller.HelloController - Info log in sayHello method
None of the application startup logs are present because the root log level is set to WARN in the logback.xml. Both the debug and info log lines from the controller are present because the controller log level has been set to DEBUG in the application.yml. Thus we can confirm that logging config from both logback.xml and application.yml are applied without any issues
Update 1:
Looks like if a logback.xml is specified, at a minimum, it needs to have the appender, encoder and the attachment of appender to root log level, for the logging config overrides using spring boot's logging.* properties to work. Once I specified such a logback.xml file with also the jmxConfigurator, I was able to adjust the root and controller log levels in the application.yml. The new logback.xml and application.yml files below:
logback.xml with jmxConfigurator:
<configuration>
<jmxConfigurator />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
application.yml with root log level:
logging:
level:
root: WARN
io.github.devatherock.demo.controller: DEBUG

Use of springProperty might be suitable for your requirement.
Let's say ,you have application.yml like below:
logging:
level:
root: DEBUG
... // other configs
Now you want to enforce configs of application.yml even after having logback.xml, then you can add springProperty in your logback.xml:
<configuration>
<jmxConfigurator />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<springProperty scope="context" name="loggerProperty" source="logging.level.root"/>
<root level="${loggerProperty}">
<appender-ref ref="STDOUT" />
</root>
... //other configurations.
</configuration>
Now, here when you start your spring-boot, you can see application.yml's config value is getting read instead of overriding.
So by this way , you can have as many properties configured in logback & in application.yml.
Basically, you are referring Environment properties (which are defined in your application.properties / application.yml) from your logback.
Here logging.level.root is environment property which is defined application.yml & you referred it in logback.xml by giving it a name as loggerProperty. You are then using this loggerProperty within your logback so that it will get used instead of logback's default one.

Related

Add datetime to log file name

I have some logs that I want to write to a file in a spring-boot microservice.
In my "application.yml" I have the below line which is working fine. But I also want to add date and time to the file name. How do I do that?
logging:
file: logs/${spring.application.name}.log
Ideally, I want the filename to be something like this:
logs/spring-boot-application_YYYY_MM_DD_HH_MM
A similar question has been answered here: How to include date in log file's name with Spring Boot / slf4j?
Basically if you want more control over the logging setup, you should have your own logback.xml under src/main/resources and configure the naming format similar to:
<FileNamePattern>LogFile.%d{yyyy-MM-dd}.log</FileNamePattern>
If you are using spring-boot , you could easily specify it in application.yml or application.properties and configuring logback xml to enable Rolling File Appender as :
spring:
logging:
file: logs/dev_app.log
pattern:
console: "%d %-5level %logger : %msg%n"
file: "%d %-5level [%thread] %logger : %msg%n"
level:
org.springframework.web: DEBUG
guru.springframework.controllers: DEBUG
org.hibernate: DEBUG
and specify the time based rolling policy for the file in :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="ROLLIN" />
</root>
<logger name="org.springframework.web" level="INFO"/>
</configuration>
Doc
Official Spring Doc

How to ignore logback RollingFileAppender FileNotFoundException

I am using logback in my spring boot project, but logback log file must locate in /home/xxx/logs folder.
spring boot cannot start caused by RollingFileAppender's FileNotFoundException exception in my MacOS machine, because of MacOS cannot create folder /home/xxx/logs.
How to ignore this Exception in my spring boot?
As much I know logging framework don't provide any exception handling capability. It's not their job. Either you Correct log location and syntax or just remove config which you don't need.
Include a file logback-spring.xml in your classpath or resources folder and then you will be able to explicitly configure the location of the log file or you may have it print to the console instead. The config below would do just that and override the default config that comes with spring boot.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger{36}.%M - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

IntelliJ: How to set log levels for tests

I have a problem with test console output in IntelliJ 2016.
When I run JUnit tests via IntelliJ, the console window is flooded with enormous amounts of log lines, for example
DEBUG reactor.ipc ....
DEBUG io.netty.buffer.ByteBufUtil ....
It's a simple Spring-Boot application which uses the default logging - I think it's slf4j.
I tried setting
logging.level.reactor.ipc=WARN
in my src/main/resources/application.properties and also setting
-Dlogging.level.root=WARN on the RunConfig's VM arguments, but neither has any effect on the log output.
What is the correct place to configure logging verbosity when executing Tests from Intellij?
You can fill up file named logback.xml in src/test/resources with sample content like:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p | %t | %-55logger{55} | %m %n</pattern>
</encoder>
</appender>
<root>
<level value="TRACE"/>
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
to have TRACE logging level. You can change this log level to meet your needs.

Spring boot logging into mysql database

I have to put all the log data (i.e., debug, info, error) into mysql database instead of to file/console.
I read the spring boot documentation but I didn't see any configuration related to database for logging.
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
Also tried the following link but its also not working.
https://www.tutorialspoint.com/log4j/log4j_logging_database.htm
Can anyone help me to do this.
Thanks.
I read the spring boot documentation but I didn't see any
configuration related to database for logging.
Because spring boot hands off that functionality to logging framework (slf4j + logback/log4j etc). So you need to configure your logging framework accordingly using it's configuration file (eg: logback.xml, logback-spring.xml, logback.groovy etc). Default logging frameworks in Spring boot is slf4j+logback. So checkout how you can use DBAppender.
For Logback
https://logback.qos.ch/manual/appenders.html#DBAppender
http://learningviacode.blogspot.com/2014/01/writing-logs-to-database.html
Log to database with LogBack
https://medium.com/#chakrar27/storing-log-data-in-postgresql-using-logback-db-appender-292891a9918
1. create logback.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="db" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource
class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<driverClass>org.postgresql.Driver</driverClass>
<url>jdbc:postgresql://localhost:5432/simple</url>
<user>postgres</user>
<password>root</password> <!-- no password -->
</connectionSource>
</appender>
<!-- the level of the root level is set to DEBUG by default. -->
<root level="TRACE">
<appender-ref ref="stdout" />
<appender-ref ref="db" />
</root>
</configuration>
2. Create the 3 tables
logging_event
logging_event_property
logging_event_exception
They must exist before DBAppender can be used
For Log4J
https://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender
For Log4J2
http://smasue.github.io/log4j2-spring-database-appender

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?
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.
I faced similar issue and its easy to solve it. Basically , concept is that Spring Boot already gives you System property - LOG_PATH for Spring Boot property - logging.path so you define logging.path in your application.properties and simply use LOG_PATH in your logback configuration - logback-spring.xml.
You shouldn't declare logback <property ...> for LOG_PATH , just use it whenever you want.
See at near bottom here
I encountered the same problem.
put an entry in logback.xml
<property resource="application.properties" />
In application.properties
FILE_LOG_PATTERN=###
LOG_FILE=###
when your application starts,the name of the directory created is what you have defined in the properties file.
Might not be your case but if you have bootstrap.properties make sure logging.path is defined there and only there.
if you're on Spring Boot Finchley (2.x), you can define spring.application.name in your application.properties or application.yml file and add the following in your Logback configuration:
<configuration>
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
</configuration>
you will now have ${springAppName} as a variable at your disposal for your log pattern.
Before Spring Boot enviroment is prepared, the Spring Boot main class or the SpringApplication will initialize the loggerfactory, which will detect the default configuration file (logback.groovy, logback.xml, logback-test.xml), but at this time the Spring Boot application is not started yet, which means the variable LOG_PATH is not set. So at first you should alter the name of your logback config file and configure the file name manually in the Spring Boot config as logging.config. By this way the logback will configure a console appender by default instead of creating a file appender, and then when the Spring Boot enviroment is ready it will fire an enviromentready event, which causes a logback reconfig by LoggingApplicationListener. You can find the issue at springboot's page https://github.com/spring-projects/spring-boot/issues/2558
If you upgrade your Spring Boot version into pom.xml, make sure that your replaced
logging.path = your/log/path
by
logging.file.path = your/log/path
into application.properties. That was my case.
I encountered the same problem. I tried to define my own logback.xml and had trouble using the logging.path and logging.file properties defined in my application.properties file. Here is how I resolved (and worked around) the issues.
First, I learned that you cannot define both logging.path and logging.file properties. Since I'm using a RollingFileAppender that will produce multiple files over multiple days, I define logging.file, but use it more like a file prefix.
In application.properties
# Don't add the file type at the end. This will be added in logback.xml
logging.file=logs/my-app-name
In src/main/resources/logback.xml
<configuration>
<property name="FILE_LOG_PATTERN" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>${FILE_LOG_PATTERN}</Pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<Pattern>${FILE_LOG_PATTERN}</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
This seems to work for the most part. I defined my own FILE_LOG_PATTERN in the file, which I think is optional. The interesting part is the fileNamePattern. It correctly translates logging.file from my application.properties file into the variable LOG_FILE. The only real ugliness here is that on startup Logback still complains about the log file being undefined and creates an empty file called LOG_FILE_IS_UNDEFINED_XXX in the current directory. But the actual log file in my property is created and correctly appended to.
Andrew
somewhere Spring is loading the xml before parsing the yml
so just rename logback.xml to your-logback.xml and add logging.config=classpath:your-logback.xml in your application.properties
Do below to create dev/log directory only. Do not add log.path in application.properties
Add log.path=dev/logs in your bootstrap.properties.
Add below line in your logback-spring.xml.
<springProperty scope="context" name="LOG_PATH" source="log.path"/>
<property name="LOG_FILE" value="${LOG_PATH}/app/current"/>
Note
Make sure you include the below line only.
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
Do not use the below line else console logs will never be disabled and spring.log file will be created in temp directory(if you dont not provide logging.path in application.properties). The check the code of below file to know more.
<include resource="org/springframework/boot/logging/logback/base.xml"/>
put an entry in logback:
<property name="DEV_HOME" value="c:/application_logs/ps-web" />
and reference it:
<fileNamePattern>${DEV_HOME}.%d{yyyy-MM-dd}.log</fileNamePattern>
I had the same problem since I configured logging.path and logging.file on application.properties but some logs was produced before Spring Boot LogBack configuration and so they were written into LOG_PATH_IS_UNDEFINED/LOG_FILE_IS_UNDEFINED file and then the logs switched to the right location.
I found 2 possible solutions:
1) Configure logging.path and logging.file in bootstrap.properties since the configuration in bootstrap take place before
or
2) Set logging.path and logging.file as system properties with -Dlogging.path=... -Dlogging.file=... when launching the application
Based on Spring Boot common properties,
add the following into your application.yml
logging:
file:
path: logs/dev
if using application.properties, it should be
logging.file.path = logs/dev
Declare the property LOG_PATH in your logback.xml
<property name="LOG_PATH" value="" />
is where you must specify the directory where the log files are created. If this field is left empty, logback will create a new directory in the program execution. The name of the directory created is LOG_PATH_IS_UNDEFINED
Try adding the following to your POM file
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/catalina.base_IS_UNDEFINED</directory>
<includes>
<include>**/*.log</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
To call an logback form an external path in a .yml file, it worked for me as:
logging:
config: C:/folder/logback.xml
I suppose you have included an error file.
Please change
<include resource="org/springframework/boot/logging/logback/basic.xml" />
to
<include resource="org/springframework/boot/logging/logback/base.xml"/>
then have a try.
version: 1.5.9
springcloud:
bootstrap.yml
spring:
application:
name: awesome-app
# profile:
# active: dev
logging:
path: /code/awesome-app
spring-logback.xml
${LOG_PATH}/awesome-app.log
springboot:
application.yml
spring:
application:
name: awesome-app
# profile:
# active: dev
logging:
path: /code/awesome-app
spring-logback.xml
${LOG_PATH}/awesome-app.log
custom-log-configuration:https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/#boot-features-custom-log-configuration
I was also having similar issue. I resolved it by renaming logback-spring.xml to logback-whatever.xml and added below in application.properties:
logging.config=classpath:logback-whatever.xml
Also, this issue comes when we use user defined properties for logging purposes such as:
log.path=logs
log.archive.path=archived
What worked for me:
having logback-spring.xml under resources folder (the same as yamls)
setting the environment variable in the application.yaml
after modifications, do a ./gradlew clean build
Happy new year everybody!
So, I've updated my spring boot to version (2.4.1) and I started getting the LOG_PATH_IS_UNDEFINED error.
I did a bit of research and I'm guessing there is a problem with the mapping of the properties from logging.path to LOG_PATH. (I manually debugged the logger and the properties were being load)
My solution/Patch:
I added a manual mapping to the logback-spring.xml at the very top:
<springProperty scope="context" name="LOG_PATH" source="logging.path"/>
Now it is working for me...

Resources