log4j
1.遇到问题
log4j:WARN No appenders could be found for logger (com.mvn.spring.Tt).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
原因 没有log4j.properties文件
spring下 pom.xml
<dependency> <groupId>log4jgroupId> <artifactId>log4jartifactId> <version>1.2.17version> dependency>
class内
import org.apache.log4j.Logger; public class Log4jTest { public static Logger log = Logger.getLogger(Log4jTest.class); public static void main(String[] args) { // 记录debug级别的信息 log.debug("This is debug message."); // 记录info级别的信息 log.info("This is info message."); // 记录error级别的信息 log.error("This is error message."); } }
log4j.properties
log4j.rootLogger=DEBUG, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n