找到你要的答案

Q:Log4j in Log DSL of Apache Camel Standalone Application

Q:在Apache的骆驼独立应用DSL log4j日志

I tried to configure file log4.properties in my standalone application, it shows on console but i am unable to see it in file, following is my code.

Main Class:

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

TestLogRoute Class:

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

Following is my log4j.properties file under 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 

EDIT: In my main class i added the following line, due to this i can see a new log file created in directory but no log get printed in that file:

PropertyConfigurator.configure("log4j.properties"); 

我试图在我的独立的应用程序配置文件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}"); 
} 

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

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 

EDIT: In my main class i added the following line, due to this i can see a new log file created in directory but no log get printed in that file:

PropertyConfigurator.configure("log4j.properties"); 
answer1: 回答1:

Issue resolved by adding slf4j-log4j12.jar in classpath as mentioned here(http://camel.465427.n5.nabble.com/Log4j-in-Camel-Standalone-Application-td5750730.html#a5750828)

Regards, imran

通过添加slf4j-log4j12.jar classpath问题在这里提到的解决(http:/ /骆驼。465427。5。nabble。COM / log4j-in-camel-standalone-application-td5750730。HTML # a5750828)

Regards, imran

java  log4j  apache-camel