Spring 登录

uinbv5nw  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(284)

我有一个spring引导应用程序,在它启动之后,我们通常会看到控制台的以下输出

/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.0)
1283 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path

等。。。
我需要得到这个日志输出:

1283 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path

并使用slf4j将其放入文件
我有一个设置为slf4j的application.properties

logging.level.root=INFO
logging.level.org.spring.upskill = INFO
logging.level.org.springframework.web = INFO
logging.file.name = app.log

但我没有得到文件的完整输出。只响应我的getmappings
例如

[2020-12-10 14:31:53.381] - 19960 INFO [main] --- org.apache.catalina.core.StandardService: Starting service [Tomcat]
[2020-12-10 14:31:53.385] - 19960 INFO [main] --- org.apache.catalina.core.StandardEngine: Starting Servlet engine: [Apache Tomcat/9.0.39]
[2020-12-10 14:31:53.432] - 19960 INFO [main] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]: Initializing Spring embedded WebApplicationContext

我该怎么做?
谢谢您!

7ajki6be

7ajki6be1#

我假设您可以在properties中使用appender.rolling.policies.startup.type=onstartuptriggeringpolicy,或者更新log4j2.xml以包含以下内部appenders-->rollingrandomaccessfile

<Policies>
        <!-- Starts a new log on tomcat start -->
        <OnStartupTriggeringPolicy />
        <!-- Starts a new file when size reaches threshold -->
        <SizeBasedTriggeringPolicy size="100 MB" />
        <!-- causes a rollover once the date/time pattern no longer applies to 
            the active file
        <TimeBasedTriggeringPolicy /> -->
    </Policies>

相关问题