老师我是用idea的 验证logback 和老师的不一样

老师我是用idea的 验证logback 和老师的不一样

VersionLoggerListener.log CATALINA_BASE:         C:\Users\Fushan\.IntelliJIdea2018.3\system\tomcat\Unnamed_o2o_3

在这下面没有找到log文件反而生成在桌面上[1022/171425.047:ERROR:crash_report_database_win.cc(428)] unexpected header

17:14:23,644 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]

17:14:23,645 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]

17:14:23,645 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/E:/idea/apache-tomcat-8.5.33/webapps/o2o/WEB-INF/classes/logback.xml]

17:14:23,731 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set

17:14:23,735 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/E:/idea/apache-tomcat-8.5.33/webapps/o2o/WEB-INF/classes/logback.xml] 

17:14:23,735 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 1 minutes

17:14:23,751 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:82 - no applicable action for [apperder], current ElementPath  is [[configuration][apperder]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:18 - no applicable action for [encoder], current ElementPath  is [[configuration][apperder][encoder]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:22 - no applicable action for [pattern], current ElementPath  is [[configuration][apperder][encoder][pattern]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@18:92 - no applicable action for [apperder], current ElementPath  is [[configuration][apperder]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:15 - no applicable action for [file], current ElementPath  is [[configuration][apperder][file]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@21:83 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][apperder][rollingPolicy]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@23:30 - no applicable action for [fileNamePattern], current ElementPath  is [[configuration][apperder][rollingPolicy][fileNamePattern]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@26:25 - no applicable action for [maxHistory], current ElementPath  is [[configuration][apperder][rollingPolicy][maxHistory]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:18 - no applicable action for [encoder], current ElementPath  is [[configuration][apperder][encoder]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@29:22 - no applicable action for [pattern], current ElementPath  is [[configuration][apperder][encoder][pattern]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@31:67 - no applicable action for [filter], current ElementPath  is [[configuration][apperder][filter]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:20 - no applicable action for [level], current ElementPath  is [[configuration][apperder][filter][level]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@33:22 - no applicable action for [onMatch], current ElementPath  is [[configuration][apperder][filter][onMatch]]

17:14:23,752 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@34:25 - no applicable action for [onMismatch], current ElementPath  is [[configuration][apperder][filter][onMismatch]]

17:14:23,752 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]

17:14:23,761 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [infoAppender]

17:14:23,800 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@588682596 - Will use gz compression

17:14:23,802 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@588682596 - Will use the pattern log.filePath_IS_UNDEFINED/info/info.%d{yyyy-MM-dd}.log for the active file

17:14:23,809 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'log.filePath_IS_UNDEFINED/info/info.%d{yyyy-MM-dd}.log.gz'.

17:14:23,809 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.

17:14:23,810 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Tue Oct 22 17:07:36 CST 2019

17:14:23,814 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property

17:14:23,861 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[infoAppender] - Active log file name: log.filePath_IS_UNDEFINED/info.log

17:14:23,861 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[infoAppender] - File property is set to [log.filePath_IS_UNDEFINED/info.log]

17:14:23,863 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]

17:14:23,863 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [errorAppender]

17:14:23,864 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1195521582 - Will use gz compression

17:14:23,864 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1195521582 - Will use the pattern log.filePath_IS_UNDEFINED/error/error.%d{yyyy-MM-dd}.log for the active file

17:14:23,865 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'log.filePath_IS_UNDEFINED/error/error.%d{yyyy-MM-dd}.log.gz'.

17:14:23,865 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.

17:14:23,865 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Tue Oct 22 17:07:36 CST 2019

17:14:23,865 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property

17:14:23,866 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorAppender] - Active log file name: log.filePath_IS_UNDEFINED/erorr.log

17:14:23,866 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorAppender] - File property is set to [log.filePath_IS_UNDEFINED/erorr.log]

17:14:23,868 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.fushan.o2o] to DEBUG

17:14:23,868 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.fushan.o2o] to true

17:14:23,868 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [debugAppender]. Did you define it below instead of above in the configuration file?

17:14:23,868 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details.

17:14:23,868 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [infoAppender] to Logger[com.fushan.o2o]

17:14:23,869 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [errorAppender] to Logger[com.fushan.o2o]

17:14:23,869 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO

17:14:23,869 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [consoleAppender]. Did you define it below instead of above in the configuration file?

17:14:23,869 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details.

17:14:23,869 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.

17:14:23,870 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@16eaa402 - Registering current configuration as safe fallback point


正在回答

登陆购买课程后可参与讨论,去登陆

6回答

同学你好!

  1. 老师这里没有在桌面生成文件呢,同学使用老师源码中的配置文件试一下看是否还会在桌面生成

  2. 首先logger 有两种级别:

    1) root,它只有一个 level 属性,在案例中的应用

    http://img1.sycdn.imooc.com//climg/5db004ba0992cbeb05370185.jpg

    2)普通的 logger,logger 是用来设置某一个包或者具体的某一个类的日志打印机级别,以及制定的 appender。 它的三个属性老师在注释中写出了。

    http://img1.sycdn.imooc.com//climg/5db0056309d64c5208630435.jpg

         3)同学可以看到无论是root还是logger里面都写了appender-ref,其中的appender 是负责写日志的组件,常用的组件有:

          (1)ConsoleAppender:控制台日志组件,该组件将日志信息输出到控制台,其中root就是用了这种方式

          (2)FileAppender:文件日志组件,该组件将日志信息输出到日志文件中,这个在本次案例中没有使用

          (3)RollingFileAppender:滚动记录文件日志组件,先将日志记录记录到指定文件,当符合某个条件时,将日志记录到其他文件,该组件有以下节点。本次案例中logger中配置就使用了这样的方式

如果我的回答解决了你的疑惑,请采纳,祝学习愉快  ~


提问者 学习中的傅山 2019-10-23 12:08:39

  <logger name="com.fushan.o2o" level="${log.level}" additivity="true">

        <appender-ref ref="debugAppender"/>

        <appender-ref ref="infoAppender"/>

        <appender-ref ref="errorAppender"/>

    </logger>

    <root level="info">

        <appender-ref ref="consoleAppender"/>

    </root>

老师可以在解释一下这几行代码吗   

提问者 学习中的傅山 2019-10-23 11:57:06
好帮手慕柯南 2019-10-23 10:42:43

同学你好!

这是因为同学的配置文件写错了呢

  1. 同学的log.filepath其中的p写为小写了呢,应该改为大写

    http://img1.sycdn.imooc.com//climg/5dafbd9609bdfcd007510585.jpg

  2. 修改之后在老师这里除了debug文件都是可以正常生成的,老师仔细对比并没有发现debug哪里有什么问题。可能是由于老师代码复制过来里面有一些中文的空格或者什么导致的。这里建议同学将debug级别的配置删除,复制其它级别的配置修改为debug的测试一下。

  3. 或者同学直接下载源码,使用老师的配置文件也是可以的

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 提问者 学习中的傅山 #1
    老师 修改之后有生成debug/info/error文件了 但不知道为什么桌面就是会多一个debug文件
    2019-10-23 11:55:42
提问者 学习中的傅山 2019-10-22 19:32:03
提问者 学习中的傅山 2019-10-22 19:31:36

<?xml version="1.0" encoding="UTF-8" ?>

<configuration scan="true" scanPeriod="60 seconds" debug="false">

    <!--定义参数常量-->

    <!--TRACE<DEBUG<INFO<WARN<ERROR-->

    <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"/>

    <!--时间格式/那个线程执行/哪个级别日志/哪个类-->

    <!--控制台设置-->

    <apperder name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">

        <encoder>

            <pattern>${log.pattern}</pattern>

        </encoder>

    </apperder>

    <!--DEBUG-->

    <apperder 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>

        <encoder>

            <pattern>${log.pattern}</pattern>

        </encoder>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">

            <level>DEBUG</level>

            <onMatch>ACCEPT</onMatch>

            <onMismatch>DENY</onMismatch>

        </filter>

    </apperder>

    <!-- INFO -->

    <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>

        <encoder>

            <pattern>${log.pattern}</pattern>

        </encoder>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">

            <level>INFO</level>

            <onMatch>ACCEPT</onMatch>

            <onMismatch>DENY</onMismatch>

        </filter>

    </appender>

    <!-- ERROR -->

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

        <!-- 文件路径 -->

        <file>${log.filePath}/erorr.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>

        <encoder>

            <pattern>${log.pattern}</pattern>

        </encoder>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">

            <level>ERROR</level>

            <onMatch>ACCEPT</onMatch>

            <onMismatch>DENY</onMismatch>

        </filter>

    </appender>

    <logger name="com.fushan.o2o" level="${log.level}" additivity="true">

        <appender-ref ref="debugAppender"/>

        <appender-ref ref="infoAppender"/>

        <appender-ref ref="errorAppender"/>

    </logger>

    <root level="info">

        <appender-ref ref="consoleAppender"/>

    </root>

</configuration>


问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师