Spring boot logging.file.max-size not working - spring-boot

I've following configuration in Spring boot application.properties file. The log is getting generated but not rolling after 1 MB.
logging.level.root=INFO
logging.file=C:/logs/Application.log
logging.file.max-size=1MB
logging.file.max-history=10
logging.pattern.rolling-file-name=Application-%d{yyyy-MM-dd}.%i.log

I test on my local and found rolling file is made at application running directory.
So I think following will work as expected.
logging.file.name=C:/logs/Application.log
logging.pattern.rolling-file-name=C:/logs/Application-%d{yyyy-MM-dd}.%i.log
I tested with spring-boot version 2.4.1

Problem solved after commenting below lines. Earlier I used log4j2 so for that I had to exclude default logging provided by spring-boot. In order to use logback we need to make sure spring-boot-starter-logging is enabled.
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile.exclude module: 'spring-boot-starter-logging'

Related

How to get rid of log4j 1.2.17 jar in springboot

I am using spring boot version 2.1.5.Release, am trying to remove log4j 1.2.17 jar tried exclusion logic.inside spring boot starter dependency it's not worked. Could you please help me to fix the log4j issue. I tried upgrade of Spring boot version still I see dependency in my eclipse under maven dependencies..thanks in advance.
Check that you do not have the logging starter for log4j. If not, then in the dependency hierarchy in eclipse, right-click on log4j and it will let you exclude it from whatever is pulling it in as a transitive dependency.

Basic "Hello World" Spring Boot application in IDEA doesn't work

I can't decide if there is a problem with the instructions in the spring.io tutorial or if there's something wrong with IDEA. Some help would be nice.
I'm following a guide at spring.io to create a simple blog application. I've used the spring initializr to create the application as directed (using Gradle, JDK 1.8, Kotlin) and I cannot run the application from a Spring Boot Run/Debug Configuration. It works only when I run the gradle "bootRun" task, but running through IntelliJ yields a Whitelabel Error Page.
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Additionally, the Spring Boot output in my console shows that the MustacheAutoConfiguration class could not find the /templates/ folder in my classpath.
2019-11-19 13:06:07.136 WARN 11840 --- [ restartedMain] o.s.b.a.m.MustacheAutoConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Mustache configuration, or set spring.mustache.check-template-location=false)
My Spring Boot Run/Debug configuration for BlogApplication has "Use classpath of module: blog.main".
Is there something else I'm missing here?
Did run the application after cloning from the github source. It runs just fine from intellj idea. Tested on JDK 13, 11 and 8
and the configuration for Boot run from intellj idea is bellow.
So I would suggest checking your gradle configuration of intelljidea.
This appears to be a known issue at the moment. See: https://youtrack.jetbrains.com/issue/IDEA-221673

Spring boot devtools does not consider exclude property

I am using Spring Boot with Gradle and added the Devtools plugin. My application is creating files in src/main/resources so I don't want it to be restarted when this is changed. I have tried the following settings in application config file:
spring.devtools.restart.exclude= src/main/resources
spring.devtools.restart.exclude= resources
spring.devtools.restart.exclude= resources/**
spring.devtools.restart.exclude= src/main/resources/**
but none worked.
How can I configure spring boot devtools to ignore files changed in resources folder?

spring-boot - External log4j configuration not working

I am trying to do a setup for production environment, so I wanted to keep log4j.properties out of my application jar file.
For that I have kept my application.properties and log4j.properties files parallel to my spring-boot jar file. And I have given logging.config: file:log4j.properties in my application.properties. This doesn't seem to work. Spring is still picking up the log4j.properties file which is placed inside the jar file.
I have tried giving the absolute path in logging.config property like C:\Users\furquan\project\jars\log4j.properties, but it still the log4j.properties that was being used was the one inside the jar file.
Please help, its important !!!
-Dlogging.config=/path/to/log4j.properties
Or you can specify it in your application.properties or bootstrap.properties.
From 26.5 Custom log configuration
And just a note:
After spring boot 1.4, Log4j 1 support has been removed. So maybe you can consider use the default logback, or use log4j2 instead.

Springboot externalizing log4j configuration

In a springboot application, I have a single jar, and then a subdirectory config with application.properties, applicationContext.xml, and log4j...properties file.
I am trying to externalize the log4j config. The application.properties is externalized this way.
But, when springboot runs it is using the log4j config file from within the jar file. By using the -Dlog4j.debug option I can see that log4j uses my external file first, but when spring starts it overrides the log4j setting with the one in the jar.
here is an example startup (with all options)
java -Dlog4j.debug
-Dlogging.config="file:/opt/config/log4j-qa.properties"
-Dlog4j.configuration="file:/opt/config/log4j-qa.properties"
-jar /opt/myjarName.jar
--spring.config.location=/opt/config/
on first startup log4j states
log4j: Reading configuration from URL file:/opt/config/log4j-qa.properties
then on springboot start
log4j: Reading configuration from URL jar:file:/opt/dms-events-api.jar!/log4j-qa.properties
but I want it to read only the external file file:/opt/config/log4j-qa.properties
resolution:
In our application we had line
#ImportResource("classpath:applicationContext.xml")
which then defined the log4j properties file from the classpath:
the simple solution
1. create a /config directory at the root of the api application and put the properties files there
2. remove the ImportResource line, it isn't needed now
3. add a line to the the application.properties file
logging.config=file:config/log4j-${our environment var}.properties
the explanation
By creating a /config directory at the root of the project then
we can work in eclipse as usual and find our properties files.
--and then to externalize configs
simply add a config directory off of where the application jar is and put properties files there.
Two problems are there:
Configuration for externalise: - Tried and works below one for me in spring boot jar
-Dlog4j.configuration=file:/Users/test/Any-Folder/log4j.properties
Spring logging takes over - for that you need to exclude the logging module. PFB the config for Gradle build.
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}

Resources