Apache Camel独立应用程序的Log DSL中的Log4j

时间:2014-05-04 06:25:08

标签: java log4j apache-camel

我尝试在我的独立应用程序中配置文件log4.properties,它在控制台上显示但我无法在文件中看到它,以下是我的代码。

主类:

public static void main(String[] args) throws Exception { 
    Main main = new Main(); 
    main.enableHangupSupport(); 
    main.addRouteBuilder(new TestLogRoute()); 
    main.run(); 
} //EO main 

TestLogRoute类:

public void configure() throws Exception { 
    from("timer://foo?delay=0&period=20000")
        .log(LoggingLevel.INFO,"Log Configured MT ${body}"); 
} 

以下是log4j.properties下的com.my.test.resources文件:

log4j.rootLogger=info, stdout, R 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=%d{dd-MMM-yyyy HH:mm:ss:SSS} %5p [%t] - %m%n 
log4j.appender.R=org.apache.log4j.RollingFileAppender 
log4j.appender.R.File=d:\\logs\\testlogs.log 
log4j.appender.R.MaxFileSize=15000KB 
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%d %5p [%t] - %m%n 

编辑: 在我的主类中,我添加了以下行,因为我可以看到在目录中创建的新日志文件,但该文件中没有日志打印:

PropertyConfigurator.configure("log4j.properties"); 

1 个答案:

答案 0 :(得分:0)

通过在类路径中添加slf4j-log4j12.jar来解决问题,如此处所述(http://camel.465427.n5.nabble.com/Log4j-in-Camel-Standalone-Application-td5750730.html#a5750828

此致 姆兰