final Hierarchy defaultHierarchy = Hierarchy.getDefaultHierarchy();
final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""));
final LogKitLoggerManager logKitLoggerManager = new LogKitLoggerManager(defaultHierarchy);
logKitLoggerManager.enableLogging(logger);
final DefaultContext subcontext = new DefaultContext();
subcontext.put(Constants.CONTEXT_WORK_DIR, workDir);
subcontext.put("portlet-context", this.portletContext);
if (this.portletContextPath == null) {
File logSCDir = new File(this.workDir, "log");
logSCDir.mkdirs();
if (getLogger().isWarnEnabled()) {
getLogger().warn("Setting context-root for LogKit to " + logSCDir);
}
subcontext.put("context-root", logSCDir.toString());
} else {
subcontext.put("context-root", this.portletContextPath);
}
if ( this.portletContext instanceof PortletContextImpl ) {
subcontext.put("servlet-context", ((PortletContextImpl)this.portletContext).getServletContext());
}
try {
logKitLoggerManager.contextualize(subcontext);
//Configure the logkit management
String logkitConfig = getInitParameter("logkit-config", "/WEB-INF/logkit.xconf");
// test if this is a qualified url
InputStream is = null;
if (logkitConfig.indexOf(':') == -1) {
is = this.portletContext.getResourceAsStream(logkitConfig);
if (is == null) is = new FileInputStream(logkitConfig);
} else {
URL logkitURL = new URL(logkitConfig);
is = logkitURL.openStream();
}
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final Configuration conf = builder.build(is);
logKitLoggerManager.configure(conf);
} catch (Exception e) {
e.printStackTrace();
}
if (accesslogger != null) {
this.log = logKitLoggerManager.getLoggerForCategory(accesslogger);
} else {
this.log = logKitLoggerManager.getLoggerForCategory("cocoon");
}
}