简体   繁体   中英

Spring Boot and Logging with External Tomcat

I am deploying my Spring Boot Application on an external Tomcat Server. I can't seem to make my eclipse console display the log messages that I write in my code:

private static final Logger log = LoggerFactory.getLogger(PersonServiceImpl.class);
...
log.info("Running...");

I managed to log all hibernate trace but still can't show the log messages I am adding to my code:

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
logging.level.root=INFO
logging.level.org.springframework.web=INFO

And the catalina log folder doesn't contain the logged infos I am needing.

What should I do?

I think, you deploy your spring boot application in an external tomcat, you package it as war file.

You can check this configuration :

In your pom.xml

<!-- mark the embedded tomcat server as provided -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

and in the packaging value :

<packaging>war</packaging>

In the dependencies, if you use the Web starter :

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

it's depends transitively on the logging starter, that means we can only add the starter web dependecy, no more logging component to provide.

And In the application.properties file, add the following lines :

logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO

After that, using maven, you can type :

mvn clean package

And move it to your external tomcat :

cp target/project.war apache-tomcat-8.X.X/webapps/project.war
./apache-tomcat-8.X.X/bin/startup.sh

Please configure your application.properties or application.yml file

application.properties

#Logging pattern for file.
logging.pattern.file= "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"

#output to a file 
logging.file=/path_to_file/file_name.log

#Logging pattern for console and output.
logging.pattern.console= "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM