2014-06-20 49 views
0

我有一个弹簧mvc 3.0 webapp,我试图按照http://wiki.eclipse.org/BIRT/FAQ/Deployment#Logging的指示将birt报告日志重定向到log4j,但我有一些麻烦理解如何去做。直接BIRT报告日志到log4j

第一步创建类是好的。

第二步创建配置文件“logging.properties”,并指定上述处理程序左撇子:处理器= test.Log4jHandler

究竟应该是logging.properties的内容?一个例子会很棒。

第三步我也不太了解。我假设这意味着将文件放入类路径中......但是,如何通过系统属性设置位置?

如果有人能帮助一个很好的例子。

感谢

回答

1

在我们的应用程序(不使用弹簧),我们这样做是这样的:文件c的

内容:\报告\的conf \ BIRT \ birt-log4j.properties:

log4j.rootCategory=INFO, file 
# Set to DEBUG to see a lot more messages from BIRT 

log4j.logger.org.eclipse=INFO, engine 
log4j.additivity.org.eclipse=false 

log4j.logger.org.eclipse.birt=INFO, engine 
log4j.additivity.org.eclipse.birt=false 

log4j.logger.org.eclipse.birt.data=WARN, engine 
log4j.additivity.org.eclipse.birt.data 

log4j.appender.file=org.apache.log4j.RollingFileAppender 
log4j.appender.file.File=C:/reporting/log/birt/birt.log 
log4j.appender.file.MaxFileSize=5000KB 
log4j.appender.file.MaxBackupIndex=10 
log4j.appender.file.layout=org.apache.log4j.PatternLayout 
log4j.appender.file.layout.ConversionPattern=[%d{ISO8601}] %-5p [%t] J:%X{jobId} - (%F:%L) - %m%n 

log4j.appender.engine=org.apache.log4j.RollingFileAppender 
log4j.appender.engine.File=C:/reporting/log/birt/engine.log 
log4j.appender.engine.MaxFileSize=2000KB 
log4j.appender.engine.MaxBackupIndex=10 
log4j.appender.engine.layout=org.apache.log4j.PatternLayout 
log4j.appender.engine.layout.ConversionPattern=[%d{ISO8601}] %-5p [%t] J:%X{jobId} - %c - %m%n 

和启动应用程序时,我们设置这样的SystemProperty:

-Dlog4j.configuration=file:///C:/reporting/conf/birt/birt-log4j.properties 

而且在应用程序内,我们使用org.yajul.log.JuliToLog4JService(见http://yajul.sourceforge.net/),并将其设置是这样的:

private JuliToLog4JService logHelper; 


/** 
* Initialize the BIRT and logging libraries. 
* 
* @throws Exception 
*/ 
private void initLogging() throws Exception { 
    logHelper = new JuliToLog4JService(); 
    logHelper.start(); 
} 


private void initBIRT() throws ConfigurationError { 

    String birtFontDirs = System.getProperty("birt.font.dirs"); 
    fontPath = birtFontDirs.split(File.pathSeparator); 
    // Check that the report directory exists 
    File f = new File(reportDir); 
    boolean dirOk = false; 
    dirOk = (f.isDirectory()); 
    if (!dirOk) { 
     log.fatal("Specified report directory " + String.valueOf(reportDir) 
       + " is not a directory or not accessible!"); 
     throw new ConfigurationError("Invalid report directory " 
       + String.valueOf(reportDir)); 
    } 
    log.info("Creating BIRT EngineConfig..."); 
    engineConfig = new EngineConfig(); 

    engineConfig.setLogger(java.util.logging.Logger 
      .getLogger("org.eclipse.BIRTengine")); 

    dbUrl = System.getProperty("lisa.birt.db.url"); 
    log.info("DB URL=" + dbUrl); 

    try { 
     log.info("Platform startup..."); 
     Platform.startup(engineConfig); 
     log.info("Creating report engine factory..."); 
     factory = (IReportEngineFactory) Platform 
       .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); 

     log.info("Creating report engine..."); 
     engine = factory.createReportEngine(engineConfig); 
     engine.setLogger(engineConfig.getLogger()); 
     // reportEngine.changeLogLevel(Level.parse(logLevel)); 
    } catch (Exception e) { 
     log.fatal("Error during BIRT startup!", e); 
     throw new ConfigurationError("Error during BIRT platform startup"); 
    } 
    log.info("BIRT EngineManager initialization completed."); 
} 

/** 
* Shut down the engine manager. Before destroying the BIRT report engine, 
* interrupt the generator threads. 
*/ 
public void shutdownBIRT() { 
    // Interrupt the still running threads 
    log.info("Shutting down BIRT engine..."); 

    // destroy the engine 
    if (engine != null) { 
     try { 
      log.info("Destroying BIRT ReportEngine..."); 
      engine.destroy(); 
      engine = null; 
     } catch (Exception e) { 
      log.warn("Error calling reportEngine.destroy:", e); 
     } 
    } 
    // shut down BIRT OSGI platform 
    try { 
     log.info("Shutting down BIRT OSGI platform..."); 
     Platform.shutdown(); // FIMXE This seems to hang. 
    } catch (Exception e) { 
     log.warn("Error calling Platform.shutdown:", e); 
    } 
    log.info("BIRT EngineManager shutdown completed."); 
} 

/** 
* Uninitialize the BIRT and logging libraries. 
*/ 
private void uninitialize() { 
    shutdownBIRT(); 
    try { 
     logHelper.stop(); 
    } catch (Throwable t) { 
     try { 
      t.printStackTrace(System.err); 
     } catch (Throwable t1) { 
      ; // ignore if we cannot log the error 
     } 
    } 
} 

作为一个很好的副作用,可以使用MDC使用log4j的。例如。我们的应用程序使用BIRT多线程,并且log4j可以自动为线程添加一个有意义的标识符到日志行。

对于IDE,我们不使用log4j。为了直接BIRT的日志消息发送到不那么深度嵌套的日志文件,我们刚开始是这样的IDE(在Windows中):

start /D%~dp0birt %BIRT_EXE% -clean -vmargs -Djava.util.logging.config.file=%~dp0logging.properties 

有这样的文件logging.properties:

handlers= java.util.logging.FileHandler 

.level= INFO 

org.eclipse.birt.report.data.oda.jdbc.level = FINE 

java.util.logging.FileHandler.pattern = ../log/birt-designer.log 
java.util.logging.FileHandler.limit = 5000000 
java.util.logging.FileHandler.count = 1 
#java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter 
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter 
java.util.logging.FileHandler.level = ALL 
+0

感谢您的输入创建记录器。如果我无法获取原始帖子中发布的说明,我会记住这一点。 – Richie

0

如果你想与自己的自定义java.util.logging的处理程序要做到这一点,你需要用“org.eclipse.birt.report”

...  
engineConfig.setLogger(java.util.logging.Logger.getLogger("org.eclipse.birt.report")); 
...