这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
当前回答
现有的答案很好。我只是想与您分享一个新的spring引导功能,允许对日志进行分组并在整个组上设置日志级别。
来自文件的例子:
创建日志记录组
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
为组设置日志级别
logging.level.tomcat=TRACE
这是一个很好的功能,它带来了更多的灵活性。
其他回答
记录:官方文档,如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.
您可以尝试将日志级别设置为DEBUG,它将在启动应用程序时显示所有内容
logging.level.root=DEBUG
如果您使用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
在Springboot 2中,你可以像这样用环境变量设置根日志级别:
logging.level.root=DEBUG
或者你可以像这样为包设置特定的日志记录:
logging.level.my.package.name=TRACE
我们也可以像下面这样通过命令行打开DEBUG日志
java -jar <jar file> --debug