package org.apache.log4j;
public
class Logger {
// Creation and retrieval methods:
public
static Logger getRootLogger();
public
static Logger getLogger(String name);
// printing methods:
public
void debug(Object message);
public
void info(Object message);
public
void warn(Object message);
public
void error(Object message);
public
void fatal(Object message);
// generic printing method:
public
void log(Level l, Object message);
}
|
Logger x = Logger.
getLogger("wombat");
Logger y = Logger.
getLogger("wombat");
|
PropertyConfigurator.configure("log4j.properties");
|
private
static Logger log = Logger.getLogger("MyCLASS.class");
|
log.debug("it is the debug info");
|
import org.apache.log4j.Logger;
public
class Test {
static Logger
log= Logger.
getLogger(Test.
class);
public
void log(){
log.debug("Debug info.");
log.info("Info info");
log.warn("Warn info");
log.error("Error info");
log.fatal("Fatal info");
}
public
static
void main(String[] args) {
Test test =
new Test();
test.log();
}
}
|
log4j.rootLogger=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
|
log4j.rootLogger=info, stdout
|
log.debug("Debug info.");
|
log4j.appender.A=org.apache.log4j.ConsoleAppender
|
本文出自 “子 孑” 博客,请务必保留此出处http://zhangjunhd.blog.51cto.com/113473/21211
错误现象:
提示如下:
log4j:WARN No appenders could be found for logger (org.springframework.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
翻译过来是说:没有输出源给予logger(记录器)(org.springframework.context.ContextLoader).请初始化log4系统属性。
解决,这种情况肯能是没有添加log4j.properties到项目导致