logback+SLF4J 没打印日志 为什么?启动时正常,但调用logger.info没打印日志,控制台和文件都没有输出。
jar:
logback-ext-spring-0.1.3-SNAPSHOT.jar
logback-ext-loggly-0.1.3-SNAPSHOT.jar
logback-core-1.1.2.jar
logback-classic-1.1.2.jar
slf4j-api-1.7.7.jar
spring用的4.1版本
web.xml:
<context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>/WEB-INF/logback.xml</param-value>
</context-param>
<listener>
<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
logback.xml内容
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<configuration debug=”true”>
<!–定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 –>
<property name=”LOG_HOME” value=”e:/temp2″ />
<jmxConfigurator />
<!– 控制台输出 –>
<appender name=”STDOUT” class=”ch.qos.logback.core.ConsoleAppender”>
<target>System.out</target>
<encoder class=”ch.qos.logback.classic.encoder.PatternLayoutEncoder”>
<!–格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 –>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} –
%msg%n</pattern>
</encoder>
</appender>
<!– 按照每天生成日志文件 –>
<appender name=”FILE”
class=”ch.qos.logback.core.rolling.RollingFileAppender”>
<File>${LOG_HOME}/yoyo.log</File>
<rollingPolicy class=”ch.qos.logback.core.rolling.FixedWindowRollingPolicy”>
<FileNamePattern>${LOG_HOME}/yoyo.log.%i.bak</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>12</MaxIndex>
</rollingPolicy>
<triggeringPolicy
class=”ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy”>
<MaxFileSize>100MB</MaxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} – %msg%n</pattern>
</encoder>
</appender>
<logger name=”slf4j”>
<level value=”DEBUG” />
<appender-ref ref=”STDOUT” />
<appender-ref ref=”FILE” />
</logger>
</configuration>
调用:
protected static final Logger logger = LoggerFactory.getLogger(ActionLogin.class);
logger.info(“Hello {}”,”SLF4J”);