求解,为什么我的logback报错

这个是配置文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <property name="log.level" value="debug" />
    <property name="log.maxHistory" value="30" />
    <property name="log.filePath" value="${catalina.base}/logs/webapps" />
    <property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss:SSS} [%thread]
     %-5level %logger{50}-%msg%n" />

    <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
    </appender>

    <appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.filePath}/debug.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.filePath}/debug/debug.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
            <maxHistory>${log.maxHistory}</maxHistory>

        </rollingPolicy>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>


    <appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.filePath}/info.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.filePath}/info/info.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
            <maxHistory>${log.maxHistory}</maxHistory>
        </rollingPolicy>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>


    <appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.filePath}/error.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.filePath}/error/error.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
            <maxHistory>${log.maxHistory}</maxHistory>
        </rollingPolicy>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <logger name="com.imooc.o2o" level="${log.level}" additivity="true">
        <appender-ref ref="infoAppender" />
        <appender-ref ref="debugAppender" />
        <appender-ref ref="errorAppender" />
    </logger>

    <root level="info">
        <appender-ref ref="consoleAppender" />
    </root>

</configuration>

这个是报错日志

10:20:48,900 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[debugAppender] - No encoder set for the appender named "debugAppender".
10:20:48,900 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
10:20:48,900 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [infoAppender]
10:20:48,900 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@905986454 - Will use gz compression
10:20:48,900 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@905986454 - Will use the pattern C:/Users/36537/.IntelliJIdea2019.1/system/tomcat/Unnamed_o2o_3/logs/webapps/info/info.%d{yyyy-MM-dd}.log for the active file
10:20:48,900 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'C:/Users/36537/.IntelliJIdea2019.1/system/tomcat/Unnamed_o2o_3/logs/webapps/info/info.%d{yyyy-MM-dd}.log.gz'.
10:20:48,900 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
10:20:48,900 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Fri May 10 09:23:22 CST 2019
10:20:48,900 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[infoAppender] - Active log file name: C:Users36537.IntelliJIdea2019.1systemtomcatUnnamed_o2o_3/logs/webapps/info.log
10:20:48,900 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[infoAppender] - File property is set to [C:Users36537.IntelliJIdea2019.1systemtomcatUnnamed_o2o_3/logs/webapps/info.log]
10:20:48,900 |-WARN in ch.qos.logback.core.rolling.RollingFileAppender[infoAppender] - Encoder has not been set. Cannot invoke its init method.
10:20:48,900 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[infoAppender] - No encoder set for the appender named "infoAppender".
10:20:48,900 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
10:20:48,900 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [errorAppender]
10:20:48,900 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1482593465 - Will use gz compression
10:20:48,900 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1482593465 - Will use the pattern C:/Users/36537/.IntelliJIdea2019.1/system/tomcat/Unnamed_o2o_3/logs/webapps/error/error.%d{yyyy-MM-dd}.log for the active file
10:20:48,903 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'C:/Users/36537/.IntelliJIdea2019.1/system/tomcat/Unnamed_o2o_3/logs/webapps/error/error.%d{yyyy-MM-dd}.log.gz'.
10:20:48,903 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
10:20:48,903 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Fri May 10 09:23:22 CST 2019
10:20:48,904 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorAppender] - Active log file name: C:Users36537.IntelliJIdea2019.1systemtomcatUnnamed_o2o_3/logs/webapps/error.log
10:20:48,904 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorAppender] - File property is set to [C:Users36537.IntelliJIdea2019.1systemtomcatUnnamed_o2o_3/logs/webapps/error.log]
10:20:48,904 |-WARN in ch.qos.logback.core.rolling.RollingFileAppender[errorAppender] - Encoder has not been set. Cannot invoke its init method.
10:20:48,904 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[errorAppender] - No encoder set for the appender named "errorAppender".
10:20:48,904 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.imooc.o2o] to DEBUG
10:20:48,904 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.imooc.o2o] to true
10:20:48,904 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [infoAppender] to Logger[com.imooc.o2o]
10:20:48,906 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [debugAppender] to Logger[com.imooc.o2o]
10:20:48,906 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [errorAppender] to Logger[com.imooc.o2o]
10:20:48,906 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
10:20:48,906 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [consoleAppender] to Logger[ROOT]
10:20:48,906 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
10:20:48,906 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@4d89bfc6 - Registering current configuration as safe fallback point

这个erro,怎么解决,求解
10:20:48,904 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[errorAppender] - No encoder set for the appender named "errorAppender".

阅读 12.7k
2 个回答

没有日志格式吧

<encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
 </encoder>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logFile.log</file>       
    ....
    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
</appender>

官网说明地址:appender

异常说的很明显, 你的"debugAppender"配置里缺少encoder标签.

在配置里加上

    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题