Spring Boot Logback不记录我的应用程序日志

时间:2018-12-10 22:10:19

标签: spring-boot logback spring-logback

需要帮助...我在这里做错了什么??? 我相信它确实从application.properties文件读取了路径和文件名。但我认为它不会读取logback.xml或logback-spring.xml

我做了一些研究,发现了很多问题/答案。但是我认为每个人都说要在资源中放置回退xml,并在application.properties中提供路径和文件名。我知道这很简单,但是在某处缺少了东西...

提前谢谢!

application.properties

# ===============================
# LOGGING
# ===============================
# log configuration -- update config location as needed
#logging.config=/logback-spring.xml
#logging.file=/logs/iqs-service.txt
logging.path=/logs
logging.file=${logging.path}/log.log
logging.pattern.file=%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n

enter image description here

enter image description here

日志文件的内容( log.log.0 ):

[2018-12-10 15:54:41.999] - 10828 INFO [main] --- org.apache.catalina.core.StandardService: Starting service Tomcat
[2018-12-10 15:54:42.002] - 10828 INFO [main] --- org.apache.catalina.core.StandardEngine: Starting Servlet Engine: Apache Tomcat/8.5.14
[2018-12-10 15:54:42.257] - 10828 INFO [localhost-startStop-1] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]: Initializing Spring embedded WebApplicationContext
[2018-12-10 15:54:46.551] - 10828 INFO [http-nio-19917-exec-1] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]: Initializing Spring FrameworkServlet 'dispatcherServlet

我的java方法中的日志语句-永远不会在日志中打印

log.info("init(): [" + modelId + "]");
log.error("init(): [" + modelId + "]");

enter image description here

1 个答案:

答案 0 :(得分:0)

据我所知,我认为唯一会杀死它的是以下几行:

logging.path=/logs
logging.file=${logging.path}/log.log

我相信,如果同时包含两者,则Spring Boot将忽略它们。因此,我尝试删除其中之一,看看是否有帮助。

作为另一件事(但我认为这不会导致此问题),Spring建议您仅拥有一个logback-spring.xml文件,而不要拥有logback.xml(而且绝对不能同时存在)。