In our application (not using spring), we do it like this:
Content of the file c:\reporting\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
And when starting the application, we set a SystemProperty like this:
-Dlog4j.configuration=file:///C:/reporting/conf/birt/birt-log4j.properties
And inside the application, we are using org.yajul.log.JuliToLog4JService (see http://yajul.sourceforge.net/) and set it up like this:
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
}
}
}
As a nice side-effect, you can use MDC with log4j. E.g. our application is using BIRT multi-threaded, and log4j can automatically add a meaningful identifier for the thread to the log line.
For the IDE, we aren't using log4j. In order to direct BIRT's log messages to a not-so-deeply-nested log file, we just start the IDE like this (in Windows):
start /D%~dp0birt %BIRT_EXE% -clean -vmargs -Djava.util.logging.config.file=%~dp0logging.properties
with a file logging.properties like this:
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