标签:you set 错误 isp png group err app show
Log4j:日志工厂的一部分(使用起来比较麻烦)
1.要想使用外部类,得先导包 pom.xml
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
2.导入之后他说我们可以通过一个配置文件来配置
在resources包里创建配置文件 log4j.properties
### 设置###
log4j.rootLogger = debug,stdout,D,E
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### 输出DEBUG 级别以上的日志到=E://logs/error.log ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = E://logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 输出ERROR 级别以上的日志到=E://logs/error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =E://logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
3.配置log4j为日志的实现 mybatis-config.xml
<settings> <settings name=“logImp1“ value=”“/> </settings>
4.log4j的使用
import org.apache.log4j.Logger;
import org.junit.Test;
public class Log4jTest {
Logger LOGGER = Logger.getLogger(Log4jTest.class);
/**
* apache-log4j 日志输出
*/
@Test
public void testLog4j(){
LOGGER.info("普通信息");
LOGGER.error("普通错误");
LOGGER.trace("堆栈信息");
LOGGER.fatal("致命错误");
LOGGER.warn("警告信息");
LOGGER.debug("调试信息");
}
}
标签:you set 错误 isp png group err app show
原文地址:https://www.cnblogs.com/tuyaojiao/p/12368715.html