这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
当前回答
确保Dave Syer技巧得到一些喜爱,因为向应用程序添加debug=true。属性确实会启用调试日志记录。
其他回答
根据文档,您可以根据java包拥有不同的日志级别。
logging.level.com.mypackage.myproject=WARN
logging.level.org.springframework=DEBUG
logging.level.root=INFO
这就意味着
对于您的自定义包com.mypackage.myproject将应用WARN日志级别 对于spring框架包org。将应用springframework DEBUG日志级别 对于每个其他包,将应用INFO日志级别
您还可以将不同的java包分组在一起,并指示系统在一行中对该组的所有包使用相同的日志级别。
在前面的例子中你可以这样做
logging.level.root=INFO
logging.level.org.springframework=DEBUG
logging.group.myCustomGroup = com.mypackage.myproject, com.otherpackage.otherproject, com.newpackage.newproject
logging.level.myCustomGroup=WARN
这就意味着包裹
com.mypackage.myproject com.otherpackage.otherproject com.newpackage.newproject
是否所有日志级别都应用了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"
}
假设应用程序的包名为com.company.myproject。然后,您可以在应用程序中为项目中的类设置日志级别,如下所示。属性文件
loging.level.com.company.myproject = DEBUG
loging.level.org.springframework.web = DEBUG和loging.level.org.hibernate = DEBUG将仅为Spring框架web和Hibernate的类设置日志级别。
用于设置日志文件位置使用
伐木。文件= /home/ubuntu/myproject
记录:官方文档,如Spring Boot v1.2.0。RELEASE和Spring v4.1.3 RELEASE:
If the only change you need to make to logging is to set the levels of various loggers then you can do that in application.properties using the "logging.level" prefix, e.g. logging.level.org.springframework.web: DEBUG logging.level.org.hibernate: ERROR You can also set the location of a file to log to (in addition to the console) using "logging.file". To configure the more fine-grained settings of a logging system you need to use the native configuration format supported by the LoggingSystem in question. By default Spring Boot picks up the native configuration from its default location for the system (e.g. classpath:logback.xml for Logback), but you can set the location of the config file using the "logging.config" property.
现有的答案很好。我只是想与您分享一个新的spring引导功能,允许对日志进行分组并在整个组上设置日志级别。
来自文件的例子:
创建日志记录组
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
为组设置日志级别
logging.level.tomcat=TRACE
这是一个很好的功能,它带来了更多的灵活性。