0
我使用下面的簡單代碼。我正在嘗試使用apache-commons + log4j,因爲Spring WS預計將使用apache commons。Apache commons + log4j日誌記錄
但我沒有得到任何打印的東西。請讓我知道我在這裏錯過了什麼。
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.
當我編寫答案時,我沒有注意到錯誤信息,必須將jar slf4j-log4j12.jar添加到您的類路徑中,因爲您的類路徑中可能包含slf4j api,並且它包含與常規日誌記錄相同的包,請參閱:http://www.slf4j.org/api/org/apache/commons/logging/package-summary.html – jMounir 2015-03-31 11:30:04