<?xml version="1.0" encoding="utf-8"?> <configuration debug="false" scan="true" scanPeriod="60 seconds"> <!-- 定义参数常量 --> <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}/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> <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.ouyan.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>
package com.ouyan.o2o.web.superadmin; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.ouyan.o2o.entity.Area; import com.ouyan.o2o.service.AreaService; @Controller @RequestMapping("/superadmin") public class AreaController { Logger logger = LoggerFactory.getLogger(AreaController.class); @Autowired private AreaService areaService; @RequestMapping(value = "/listarea", method = RequestMethod.GET) @ResponseBody private Map<String, Object> listArea() { logger.info("===start==="); long startTime = System.currentTimeMillis(); Map<String, Object> modelMap = new HashMap<String, Object>(); List<Area> list = new ArrayList<Area>(); try { list = areaService.getAreaList(); modelMap.put("rows", list); modelMap.put("total", list.size()); } catch (Exception e) { e.printStackTrace(); modelMap.put("success", false); modelMap.put("errMs", e.toString()); } logger.error("test error"); long endTime = System.currentTimeMillis(); logger.debug("costTime:[{}ms]",endTime-startTime); logger.info("===end==="); return modelMap; } }
然后看控制台,发现有日志输出。看到控制台信息: CATALINA_BASE: D:workspace.metadata.pluginsorg.eclipse.wst.server.core mp3
进入到该目录下:
搞定。