我无法获得子日志级别来覆盖父日志级别。我在Spring Boot应用程序中具有以下logback配置。
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds" debug="true">
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%p %C{1.} [%t] %m%n</pattern>
</encoder>
</appender>
<!-- LOG everything at DEBUG level -->
<root level="DEBUG">
<appender-ref ref="Console" />
</root>
<Logger name="org.springframework" level="INFO" />
<Logger name="org.springframework.web.servlet.handler" level="DEBUG" />
</configuration>
我希望已经显示了来自org.springframework.web.servlet.handler的所有调试日志。覆盖父级的INFO级别。但是,我看不到来自org.springframework.web.servlet.handler的任何调试日志。
我故意没有在请求中传递必需的标头参数来获取400状态代码。不会显示org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver类中缺少标题的日志。
但是,如果我将org.springframework的日志级别设置为DEBUG,则它可以工作。但我不想这样做,因为它会从其他程序包中引入很多日志,从而在日志文件中产生噪音。
子记录器是否应覆盖父记录器的日志级别?
以下是控制台上的输出,其中org.springframework设置为INFO
11:22:55,433 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
11:22:55,433 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
11:22:55,433 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/D:/Dev/Workspaces/Test/banking-rest-api/target/classes/logback.xml]
11:22:55,533 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/D:/Dev/Workspaces/Test/banking-rest-api/target/classes/logback.xml]
11:22:55,533 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 5 seconds
11:22:55,533 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
11:22:55,540 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [Console]
11:22:55,586 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
11:22:55,586 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [Console] to Logger[ROOT]
11:22:55,586 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to INFO
11:22:55,586 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.web.servlet.handler] to DEBUG
11:22:55,586 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
11:22:55,586 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@60d8c9b7 - Registering current configuration as safe fallback point
11:22:56,036 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/D:/Dev/Workspaces/Test/banking-rest-api/target/classes/logback.xml]
11:22:56,036 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 5 seconds
11:22:56,036 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
11:22:56,036 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [Console]
11:22:56,043 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
11:22:56,043 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [Console] to Logger[ROOT]
11:22:56,044 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to INFO
11:22:56,044 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@26adfd2d - Propagating INFO level on Logger[org.springframework] onto the JUL framework
11:22:56,045 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.web.servlet.handler] to DEBUG
11:22:56,045 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@26adfd2d - Propagating DEBUG level on Logger[org.springframework.web.servlet.handler] onto the JUL framework
11:22:56,045 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
11:22:56,045 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@6f3187b0 - Registering current configuration as safe fallback point
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.0.RELEASE)
INFO org.springframework.boot.StartupInfoLogger [main] Starting BankingSolutionsRestApiApplication on US102994WIN with PID 16176 (D:\Dev\Workspaces\Test\banking-rest-api\target\classes started by Milind.Rao in D:\Dev\Workspaces\Test\banking-rest-api)
DEBUG org.springframework.boot.StartupInfoLogger [main] Running with Spring Boot v2.3.0.RELEASE, Spring v5.2.6.RELEASE
INFO org.springframework.boot.SpringApplication [main] No active profile set, falling back to default profiles: default
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [background-preinit] HV000252: Using org.hibernate.validator.internal.engine.DefaultPropertyNodeNameProvider as property node name provider.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [background-preinit] HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [background-preinit] HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [background-preinit] HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [background-preinit] HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [background-preinit] HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer [main] Tomcat initialized with port(s): 7787 (http)
INFO org.apache.juli.logging.DirectJDKLog [main] Initializing ProtocolHandler ["http-nio-7787"]
INFO org.apache.juli.logging.DirectJDKLog [main] Starting service [Tomcat]
INFO org.apache.juli.logging.DirectJDKLog [main] Starting Servlet engine: [Apache Tomcat/9.0.35]
INFO org.apache.juli.logging.DirectJDKLog [main] Initializing Spring embedded WebApplicationContext
INFO org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext [main] Root WebApplicationContext: initialization completed in 2682 ms
DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator [main] Loaded expression factory via original TCCL
DEBUG org.hibernate.validator.internal.engine.AbstractConfigurationImpl [main] Setting custom MessageInterpolator of type org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator
DEBUG org.hibernate.validator.internal.engine.AbstractConfigurationImpl [main] Setting custom ConstraintValidatorFactory of type org.springframework.validation.beanvalidation.SpringConstraintValidatorFactory
DEBUG org.hibernate.validator.internal.engine.AbstractConfigurationImpl [main] Setting custom ParameterNameProvider of type org.springframework.validation.beanvalidation.LocalValidatorFactoryBean$1
DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser [main] Trying to load META-INF/validation.xml for XML based Validator configuration.
DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper [main] Trying to load META-INF/validation.xml via user class loader
DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper [main] Trying to load META-INF/validation.xml via TCCL
DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper [main] Trying to load META-INF/validation.xml via Hibernate Validator's class loader
DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser [main] No META-INF/validation.xml found. Using annotation based configuration only.
DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers [main] Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [main] HV000252: Using org.hibernate.validator.internal.engine.DefaultPropertyNodeNameProvider as property node name provider.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [main] HV000234: Using org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator as ValidatorFactory-scoped message interpolator.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [main] HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [main] HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [main] HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper [main] HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
INFO org.springframework.scheduling.concurrent.ExecutorConfigurationSupport [main] Initializing ExecutorService 'applicationTaskExecutor'
DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping [main] Patterns [/webjars/**, /**, /**/swagger-ui/**] in 'resourceHandlerMapping'
INFO org.apache.juli.logging.DirectJDKLog [main] Starting ProtocolHandler ["http-nio-7787"]
INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer [main] Tomcat started on port(s): 7787 (http) with context path '/cases'
INFO org.springframework.boot.StartupInfoLogger [main] Started BankingSolutionsRestApiApplication in 5.497 seconds (JVM running for 6.303)
INFO org.apache.juli.logging.DirectJDKLog [http-nio-7787-exec-2] Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO org.springframework.web.servlet.FrameworkServlet [http-nio-7787-exec-2] Initializing Servlet 'dispatcherServlet'
INFO org.springframework.web.servlet.FrameworkServlet [http-nio-7787-exec-2] Completed initialization in 9 ms
如果将org.springframework的日志级别更改为DEBUG,我将获得其他日志
DEBUG org.springframework.core.log.LogFormatUtils [http-nio-7787-exec-5] GET "/cases/lead_ccfraud_100", parameters={}
DEBUG org.springframework.web.servlet.handler.AbstractHandlerMapping [http-nio-7787-exec-5] Mapped to com.banking.solutions.api.controller.BankingController#getCase(String, String, String)
DEBUG org.springframework.web.method.support.InvocableHandlerMethod [http-nio-7787-exec-5] Could not resolve parameter [2] in public org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<com.banking.solutions.api.model.BankingCase>> com.banking.solutions.api.controller.BankingController.getCase(java.lang.String,java.lang.String,java.lang.String): Missing request header 'tenant_id2' for method parameter of type String
DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver [http-nio-7787-exec-5] Using @ExceptionHandler com.banking.solutions.api.exception.handler.RestExceptionHandler#handleException(Exception, WebRequest)
DEBUG org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor [http-nio-7787-exec-5] No match for [*/*], supported: []
DEBUG org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver [http-nio-7787-exec-5] Resolved [org.springframework.web.bind.MissingRequestHeaderException: Missing request header 'tenant_id2' for method parameter of type String]
DEBUG org.springframework.web.servlet.FrameworkServlet [http-nio-7787-exec-5] Completed 400 BAD_REQUEST