这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
当前回答
确保Dave Syer技巧得到一些喜爱,因为向应用程序添加debug=true。属性确实会启用调试日志记录。
其他回答
在Springboot 2中,你可以像这样用环境变量设置根日志级别:
logging.level.root=DEBUG
或者你可以像这样为包设置特定的日志记录:
logging.level.my.package.name=TRACE
如果您使用Spring Boot,那么您可以直接在应用程序中添加以下属性。属性文件设置日志级别, 自定义日志记录模式并将日志存储在外部文件中。
这些是不同的日志级别及其从最小值<<最大值的顺序。
关闭<<致命<<错误<<警告<< info << debug << trace << all
# To set logs level as per your need.
logging.level.org.springframework = debug
logging.level.tech.hardik = trace
# To store logs to external file
# Here use strictly forward "/" slash for both Windows, Linux or any other os, otherwise, its won't work.
logging.file=D:/spring_app_log_file.log
# To customize logging pattern.
logging.pattern.file= "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"
请通过这个链接来更生动地定制您的日志。
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html
设置根日志级别的正确方法是使用logging.level.root属性。参见文档,自最初提出这个问题以来,文档已经更新。
例子:
logging.level.root=WARN
in spring boot project we can write logging.level.root=WARN but here problem is, we have to restart again even we added devtools dependency, in property file if we are modified any value will not autodetectable, for this limitation i came to know the solution i,e we can add actuator in pom.xml and pass the logger level as below shown in postman client in url bar http://localhost:8080/loggers/ROOT or http://localhost:8080/loggers/com.mycompany and in the body you can pass the json format like below
{
"configuredLevel": "WARN"
}
在我当前的配置中,我在应用程序中定义了它。Yaml是这样的:
logging:
level:
ROOT: TRACE
我正在使用spring-boot:2.2.0.RELEASE。您可以像这样定义任何应该具有TRACE级别的包。