我有以下简单的代码。我试图使用apache-commons + log4j,因为Spring希望使用apache commons。
但我没有打印任何东西。请让我知道我在这里失踪了什么。
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//Import log4j classes.
public class MyApp {
// Define a static logger variable so that it references the
// Logger instance named "MyApp".
private static final Log logger = LogFactory.getLog(MyApp.class);
public static void main(final String... args) {
// Set up a simple configuration that logs on the console.
logger.info("Entering application.");
//some stuff here
logger.trace("Exiting application.");
}
}
commons-logging.properties:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4jLogger
log4j.configuration=log4j.properties
log4j.properties:
log4j.rootCategory=INFO, stdout, TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE
log4j.logger.org.springframework.ws.server.MessageTracing=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p [%c{3}] %m%n
此外,我在控制台中收到以下错误消息。我想知道我没有用slf4j配置任何东西
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
答案 0 :(得分:0)
必须确保您的log4j版本与rootCategory关键字兼容,因为我发现here它仍然存在只是为了确保与旧版本的兼容性,所以尝试使用rootLogger,如下所示:
log4j.rootLogger = DEBUG, stdout
另一方面,你的rootCategory有一个错误的参数
log4j.rootCategory = INFO,stdout, TRACE
请参阅此帖子:StackOverFlow
希望有所帮助