Logback不显示堆栈跟踪

时间:2015-01-03 11:31:25

标签: java spring jetty spring-boot logback

我正在使用Spring Boot 1.2.0,我在控制台中看不到异常堆栈跟踪。

记录其他所有内容,SQL,事务启动和回滚(发生异常时)但我没有看到它们。有没有人有想法?

资源文件夹中的logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" scan="true">
<jmxConfigurator/>

<include resource="org/springframework/boot/logging/logback/base.xml"/>

<logger name="org.apt.crm" level="DEBUG"/>
<logger name="org.springframework" level="ERROR"/>
<logger name="org.hibernate" level="ERROR"/>
<logger name="org.springframework.orm.jpa" level="ERROR"/>
<logger name="org.springframework.transaction" level="DEBUG"/>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<root level="INFO">
    <appender-ref ref="STDOUT"/>
</root>

</configuration>

Gradle依赖

dependencies {
// Core
// ====
// Spring Boot
compile("org.springframework.boot:spring-boot-starter-web") {
    exclude module: 'spring-boot-starter-tomcat'
    exclude module: 'commons-logging'
}
if (!buildWar)
{
    compile "org.springframework.boot:spring-boot-starter-jetty"
}
compile "org.springframework.boot:spring-boot-starter-security"
compile "org.springframework.boot:spring-boot-starter-aop"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
// Needed for thymeleaf HTML5LEGACY mode
compile "net.sourceforge.nekohtml:nekohtml:$nekoHtmlVersion"
compile("org.springframework.boot:spring-boot-starter-actuator") { exclude module: 'hsqldb' }
// Bean Validation
compile "org.hibernate:hibernate-validator:$hibernateValidatorVersion"
// Jetty Server
compile "org.eclipse.jetty:jetty-servlets:$jettyVersion"
if (!buildWar)
{
    compile "org.eclipse.jetty:jetty-client:$jettyVersion"
    compile "org.eclipse.jetty:jetty-continuation:$jettyVersion"
    compile "org.eclipse.jetty:jetty-http:$jettyVersion"
    compile "org.eclipse.jetty:jetty-io:$jettyVersion"
    compile "org.eclipse.jetty:jetty-jsp:$jettyVersion"
    compile "org.eclipse.jetty:jetty-security:$jettyVersion"
    compile "org.eclipse.jetty:jetty-server:$jettyVersion"
    compile "org.eclipse.jetty:jetty-servlet:$jettyVersion"
    compile "org.eclipse.jetty:jetty-util:$jettyVersion"
    compile "org.eclipse.jetty:jetty-webapp:$jettyVersion"
    compile "org.eclipse.jetty:jetty-xml:$jettyVersion"
    // Servlet API
    compile "javax.servlet:javax.servlet-api:$servletApiVersion"
}
// JAX-RS REST
compile "org.glassfish.hk2:spring-bridge:$springHk2BridgeVersion"
compile "org.glassfish.jersey.core:jersey-server:$jerseyVersion"
compile "org.glassfish.jersey.containers:jersey-container-servlet:$jerseyVersion"
compile "org.glassfish.jersey.ext:jersey-bean-validation:$jerseyVersion"
// Apache HTTP Client
compile ("org.glassfish.jersey.connectors:jersey-apache-connector:$jerseyVersion")
        {
            exclude module: 'commons-logging'
        }
// Jackson JSON
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jacksonVersion"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion"
// Swagger Docs
compile("com.wordnik:swagger-jaxrs_2.10:$swaggerVersion") {
    exclude module: 'jsr311-api'
    exclude module: 'scala-compiler'
}
// JS, HTML, CSS minimizer
compile "ro.isdc.wro4j:wro4j-core:$wroVersion"
compile("ro.isdc.wro4j:wro4j-extensions:$wroVersion") {
    exclude module: 'commons-logging'
}
// Mapper
compile("net.sf.dozer:dozer:$dozerVersion") {
    exclude module: 'jcl-over-slf4j'
    exclude module: 'slf4j-log4j12'
}
// Database
compile "com.h2database:h2:$h2Version"
// Coda Hale Metrics
compile "com.codahale.metrics:metrics-core:$metricsVersion"

// Utilities
// =========
compile "org.projectlombok:lombok:$lombokVersion"
compile "com.google.guava:guava:$guavaVersion"

// Testing
// ========
testCompile("org.springframework.boot:spring-boot-starter-test") {
    exclude module: 'commons-logging'
}
// Mockito
testCompile "org.mockito:mockito-core:$mockitoVersion"
// Used for asserts in verification
testCompile "org.easytesting:fest-assert:$festAssertVersion"
}

服务器启动时的控制台输出

:37:38,267 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
:37:38,268 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
:37:38,268 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/Clowio/apt-crm/src/main/resources/logback.xml]
:37:38,525 |-INFO in ReconfigureOnChangeFilter{invocationCounter=0} - Will scan for changes in [[/Clowio/apt-crm/src/main/resources/logback.xml]] every 60 seconds. 
:37:38,525 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter
:37:38,536 |-INFO in ch.qos.logback.classic.joran.action.JMXConfiguratorAction - begin
:37:38,620 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@71d44a3 - Adding [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/base.xml] to configuration watch list.
:37:38,620 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@7b98f307 - URL [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/base.xml] is not of type file
:37:38,624 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@71d44a3 - Adding [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/defaults.xml] to configuration watch list.
:37:38,624 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@7b98f307 - URL [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/defaults.xml] is not of type file
:37:38,628 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word clr with class [org.springframework.boot.logging.logback.ColorConverter]
:37:38,628 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word wex with class [org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter]
:37:38,634 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [org.springframework.boot.logging.logback.LevelRemappingAppender]
:37:38,637 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [DEBUG_LEVEL_REMAPPER]
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.catalina.startup.DigesterFactory] to ERROR
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.catalina.util.LifecycleBase] to ERROR
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.coyote.http    .Http    NioProtocol] to WARN
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.sshd.common.util.SecurityUtils] to WARN
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.tomcat.util.net.NioSelectorPool] to WARN
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.crsh.plugin] to WARN
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.crsh.ssh] to WARN
:37:38,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.eclipse.jetty.util.component.AbstractLifeCycle] to ERROR
:37:38,668 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate.validator.internal.util.Version] to WARN
:37:38,668 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration] to WARN
:37:38,668 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.springframework.boot.actuate.endpoint.jmx] to false
:37:38,668 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [DEBUG_LEVEL_REMAPPER] to Logger[org.springframework.boot.actuate.endpoint.jmx]
:37:38,669 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.thymeleaf] to false
:37:38,670 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [DEBUG_LEVEL_REMAPPER] to Logger[org.thymeleaf]
:37:38,670 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@71d44a3 - Adding [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/console-appender.xml] to configuration watch list.
:37:38,671 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@7b98f307 - URL [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/console-appender.xml] is not of type file
:37:38,673 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
:37:38,678 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
:37:38,694 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
:37:38,769 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@71d44a3 - Adding [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/file-appender.xml] to configuration watch list.
:37:38,769 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@7b98f307 - URL [jar:file:/Users/lalala/.m2/repository/org/springframework/boot/spring-boot/1.2.0.RELEASE/spring-boot-1.2.0.RELEASE.jar!/org/springframework/boot/logging/logback/file-appender.xml] is not of type file
:37:38,773 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
:37:38,778 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
:37:38,789 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
:37:38,809 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@2177849e - No compression will be used
:37:38,821 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: /var/folders/j4/ntrxjqzx5kq19hbxfwc10czc0000gn/T//spring.log
:37:38,822 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [/var/folders/j4/ntrxjqzx5kq19hbxfwc10czc0000gn/T//spring.log]
:37:38,823 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
:37:38,823 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
:37:38,823 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
:37:38,824 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apt.crm] to DEBUG
:37:38,824 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to ERROR
:37:38,824 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate] to ERROR
:37:38,824 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.orm.jpa] to ERROR
:37:38,824 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.transaction] to DEBUG
:37:38,824 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
:37:38,824 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
:37:38,824 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
:37:38,826 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
:37:38,826 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
:37:38,826 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
:37:38,826 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@10959ece - Registering current configuration as safe fallback point

1 个答案:

答案 0 :(得分:1)

解决方案就是这个问题:

Global Exception Handling in Jersey & Spring?

创建ExceptionMapper后,一切正常。