简体   繁体   English

配置Spring Boot Logback

[英]Configuring Spring Boot Logback

I am trying to write the application.yml file with the logging configurations for spring boot. 我正在尝试使用spring boot的日志记录配置来编写application.yml文件。 Thanks to Bal from my previous question I was able to take a look at the sample file on spring boot's website. 感谢上一个问题中的Bal,我得以查看Spring Boot网站上的示例文件 Since I only want to configure the logging information for now here is what my yml file looks like right now: 由于我现在只想配置日志记录信息,因此这是我的yml文件现在的样子:

# ===================================================================
# SPRING BOOT PROPERTIES
# ===================================================================


# LOGGING
logging:
  config: /logback.xml # Location of the logging configuration file. For instance `classpath:logback.xml` for Logback
  logging.level.org.springFramework=DEBUG # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG`
  path: # Location of the log file. For instance `/var/log`
  pattern:
    console: # Appender pattern for output to the console. Only supported with the default logback setup.
    file: # Appender pattern for output to the file. Only supported with the default logback setup.
    level: # Appender pattern for log level (default %5p). Only supported with the default logback setup.

But I have a few questions: 但是我有几个问题:

  1. How much logging configuration should I do here in the yml file versus the logback.xml file? 我应该在yml文件和logback.xml文件中进行多少日志记录配置? Should any logging configuration be put here at all versus putting it all in logback.xml ? 是否应该将所有日志记录配置都放到这里,而不是全部放到logback.xml
  2. Is the logging level configuration line written correctly? 日志记录级别配置行是否正确编写?
  3. Can I use another library's logging level, like logback? 我可以使用其他库的日志记录级别,例如logback吗? For example, could I put this: ch.qos.logback.classic.Level=DEBUG 例如,我可以这样: ch.qos.logback.classic.Level=DEBUG
  1. I would not combine logback.xml with application.yml . 我不会将logback.xmlapplication.yml结合在一起。 Use either simplified configuration via application.yml if it is enough for you or use "fullfeatured" logback.xml . 如果足够,请通过application.yml使用简化的配置,或者使用“ logback.xmllogback.xml

To be honest I am not sure what will happen when you will have contradicting configuration in those two files (eg different patterns or log levels). 老实说,我不确定当这两个文件中的配置矛盾时(例如,不同的模式或日志级别)会发生什么。

2 + 3. My guess is you have extra logging part. 2 +3。我猜是您还有额外的logging部分。 Correct example would be eg 正确的例子是

logging:
  level:
    ch.qos.logback.classic: DEBUG
    org.hibernate: INFO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM