这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)

如何使用application.properties设置日志级别? 日志文件的位置,等等?


当前回答

现有的答案很好。我只是想与您分享一个新的spring引导功能,允许对日志进行分组并在整个组上设置日志级别。

来自文件的例子:

创建日志记录组

logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat

为组设置日志级别

logging.level.tomcat=TRACE

这是一个很好的功能,它带来了更多的灵活性。

其他回答

在Springboot 2中,你可以像这样用环境变量设置根日志级别:

logging.level.root=DEBUG

或者你可以像这样为包设置特定的日志记录:

logging.level.my.package.name=TRACE

我们也可以像下面这样通过命令行打开DEBUG日志

java -jar <jar file> --debug

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"
}
logging:
  level:
    root: INFO
    com.mycompany.myapp: DEBUG

您可以尝试将日志级别设置为DEBUG,它将在启动应用程序时显示所有内容

logging.level.root=DEBUG