How to set the logging level of embedded tomcat in Spring Boot? - spring

How to set the logging level of embedded tomcat in Spring Boot?
Especially I need to see the tomcat clustering-related logs.
I added the following line to the application.properties, but tomcat seems to log only INFO level logs.
logging.level.org.apache.catalina=TRACE
Is there a simple method to accomplish this?
It would be best to know the Spring Boot and embedded tomcat-specific, simple solution, preferably only editing application.properties.

In short, use Spring Boot version 1.3.0 with Logback. (I was using Spring Boot 1.2.4)
Spring Boot 1.3.0 adds LevelChangePropagator to LogbackLoggingSystem.java (see this commit), thus the logging level that is set in application.properties is propagated to the jul(java.util.logging) which tomcat uses.
Otherwise, one must set the logging level for the logger in the logging.properties for the jul if the level is below the INFO level which is the default, AND also set the logging level for the logger in the application.properties. This is for the limitation of jul-to-slf4j module which cannot completely override jul implementation since jul is in the java.* package.
Also see the following Spring Boot issues: Optimize JUL logging #2585, Slf4JLoggingSystem should also configure JUL levels #2923.
And this is the related StackOverflow question: Spring Boot - set logging level of external jar which is using Java Util Logging (jul). Actually this is the problem I was facing.
(I will accept this answer if no better answer is posted for a few days from now.)

Related

StreamsBuilderFactoryBeanCustomizer vs StreamsBuilderFactoryBeanConfigurer

StreamsBuilderFactoryBeanCustomizer and StreamsBuilderFactoryBeanConfigurer are both used to customize the StreamsBuilderFactoryBean. These 2 interfaces seem redundant and one of the two should certainly be deprecated before being abandoned.
This works well when using the default Spring configuration but it can become a pain when custom StreamsBuilderFactoryBean(s) need(s) to be created.
Any specific reason/constraint explaining the need of these 2 interfaces?
Any feedback is more than welcome.
StreamsBuilderFactoryBeanConfigurer is provided by Spring for Apache Kafka.
The customizer is a Spring Boot class.
Not all users use Spring Boot although, admittedly, most do. Furthermore, the ...Configurer extends Ordered so you can control the order in which multiple configurers are invoked.
It used to be worse - they were both called ...Customizer until Spring for Apache Kafka version 2.6.7.
https://github.com/spring-projects/spring-kafka/issues/1736
They were added to their respective projects:
Spring for Apache Kafka: Feb 28 2019 https://github.com/spring-projects/spring-kafka/commit/9e86163647217dd9cefb5e35c974eb476cefc150
Spring Boot: Jul 1, 2020: https://github.com/spring-projects/spring-boot/commit/54e0a61b425d00ceb220b82dc8abbad121245c10
So, it appears that Boot added its own customizer unnecessarily.
You could try opening an issue against Boot to see if they are prepared to deprecate theirs (since ours predates it), but we can't remove it from Spring for Apache Kafka for reasons stated.

Spring Boot Logging to Database using Logback (Spring Boot 2.3.7)

I am trying to create DB logging appender, ch.qos.logback.classic.db.DBAppender this one to be exact. But from what I read, the DB Appender functionality was dropped from Logback some time ago, with no guarantee when it will be back.
https://jira.qos.ch/browse/LOGBACK-1609
Now from what I read, there was a vulnerability in there. But not sure what, because I wasn't able to find any info on it?
Now from what I understand, the newer Spring Boot versions come with Logback 1.2.11, and DBAppender was supported till 1.2.8 i believe.
So my question is:
Is it safe to exclude the logback that comes with Spring Boot and use the older Logback without causing a risk?
Is switching to log4j the best option? That has had its own issues with security this year!

How -Dlogging.level JVM argument is handled in spring boot, spring cloud

I have a spring cloud application, which under the covers uses spring boot.
In the bootstrap phase of the app I am using some classes from the apache commons config library under: org.apache.commons.configuration
My application is started with this flag per the spring docs:
-Dlogging.level.org.apache.commons.configuration=INFO
Despite this, i am still getting DEBUG level logs emitted during the bootstrap phase of spring....
I am lost as to how to properly specify the log level of INFO specified for the bootstrap phase of spring boot.
Ensure you are not setting debug=true in application properties or not passing --debug flag to the application.
In application.properties set:
debug=false
The configuration of spring boot has a specific order, so probably somewhere in the application or bootstrap configuration files the logging level is configured to DEBUG.
Source:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

Spring Boot - logging configuration from JBoss

I'd like to know if there is a way to configure Spring Boot logging using JBoss standalone.xml or domain.xml configuration. For now I ended up with two empty files log4j.properties and log4j-file.properties under org\springframework\boot\logging\log4j package in mvn resources in WAR file and it looks like now my logging configuration in domain.xml works because I've overriden default spring-boot log4j configuration.
But there must be a better way to do this instead of this stupid hack. Keep in mind that I don't want to provide external log4j properties file and set it for one of the property in application.properties but I want to use jboss logging system configuration.
EDIT
Strange thing but when I updated Spring Boot to version 1.4.0 then JBoss intercepts the logs and log them only to the file and I don't have logs on the stdout anymore even without custom log4j configuration.

Default Spring Boot log4j2 log pattern

Spring boot ships with several default logging framework configurations including Log4j2. While there is detailed documentation about logging in the Spring boot reference manual it does not mention how and where exactly the default log pattern is configured, which makes it difficult to override this.
The question is where does Spring Boot configure the default log pattern of for Log4j2?
So far I have looked in the following places of Spring Boot:
AutoConfigurationReportLoggingInitializer
LoggingApplicationListener
SimpleFormatter
LoggingSystem
Log4J2LoggingSystem
It seems the Log4J2 configuration is not done in any Java class so I was looking at the wrong place. Spring Boot ships with two files log4j2.xml and log4j2-file.xml which contain the default configuration and can be found in org.springframework.boot.logging.log4j2.

Resources