Spring Boot external WAR run in Apache Tomcat has no log

Viewed 9009

I have configured Spring Boot to work with tomcat as in the guide: https://www.baeldung.com/spring-boot-war-tomcat-deploy . When I run the application from my IDE I can see everything on the console, but on tomcat the logs don't show anything, I also configured this:

logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

and no luck any idea ?

my application.properites

# ===============================
# = DATA SOURCE
# ===============================
spring.datasource.url = jdbc:mysql://...
spring.datasource.username = root
spring.datasource.password = admin

# ===============================
# = JPA / HIBERNATE
# ===============================
spring.jpa.show-sql = true
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

# ==============================================================
# = Spring Security / Queries for AuthenticationManagerBuilder
# ==============================================================
spring.queries.users-query=select email, password, active from user where email=?
spring.queries.roles-query=select u.email, r.role from user u inner join user_role ur on(u.id=ur.user_id) inner join role r on(ur.role_id=r.id) where u.email=?

logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
5 Answers

I encountered same problem, so I thought my answer will be helpful if someone has same case.

When we created the springboot app, we forgot to extend SpringBootServletInitializer in our main class. Without this, servlet context binding between your app and tomcat container does not happen. That is why, though the war is exploded, app is not actually deployed, hence no application logs. find more details here https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/servlet/support/SpringBootServletInitializer.html

@EnableSwagger2
@SpringBootApplication
@EnableJpaRepositories("com.scn.scheduler.dal")
@EnableScheduling
public class SCNSchedulerApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(SCNSchedulerApplication.class, args);
    }
}

Add the following in your Spring Boot's application.properties

logging.file=../logs/mylog.log

The answer to use the following in application properties is correct :

logging.file=../logs/mylog.log

but it's not mentioning why no messages printed to catalina.log . the complete answer is from spring boot documentation :

By default, Spring Boot logs only to the console and does not write log files. If you want to write log files in addition to the console output, you need to set a logging.file or logging.path property (for example, in your application.properties).

by adding below property in application.properties worked for me

logging.file.name = ${catalina.base}/logs/${service.name}.log

When You run file spring boot war from IDE and You want to show log console on IDE. You must to edit file pom.xml:

First. You have to exclusion spring-boot-starter-logging

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            **<exclusion>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>**
        </exclusions>
    </dependency>

Second. You add dependency logback-classic and jcl-over-slf4j

   <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </dependency>   

I made it and I saw log on IDE console.

Related