请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

控制台没输出debug日志信息,但是info和error都成功打印出来了

图片描述

        long startTime=System.currentTimeMillis();
		logger.error("test error!");
		long endTime=System.currentTimeMillis();
		logger.debug("costTime:[{}ms]",endTime-startTime);
``<!--logback.xml-->
    <appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
       <file>${log.filePath}/debug.log</file>
       <rollingPolicy class="ch.qos.logback.core.rolling.TimeBaseRollingPolicy">
          <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>
    </appender>
<!--****-->
`    <logger name="com.iflytek" 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>
    

为什么控制台打印不出debug的日志,我都写了的?谢谢!

正在回答 回答被采纳积分+3

1回答

翔仔 2019-04-09 00:00:17

同学可以直接复制粘贴我的,然后clean tomcat试试,如果成功了,再对比下区别

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
	<!-- 定义参数常量 -->
	<!-- TRACE<DEBUG<INFO<WARN<ERROR -->
	<!-- logger.trace("msg") logger.debug... -->
	<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>
	<!-- DEBUG -->
	<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>
		<encoder>
			<pattern>${log.pattern}</pattern>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>DEBUG</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
	</appender>
	<!-- 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.imooc.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>


0 回复 有任何疑惑可以回复我~
  • 提问者 weixin_慕用6148056 #1
    我复制了,缓存也清了,debug还是没打印出来
    回复 有任何疑惑可以回复我~ 2019-04-09 07:25:57
  • 提问者 weixin_慕用6148056 #2
    long endTime=System.currentTimeMillis();
    		logger.info("costTime:[{}ms]", endTime - startTime);
    		logger.info("===end===");
    		return modelMap;
    
    =============================
    2019-04-09 08:26:53.126 [http-nio-8080-exec-1] INFO  cn.iflytek.controller.superadmin.AreaController - ===end===
    2019-04-09 08:26:59.014 [http-nio-8080-exec-5] INFO  cn.iflytek.controller.superadmin.AreaController - ===start===
    2019-04-09 08:27:01.119 [http-nio-8080-exec-5] ERROR cn.iflytek.controller.superadmin.AreaController - test error!
    2019-04-09 08:27:03.368 [http-nio-8080-exec-5] INFO  cn.iflytek.controller.superadmin.AreaController - costTime:[3221ms]
    2019-04-09 08:27:04.659 [http-nio-8080-exec-5] INFO  cn.iflytek.controller.superadmin.AreaController - ===end===
    我用info能打印出时间,配置我用的上面的代码啊
    回复 有任何疑惑可以回复我~ 2019-04-09 08:29:13
  • 提问者 weixin_慕用6148056 #3
    2019-04-09 08:55:39.286 [http-nio-8080-exec-2] DEBUG cn.iflytek.dao.AreaDao.queryArea - ==>  Preparing: select area_id,area_name,priority,create_time,last_edit_time from tb_area order by priority DESC 
    2019-04-09 08:55:39.330 [http-nio-8080-exec-2] DEBUG cn.iflytek.dao.AreaDao.queryArea - ==> Parameters: 
    2019-04-09 08:55:39.371 [http-nio-8080-exec-2] DEBUG cn.iflytek.dao.AreaDao.queryArea - <==      Total: 2
    2019-04-09 08:55:39.388 [http-nio-8080-exec-2] ERROR cn.iflytek.controller.superadmin.AreaController - test error!
    2019-04-09 08:55:39.388 [http-nio-8080-exec-2] DEBUG cn.iflytek.controller.superadmin.AreaController - costTime:[944ms]
    2019-04-09 08:55:39.393 [http-nio-8080-exec-2] INFO  cn.iflytek.controller.superadmin.AreaController - ===end===
    打印出来了,包的地址每对,谢谢!
    回复 有任何疑惑可以回复我~ 2019-04-09 08:54:25
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信