java-错误log4j:WARNNoappenderscouldbefoundforlogger 使⽤环境:
1.IED⼯具 idea
2.系统环境win10
错误原因:
1.根本原因是⽇志问题
解决⽅式:
1.pom⽂件添加jar包
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<!-- mvnrepository/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
2.引⼊log包
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
3.main⽅法中初始化
3.1加载配置⽂件
3.2初始化配置⽂件
Logger Logger("st");
log.info("--------------测试");
说明:
import org.l.DOMConfigurator; 此包使⽤来加载xml格式配置⽂件
log4j.properties:
配置⽂件内容
### 设置⽇志级别及⽇志存储器 ###
#Logger=DEBUG, Console
### 设置⽇志级别及⽇志存储器 ###
#Logger=DEBUG,consolePrint,errorFile,logFile,Console
###  输出到控制台 ###
solePrint.Encoding = UTF-8
solePrint = org.apache.log4j.ConsoleAppender
solePrint.Target = System.out
solePrint.layout = org.apache.log4j.PatternLayout
solePrint.layout.ConversionPattern=%d %p [%c] - %m%n
### 输出到⽇志⽂件 ###
log4j.appender.logFile.Encoding = UTF-8
log4j.appender.logFile = org.apache.log4j.DailyRollingFileAppender
log4j.appender.logFile.File = F:/IdeaProjects/test/target/log/test.log
log4j.appender.logFile.Append = true
log4j2 appenderlog4j.appender.logFile.Threshold = info
log4j.appender.logFile.layout = org.apache.log4j.PatternLayout
log4j.appender.logFile.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
### 保存异常信息到单独⽂件 ###
File.Encoding = UTF-8
File = org.apache.log4j.DailyRollingFileAppender
File.File = D:/RUN_Data/log/dajiangtai_error.log
File.Append = true
File.Threshold = ERROR
File.layout = org.apache.log4j.PatternLayout
File.layout.ConversionPattern =%-d{yyyy-MM-dd HH\:mm\:ss}  [ %t\:%r ] - [ %p ]  %m%n #Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.java.sql.ResultSet=INFO
apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
#log4j.logger.dajiangtai.dao=DEBUG,TRACE
log4j.logger.dajiangtai.dao.IFollowDao=DEBUG

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。