Java spring boot.war tomcat应用程序日志不在那里

Java spring boot.war tomcat应用程序日志不在那里,java,spring-boot,logging,war,Java,Spring Boot,Logging,War,我正试图将我的webapp日志写入tomcat中/logs目录中的.log文件,但该文件未生成,除spring日志和tomcat日志外,任何日志输出也不会发送到控制台。当我将springboot作为一个jar文件运行并嵌入tomcat时,它会很好地写入日志文件,但一旦我通过webapps文件夹部署到tomcat,应用程序日志就找不到了 SpringBoot 2.1.2 Java1.8 Tomcat 8.5 我试过: 在setenv.sh中配置日志记录\u配置 多个伐木工人。。logback、j

我正试图将我的webapp日志写入tomcat中/logs目录中的.log文件,但该文件未生成,除spring日志和tomcat日志外,任何日志输出也不会发送到控制台。当我将springboot作为一个jar文件运行并嵌入tomcat时,它会很好地写入日志文件,但一旦我通过webapps文件夹部署到tomcat,应用程序日志就找不到了

SpringBoot 2.1.2
Java1.8
Tomcat 8.5

我试过:

  • 在setenv.sh中配置日志记录\u配置
  • 多个伐木工人。。logback、javautils等
application.properties:

logging.file=../logs/my-app.log
logging.level.org.springframework=INFO
logging.level.com.bose=DEBUG
log4j.log4j的属性:

log4j.rootLogger=${marge.log.level}, stdout, file

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=marge.log

#when stdout is also specified it will not write to the file

log4j.appender.file.MaxFileSize=1MB
# Keep one backup file
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} [%c] [%-5p] %n%m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# stdout uses PatternLayout
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%c] [%-5p] %n%m%n

# Print only messages of level DEBUG or above in the package com.bose
log4j.logger.com.app=${log.level}
预期:当我在/webapps中部署我的webapp时,应用程序日志(由log4j生成)应该在/logs目录下的my-app.log中


实际:默认情况下,spring boot使用
logback
作为日志绑定器,因此这里的关键概念是先排除
logback
,然后包括
log4j

例如:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
      <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
      </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
 package com.example;

 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 import org.springframework.context.ApplicationContext;

  @SpringBootApplication
  public class Application extends SpringBootServletInitializer {

  private static final Logger LOGGER = LogManager.getLogger(Application.class);

  public static void main(String[] args){
    ApplicationContext ctx = SpringApplication.run(Application.class, args);

    LOGGER.info("Info level log message");
    LOGGER.debug("Debug level log message");
    LOGGER.error("Error level log message");
    }
  }