springBoot使用logback:https://www.cnblogs.com/liufei2/p/16069903.html
<appender name="fileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>test-info.log</file> <encoder> <charset>UTF-8</charset> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level ${PID:-} --- [%t] %logger{50} - %msg%n</pattern> </encoder> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>INFO</level> </filter> </appender> <!--若是additivity设为false,则子Logger只会在自己的appender里输出,不会在root的logger的appender里输出--> <!--若是additivity设为true,则子Logger不止会在自己的appender里输出,还会在root的logger的appender里输出。 控制台也会输出--> <logger name="com.liufei.demo.controller.PingController" level="info" additivity="false"> <appender-ref ref="EXECUTION_LOG" /> </logger>
@RestController @RequestMapping("/ping") public class PingController { final static Logger logger = LoggerFactory.getLogger(PingController.class); @GetMapping public String ping() { logger.info("ping success!"); return "ok"; } }
说明:
我的name="com.liufei.demo.controller.PingController"。 所以 这个要这样写 LoggerFactory.getLogger(PingController.class);
如果name="TEST_LOG" 则:LoggerFactory.getLogger("TEST_LOG");