java - 春季登录
问题描述
我有一个 spring boot 应用程序,它启动后我们通常会看到以下输出到控制台
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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
ETC...
我需要得到这个日志输出:
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
我该怎么做?
谢谢!
解决方案
我想你可以在属性中使用 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>
推荐阅读
- php - 使用 Symfony 5/Twig“数组到字符串转换”的嵌套数组问题
- java - 我得到一个变量值为零,即使它在java中分配了一些值
- angular - SASS 样式未完全加载
- node.js - 将信息从数据库返回到服务器 - 异步/回调函数语法?
- python - 从invest.com 上抓取历史经济数据
- python - macOS 上的 Python“DPI-1047 无法找到 dlopen(libclntsh.dylib)”
- python - 在 python 中跨实例缓存大型数据结构,同时维护类型
- c++ - 由 NmGetFieldName(网络监视器 API)引起的 STATUS_ACCESS_VIOLATION
- javascript - 从 GEE 中的 shp 提取索引值时出错
- java - JVM 在序列化期间挂起