背景与用途
log4j的配置文件是用来设置纪录器的级别、存放位置和布局的,可以通过Java属性文件(key=value)格式设置或XML格式设置。
SpringBoot中内置了log4j。
调试Sample代码
public static void main(String [] args) {
//BasicConfigurator.configure();
Logger logger = LoggerFactory.getLogger(Log4jT.class);
logger.debug( " this is {} debug log", Log4jT.class.getName() );
logger.error( " this is {} error log", Log4jT.class.getName());
}
结果:
log4j:WARN No appenders could be found for logger (com.xiaofan.test.Test).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
import org.apache.log4j.Logger;
public class Test {
private static Logger logger= Logger.getLogger(Test.class);
public static void main(String[] args){
logger.debug("This is a debug message.");
logger.info("This is a info message.");
logger.error("This is a error message.");
}
}