i'm using spring boot embedded tomcat with spring boot 1.5.9 , im also using Log4j2.
recently i exerience problems during load, so i want to understand better the tomcat logs [Not the access Logs] , i tried (in application.properties) :
logging.level.org.apache.tomcat: INFO
logging.level.org.apache.catalina: INFO
but none of the above worked. is there any other way to achieve it ?
Default configurations are provided for Java Util Logging, Log4J, Log4J2 and Logback. In each case loggers are pre-configured to use console output with optional file output also available
refer this link : https://stackoverflow.com/questions/31939849/spring-boot-default-log-location/31939886
The embedded tomcat in spring boot internally echoes logs to console. The default log configuration will echo messages to the console as they are written. So until you explicitly specify a file as you described, it stays in the Console.
From the spring boot logging doc.
You can custmize the logging as per your need.
A log file, generated by
org.apache.catalina.valves.AccessLogValve
, usually named something likelocalhost_access_log
can be configured like this:I struggled a lot,and didnt find anything of my help.Utlimately I had build "WAR" out of my spring boot application.Deploy it to tomcat instance and followed below steps,which redirected all the internal tomcat logs(JULI) logs to my application log file.
Delete existing JULI library (CATALINA_HOME/bin/tomcat-juli.jar file) and the existing Tomcat Java Logging configuration file (CATALINA_HOME/conf/logging.properties).
Download JULI Log4j Tomcat library (tomcat-juli.jar) from the Tomcat downloads’ Extras section (http://tomcat.apache.org/download-70.cgi). Place the downloaded file to CATALINA_HOME/bin directory.
Download Tomcat JULI adapters library (tomcat-juli-adapters.jar) from the Tomcat downloads’ Extras section. Place this file in the CATALINA_HOME/lib directory.
Download Log4j (version 1.2 or later), and place the downloaded library file to CATALINA_HOME/lib directory.
Create the Log4j configuration file at the following location: CATALINA_HOME/lib/log4j.properties. Check below log4j configuration matching the default Java Logging configuration.
Restart Tomcat.
Log4j configuration File Matching the Default Tomcat Logging Settings:
You can also check a adapter avaiable on GIT @ link
In your spring boot application,you can make changes like adding and removing jars,folder from embedded Tomcat server Or even adding custom config files to it using TomcatEmbeddedServletContainerFactory.class ,of spring boot.
The package for the embeded tomcat is
org.springframework.boot.context.embedded.tomcat
So adding this to your application.properties fileFor slf4j and Spring Boot 2 hide exceptions from Tomcat and handle them by yourself:
Add to pom:
Add to config:
Add to
application.yaml
Handle exception in
ErrorController
Please refer to this url which contains common application properties which also includes application logging properties and tomcat level logging properties. Whether you use yaml or properties file, spring boot uses this configuration to bootstrap the application. Search for below configuration items.