#commons-logging.properties
文件配置信息
# org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
# Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
#
利用
log4j
为输出介质
org.apache.commons.logging.Log=
org.apache.commons.logging.impl.Log4JCategoryLog
#JDK5 Logger
#org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
|
log.fatal(Object message);
log.fatal(Object message, Throwable t);
log.error(Object message);
log.error(Object message, Throwable t);
log.warn(Object message);
log.warn(Object message, Throwable t);
log.info(Object message);
log.info(Object message, Throwable t);
log.debug(Object message);
log.debug(Object message, Throwable t);
log.trace(Object message);
log.trace(Object message, Throwable t);
|
log.isFatalEnabled();
log.isErrorEnabled();
log.isWarnEnabled();
log.isInfoEnabled();
log.isDebugEnabled();
log.isTraceEnabled();
|
privatestatic
Log
log
= LogFactory.getLog(Test.
class
);
|
log
.debug(
"Debug info."
);
|
package
sample;
import
org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory;
publicclass
Test {
privatestatic
Log
log
= LogFactory.getLog(Test.
class
);
publicvoid
log(){
log
.debug(
"Debug info."
);
log
.info(
"Info info"
);
log
.warn(
"Warn info"
);
log
.error(
"Error info"
);
log
.fatal(
"Fatal info"
);
}
publicstaticvoid
main(String[] args) {
Test test =
new
Test();
test.log();
}
}
|
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog
|
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] - %m%n
|
INFO [main] - Info info
WARN [main] - Warn info
ERROR [main] - Error info
FATAL [main] - Fatal info
|