formatter.setFormat("%7.7{priority} %{time} [%8.8{category}] " +
"(%{uri}) %{thread}/%{class:short}: %{message}\\n%{throwable}");
final ServletOutputLogTarget servTarget = new ServletOutputLogTarget(this.servletContext, formatter);
final Hierarchy defaultHierarchy = Hierarchy.getDefaultHierarchy();
final ErrorHandler errorHandler = new DefaultErrorHandler();
defaultHierarchy.setErrorHandler(errorHandler);
defaultHierarchy.setDefaultLogTarget(servTarget);
defaultHierarchy.setDefaultPriority(logPriority);
final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""));
final String loggerManagerClass =
this.getInitParameter("logger-class", LogKitLoggerManager.class.getName());
// the log4j support requires currently that the log4j system is already configured elsewhere
final LoggerManager loggerManager =
newLoggerManager(loggerManagerClass, defaultHierarchy);
ContainerUtil.enableLogging(loggerManager, logger);
final DefaultContext subcontext = new DefaultContext(this.appContext);
subcontext.put("servlet-context", this.servletContext);
subcontext.put("context-work", this.workDir);
if (this.servletContextPath == null) {
File logSCDir = new File(this.workDir, "log");
logSCDir.mkdirs();
if (logger.isWarnEnabled()) {
logger.warn("Setting context-root for LogKit to " + logSCDir);
}
subcontext.put("context-root", logSCDir.toString());
} else {
subcontext.put("context-root", this.servletContextPath);
}
try {
ContainerUtil.contextualize(loggerManager, subcontext);
this.loggerManager = loggerManager;
if (loggerManager instanceof Configurable) {
//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.servletContext.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);
ContainerUtil.configure(loggerManager, conf);
}
// let's configure log4j
final String log4jConfig = getInitParameter("log4j-config", null);
if ( log4jConfig != null ) {
final Log4JConfigurator configurator = new Log4JConfigurator(subcontext);
// test if this is a qualified url
InputStream is = null;
if ( log4jConfig.indexOf(':') == -1) {
is = this.servletContext.getResourceAsStream(log4jConfig);
if (is == null) is = new FileInputStream(log4jConfig);
} else {
final URL log4jURL = new URL(log4jConfig);
is = log4jURL.openStream();
}
configurator.doConfigure(is, LogManager.getLoggerRepository());
}
ContainerUtil.initialize(loggerManager);
} catch (Exception e) {
errorHandler.error("Could not set up Cocoon Logger, will use screen instead", e, null);
}
this.log = this.loggerManager.getLoggerForCategory(accesslogger);
}