在日志文件中看不到哪个API正在抛出错误-Spring-Boot

时间:2018-12-06 02:30:54

标签: spring spring-boot logback

嗨,我在springboot中使用logback,它只是将错误消息存储到error.log文件中。我需要查看哪个api引发了该错误。请帮助我。

示例error.log文件:

2018-12-06 00:02:11 [http-nio-8085-exec-2]错误o.h.e.jdbc.spi.SqlExceptionHelper-您的SQL语法有一个错误;查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ tabless”附近使用

在这里,我无法看到哪个API引发此错误。

logback.xml文件:

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

<property name="LOG_DIR" value="/opt/appLogs/" />

<!--Console log-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>
            %date{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
        </Pattern>
    </layout>
</appender>

<!--log file config-->

<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">

    <file>${LOG_DIR}/log.log</file>

    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>
            %date{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
        </Pattern>
    </encoder>

    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>
            ${LOG_DIR}/archived/log_%d{dd-MM-yyyy}.log
        </fileNamePattern>
        <maxHistory>10</maxHistory>
        <totalSizeCap>100MB</totalSizeCap>
    </rollingPolicy>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
        <level>INFO</level>
        <onMatch>ACCEPT</onMatch>
        <onMismatch>DENY</onMismatch>
    </filter>

</appender>

<!-- error file configuration-->
<appender name="error_file" class="ch.qos.logback.core.rolling.RollingFileAppender">

    <file>${LOG_DIR}/error.log</file>

    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>
           %date{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
        </Pattern>
    </encoder>

    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>
            ${LOG_DIR}/archived/error_%d{dd-MM-yyyy}.log
        </fileNamePattern>
        <maxHistory>10</maxHistory>
        <totalSizeCap>100MB</totalSizeCap>
    </rollingPolicy>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
        <level>ERROR</level>
        <onMatch>ACCEPT</onMatch>
        <onMismatch>DENY</onMismatch>
    </filter>

</appender>

<logger name="com.app.test" level="DEBUG" additivity="false" >
    <appender-ref ref="INFO" />
    <appender-ref ref="STDOUT" />
</logger>

<root level="ERROR">
    <appender-ref ref="error_file" />
</root>

0 个答案:

没有答案