You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/07/25 21:24:26 UTC
svn commit: r225167 - in /cocoon:
blocks/portal/trunk/java/org/apache/cocoon/portlet/
trunk/src/java/org/apache/cocoon/components/blocks/
trunk/src/java/org/apache/cocoon/core/
trunk/src/java/org/apache/cocoon/core/container/
trunk/src/java/org/apache/...
Author: cziegeler
Date: Mon Jul 25 12:24:01 2005
New Revision: 225167
URL: http://svn.apache.org/viewcvs?rev=225167&view=rev
Log:
Unify logging by providing extension to LoggerManager.
Added:
cocoon/trunk/src/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java (with props)
cocoon/trunk/src/java/org/apache/cocoon/core/logging/
cocoon/trunk/src/java/org/apache/cocoon/core/logging/CocoonLogKitLoggerManager.java (with props)
cocoon/trunk/src/java/org/apache/cocoon/core/logging/PerRequestLoggerManager.java (with props)
cocoon/trunk/src/java/org/apache/cocoon/core/logging/SettingsContext.java (with props)
Removed:
cocoon/trunk/src/java/org/apache/cocoon/util/log/Log4JConfigurator.java
Modified:
cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java
cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java
cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
cocoon/trunk/src/java/org/apache/cocoon/core/MutableSettings.java
cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java
cocoon/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
cocoon/trunk/src/webapp/WEB-INF/web.xml
Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java (original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java Mon Jul 25 12:24:01 2005
@@ -15,6 +15,7 @@
*/
package org.apache.cocoon.portlet;
+import org.apache.avalon.excalibur.logger.Log4JConfLoggerManager;
import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
import org.apache.avalon.excalibur.logger.LoggerManager;
@@ -34,17 +35,16 @@
import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
import org.apache.cocoon.components.notification.Notifier;
import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.core.logging.CocoonLogKitLoggerManager;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.portlet.PortletContext;
import org.apache.cocoon.environment.portlet.PortletEnvironment;
import org.apache.cocoon.portlet.multipart.MultipartActionRequest;
import org.apache.cocoon.portlet.multipart.RequestFactory;
-import org.apache.cocoon.util.log.Log4JConfigurator;
import org.apache.commons.lang.BooleanUtils;
import org.apache.log.ContextMap;
import org.apache.log.Hierarchy;
-import org.apache.log4j.LogManager;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
@@ -860,7 +860,7 @@
final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""));
final String loggerManagerClass =
- this.getInitParameter("logger-class", LogKitLoggerManager.class.getName());
+ this.getInitParameter("logger-class", CocoonLogKitLoggerManager.class.getName());
// the log4j support requires currently that the log4j system is already configured elsewhere
@@ -903,23 +903,6 @@
ContainerUtil.configure(loggerManager, conf);
}
- // let's configure log4j
- final String log4jConfig = getInitParameter("log4j-config", null);
- if ( log4jConfig != null ) {
- final Log4JConfigurator configurator = new Log4JConfigurator(subcontext, null);
-
- // test if this is a qualified url
- InputStream is = null;
- if ( log4jConfig.indexOf(':') == -1) {
- is = this.portletContext.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) {
e.printStackTrace();
@@ -930,10 +913,12 @@
private LoggerManager newLoggerManager(String loggerManagerClass, Hierarchy hierarchy) {
if (loggerManagerClass.equals(LogKitLoggerManager.class.getName())) {
- return new LogKitLoggerManager(hierarchy);
+ return new CocoonLogKitLoggerManager();
+ } else if (loggerManagerClass.equals(CocoonLogKitLoggerManager.class.getName())) {
+ return new CocoonLogKitLoggerManager();
} else if (loggerManagerClass.equals(Log4JLoggerManager.class.getName()) ||
loggerManagerClass.equalsIgnoreCase("LOG4J")) {
- return new Log4JLoggerManager();
+ return new Log4JConfLoggerManager();
} else {
try {
Class clazz = Class.forName(loggerManagerClass);
Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java (original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java Mon Jul 25 12:24:01 2005
@@ -75,11 +75,6 @@
s.setLoggerManagerClassName(value);
}
- value = getInitParameter(config, "log4j-config");
- if ( value != null ) {
- s.setLog4jConfiguration("context:/" + value);
- }
-
s.setAllowReload(getInitParameterAsBoolean(config, "allow-reload", s.isAllowReload()));
handleLoadClass(getInitParameter(config, "load-class"), s);
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java Mon Jul 25 12:24:01 2005
@@ -43,7 +43,7 @@
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.container.CocoonServiceManager;
import org.apache.cocoon.core.Core;
-import org.apache.cocoon.core.CoreUtil;
+import org.apache.cocoon.core.container.SingleComponentServiceManager;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.internal.EnvironmentHelper;
import org.xml.sax.SAXException;
@@ -117,7 +117,7 @@
Core core = (Core)this.serviceManager.lookup(Core.ROLE);
ServiceManager blockParentServiceManager =
- new CoreUtil.RootServiceManager(null, core);
+ new SingleComponentServiceManager(null, core, Core.ROLE);
this.blockServiceManager =
new CocoonServiceManager(blockParentServiceManager);
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/BaseSettings.java Mon Jul 25 12:24:01 2005
@@ -73,17 +73,6 @@
String KEY_LOGGING_MANAGER_CLASS = "logging.manager.class";
/**
- * If you want to configure log4j using Cocoon, then you can define
- * an XML configuration file here. You can use the usual log4j property
- * substituation mechanism, e.g. ${context-root} is replaced by the
- * context root of this web application etc.
- * You can configure the log4j configuration even if you use LogKit
- * for Cocoon logging. You can use this to configure third party code
- * for example.
- */
- String KEY_LOGGING_LOG4J_CONFIGURATION = "logging.log4j.configuration";
-
- /**
* This parameter is used to list classes that should be loaded at
* initialization time of the servlet. For example, JDBC Drivers used need to
* be named here. Additional entries may be inserted here during build
@@ -221,12 +210,6 @@
* @see #KEY_PARENT_SERVICE_MANAGER
*/
String getParentServiceManagerClassName();
-
- /**
- * @return Returns the log4jConfiguration.
- * @see #KEY_LOGGING_LOG4J_CONFIGURATION
- */
- String getLog4jConfiguration();
/**
* @return Returns the uploadDirectory.
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java Mon Jul 25 12:24:01 2005
@@ -28,11 +28,9 @@
import java.util.Map;
import java.util.Properties;
-import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
-import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
+import org.apache.avalon.excalibur.logger.Log4JConfLoggerManager;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.framework.CascadingRuntimeException;
-import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -48,16 +46,18 @@
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.container.ComponentContext;
import org.apache.cocoon.configuration.ConfigurationBuilder;
+import org.apache.cocoon.core.container.SingleComponentServiceManager;
+import org.apache.cocoon.core.logging.CocoonLogKitLoggerManager;
+import org.apache.cocoon.core.logging.PerRequestLoggerManager;
+import org.apache.cocoon.core.logging.SettingsContext;
import org.apache.cocoon.core.source.SimpleSourceResolver;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.matching.helpers.WildcardHelper;
import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.util.StringUtils;
-import org.apache.cocoon.util.log.Log4JConfigurator;
import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.TraversableSource;
-import org.apache.log.ContextMap;
-import org.apache.log4j.LogManager;
/**
* This is an utility class to create a new Cocoon instance.
@@ -96,8 +96,8 @@
/** The time the cocoon instance was created. */
protected long creationTime;
- /** We use LogKit */
- protected boolean isLogKit = false;
+ /** Is this a per request logger manager */
+ protected boolean isPerRequestLoggerManager = false;
/**
* Setup a new instance.
@@ -329,7 +329,7 @@
}
}
}
- return new RootServiceManager(parentServiceManager, core);
+ return new SingleComponentServiceManager(parentServiceManager, core, Core.ROLE);
}
/**
@@ -380,34 +380,27 @@
}
/**
- * Initialize the context for logging.
- * TODO - Move this to the logger manager and make it LogKit independent.
+ * Initialize the current request.
+ * This method can be used to initialize anything required for processing
+ * the request. For example, if the logger manager is a {@link PerRequestLoggerManager}
+ * than this manager is invoked to initialize the logging context for the request.
+ * This method returns a handle that should be used to clean up everything
+ * when the request is finished by calling {@link #cleanUpRequest(Object)}.
*/
- public Object initializePerRequestLoggingContext(Environment env) {
- if ( this.isLogKit ) {
- ContextMap ctxMap;
- // Initialize a fresh log context containing the object model: it
- // will be used by the CocoonLogFormatter
- ctxMap = ContextMap.getCurrentContext();
- // Add thread name (default content for empty context)
- String threadName = Thread.currentThread().getName();
- ctxMap.set("threadName", threadName);
- // Add the object model
- ctxMap.set("objectModel", env.getObjectModel());
- // Add a unique request id (threadName + currentTime
- ctxMap.set("request-id", threadName + System.currentTimeMillis());
-
- return ctxMap;
+ public Object initializeRequest(Environment env) {
+ if ( this.isPerRequestLoggerManager ) {
+ return ((PerRequestLoggerManager)this.loggerManager).initializePerRequestLoggingContext(env);
}
return null;
}
/**
- * Initialize the context for logging.
+ * Cleanup everything initialized during the request processing in
+ * {@link #initializeRequest(Environment)}.
*/
- public void cleanPerRequestLoggingContext(Object ctxMap) {
- if ( ctxMap != null ) {
- ((ContextMap)ctxMap).clear();
+ public void cleanUpRequest(Object handle) {
+ if ( handle != null && this.isPerRequestLoggerManager) {
+ ((PerRequestLoggerManager)this.loggerManager).cleanPerRequestLoggingContext(handle);
}
}
@@ -427,7 +420,7 @@
final Logger bootstrapLogger = this.env.getBootstrapLogger(level);
// Create our own resolver
- SimpleSourceResolver resolver = new SimpleSourceResolver();
+ final SimpleSourceResolver resolver = new SimpleSourceResolver();
resolver.enableLogging(bootstrapLogger);
try {
resolver.contextualize(this.appContext);
@@ -435,9 +428,12 @@
throw new CascadingRuntimeException(
"Cannot setup source resolver.", ce);
}
+ // create an own service manager for the logger manager
+ final ServiceManager loggerManagerServiceManager = new SingleComponentServiceManager(
+ null, resolver, SourceResolver.ROLE);
// create an own context for the logger manager
- final DefaultContext subcontext = new DefaultContext(this.appContext);
+ final DefaultContext subcontext = new SettingsContext(this.appContext, this.settings);
subcontext.put("context-work", new File(this.settings.getWorkDirectory()));
if (this.env.getContextForWriting() == null) {
File logSCDir = new File(this.settings.getWorkDirectory(), "log");
@@ -458,6 +454,8 @@
try {
ContainerUtil.contextualize(loggerManager, subcontext);
+ ContainerUtil.service(loggerManager, loggerManagerServiceManager);
+
this.loggerManager = loggerManager;
if (loggerManager instanceof Configurable) {
@@ -470,8 +468,7 @@
source = resolver.resolveURI(logkitConfig);
final ConfigurationBuilder builder = new ConfigurationBuilder(
settings);
- final Configuration conf = builder.build(source
- .getInputStream());
+ final Configuration conf = builder.build(source.getInputStream());
final DefaultConfiguration categories = (DefaultConfiguration) conf
.getChild("categories");
final DefaultConfiguration targets = (DefaultConfiguration) conf
@@ -542,22 +539,6 @@
}
}
}
-
- // let's configure log4j
- final String log4jConfig = settings.getLog4jConfiguration();
- if (log4jConfig != null) {
- final Log4JConfigurator configurator = new Log4JConfigurator(subcontext, this.settings);
-
- Source source = null;
- try {
- source = resolver.resolveURI(log4jConfig);
- configurator.doConfigure(source.getInputStream(),
- LogManager.getLoggerRepository());
- } finally {
- resolver.release(source);
- }
- }
-
ContainerUtil.initialize(loggerManager);
} catch (Exception e) {
bootstrapLogger.error(
@@ -575,19 +556,19 @@
*/
private LoggerManager newLoggerManager(String loggerManagerClass) {
if ("LogKit".equalsIgnoreCase(loggerManagerClass) || loggerManagerClass == null) {
- loggerManagerClass = LogKitLoggerManager.class.getName();
+ loggerManagerClass = CocoonLogKitLoggerManager.class.getName();
} else if ("LOG4J".equalsIgnoreCase(loggerManagerClass)) {
- loggerManagerClass = Log4JLoggerManager.class.getName();
+ loggerManagerClass = Log4JConfLoggerManager.class.getName();
}
try {
Class clazz = Class.forName(loggerManagerClass);
- if ( loggerManagerClass.equals(LogKitLoggerManager.class.getName()) ) {
- this.isLogKit = true;
+ if ( PerRequestLoggerManager.class.isAssignableFrom(clazz) ) {
+ this.isPerRequestLoggerManager = true;
}
return (LoggerManager) clazz.newInstance();
} catch (Exception e) {
- this.isLogKit = true;
- return new LogKitLoggerManager();
+ this.isPerRequestLoggerManager = true;
+ return new CocoonLogKitLoggerManager();
}
}
@@ -605,60 +586,6 @@
uri = uri.substring(pos+1);
}
return WildcardHelper.match(null, uri, parsedPattern);
- }
-
- public static final class RootServiceManager
- implements ServiceManager, Disposable {
-
- protected final ServiceManager parent;
- protected final Core cocoon;
-
- public RootServiceManager(ServiceManager p, Core c) {
- this.parent = p;
- this.cocoon = c;
- }
-
- /**
- * @see org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
- */
- public boolean hasService(String key) {
- if ( Core.ROLE.equals(key) ) {
- return true;
- }
- if ( this.parent != null ) {
- return this.parent.hasService(key);
- }
- return false;
- }
-
- /**
- * @see org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
- */
- public Object lookup(String key) throws ServiceException {
- if ( Core.ROLE.equals(key) ) {
- return this.cocoon;
- }
- if ( this.parent != null ) {
- return this.parent.lookup(key);
- }
- throw new ServiceException("Cocoon", "Component for key '" + key + "' not found.");
- }
-
- /**
- * @see org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
- */
- public void release(Object component) {
- if ( component != this.cocoon && parent != null ) {
- this.parent.release(component);
- }
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- ContainerUtil.dispose(this.parent);
- }
}
/**
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/MutableSettings.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/MutableSettings.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/MutableSettings.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/MutableSettings.java Mon Jul 25 12:24:01 2005
@@ -92,22 +92,10 @@
/**
* This parameter switches the logging system from LogKit to Log4J for Cocoon.
- * Log4J has to be configured already.
*/
protected String loggerManagerClassName;
/**
- * If you want to configure log4j using Cocoon, then you can define
- * an XML configuration file here. You can use the usual log4j property
- * substituation mechanism, e.g. ${context-root} is replaced by the
- * context root of this web application etc.
- * You can configure the log4j configuration even if you use LogKit
- * for Cocoon logging. You can use this to configure third party code
- * for example.
- */
- protected String log4jConfiguration;
-
- /**
* Allow reinstantiating (reloading) of the cocoon instance. If this is
* set to "yes" or "true", a new cocoon instance can be created using
* the request parameter "cocoon-reload". It also enables that Cocoon is
@@ -271,8 +259,6 @@
this.bootstrapLogLevel = value;
} else if ( key.equals(KEY_LOGGING_MANAGER_CLASS) ) {
this.loggerManagerClassName = value;
- } else if ( key.equals(KEY_LOGGING_LOG4J_CONFIGURATION) ) {
- this.log4jConfiguration = value;
} else if ( key.equals(KEY_ALLOW_RELOAD) ) {
this.allowReload = BooleanUtils.toBoolean(value);
} else if ( key.equals(KEY_UPLOADS_ENABLE) ) {
@@ -481,13 +467,6 @@
}
/**
- * @return Returns the log4jConfiguration.
- */
- public String getLog4jConfiguration() {
- return this.log4jConfiguration;
- }
-
- /**
* @return Returns the accessLogger.
*/
public String getEnvironmentLogger() {
@@ -564,8 +543,6 @@
value = this.bootstrapLogLevel;
} else if ( sKey.equals(KEY_LOGGING_MANAGER_CLASS) ) {
value = this.loggerManagerClassName;
- } else if ( sKey.equals(KEY_LOGGING_LOG4J_CONFIGURATION) ) {
- value = this.log4jConfiguration;
} else if ( sKey.equals(KEY_ALLOW_RELOAD) ) {
value = String.valueOf(this.allowReload);
} else if ( sKey.equals(KEY_UPLOADS_ENABLE) ) {
@@ -633,7 +610,6 @@
KEY_LOGGING_ENVIRONMENT_LOGGER + " : " + this.environmentLogger + '\n' +
KEY_LOGGING_BOOTSTRAP_LOGLEVEL + " : " + this.bootstrapLogLevel + '\n' +
KEY_LOGGING_COCOON_LOGGER + " : " + this.cocoonLogger + '\n' +
- KEY_LOGGING_LOG4J_CONFIGURATION + " : " + this.log4jConfiguration + '\n' +
KEY_LOGGING_MANAGER_CLASS + " : " + this.loggerManagerClassName + '\n' +
KEY_LOGGING_OVERRIDE_LOGLEVEL + " : " + this.overrideLogLevel + '\n' +
KEY_MANAGE_EXCEPTIONS + " : " + this.manageExceptions + '\n' +
@@ -876,14 +852,6 @@
public void setWorkDirectory(String workDirectory) {
this.checkWriteable();
this.workDirectory = workDirectory;
- }
-
- /**
- * @param log4jConfiguration The log4jConfiguration to set.
- */
- public void setLog4jConfiguration(String log4jConfiguration) {
- this.checkWriteable();
- this.log4jConfiguration = log4jConfiguration;
}
/**
Added: cocoon/trunk/src/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java?rev=225167&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java Mon Jul 25 12:24:01 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.container;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ * This is a simple service manager implementation that just serves one
+ * single component.
+ * @since 2.2
+ * @version SVN $Id:$
+ */
+public final class SingleComponentServiceManager
+implements ServiceManager, Disposable {
+
+ protected final ServiceManager parent;
+ protected final Object component;
+ protected final String role;
+
+ public SingleComponentServiceManager(ServiceManager parent,
+ Object component,
+ String role) {
+ this.parent = parent;
+ this.component = component;
+ this.role = role;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
+ */
+ public boolean hasService(String key) {
+ if ( this.role.equals(key) ) {
+ return true;
+ }
+ if ( this.parent != null ) {
+ return this.parent.hasService(key);
+ }
+ return false;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
+ */
+ public Object lookup(String key) throws ServiceException {
+ if ( this.role.equals(key) ) {
+ return this.component;
+ }
+ if ( this.parent != null ) {
+ return this.parent.lookup(key);
+ }
+ throw new ServiceException("Cocoon", "Component for key '" + key + "' not found.");
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
+ */
+ public void release(Object component) {
+ if ( component != this.component && parent != null ) {
+ this.parent.release(component);
+ }
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ ContainerUtil.dispose(this.parent);
+ }
+}
\ No newline at end of file
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/container/SingleComponentServiceManager.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/src/java/org/apache/cocoon/core/logging/CocoonLogKitLoggerManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/logging/CocoonLogKitLoggerManager.java?rev=225167&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/logging/CocoonLogKitLoggerManager.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/logging/CocoonLogKitLoggerManager.java Mon Jul 25 12:24:01 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.logging;
+
+import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
+import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.cocoon.environment.Environment;
+import org.apache.log.ContextMap;
+
+/**
+ * This is an extension of the {@link LoggerManager}. It can be used to
+ * initialize a logging context on a per thread basis. This allows the
+ * logging implementation to access and log information about the current
+ * request.
+ *
+ * @version $Id:$
+ * @since 2.2
+ */
+public class CocoonLogKitLoggerManager
+ extends LogKitLoggerManager
+ implements PerRequestLoggerManager {
+
+ /**
+ * @see org.apache.cocoon.core.logging.PerRequestLoggerManager#initializePerRequestLoggingContext(org.apache.cocoon.environment.Environment)
+ */
+ public Object initializePerRequestLoggingContext(Environment env) {
+ ContextMap ctxMap;
+ // Initialize a fresh log context containing the object model: it
+ // will be used by the CocoonLogFormatter
+ ctxMap = ContextMap.getCurrentContext();
+ // Add thread name (default content for empty context)
+ String threadName = Thread.currentThread().getName();
+ ctxMap.set("threadName", threadName);
+ // Add the object model
+ ctxMap.set("objectModel", env.getObjectModel());
+ // Add a unique request id (threadName + currentTime
+ ctxMap.set("request-id", threadName + System.currentTimeMillis());
+
+ return ctxMap;
+ }
+
+ /**
+ * @see org.apache.cocoon.core.logging.PerRequestLoggerManager#cleanPerRequestLoggingContext(java.lang.Object)
+ */
+ public void cleanPerRequestLoggingContext(Object ctxMap) {
+ if ( ctxMap != null ) {
+ ((ContextMap)ctxMap).clear();
+ }
+ }
+
+}
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/logging/CocoonLogKitLoggerManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/logging/CocoonLogKitLoggerManager.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/src/java/org/apache/cocoon/core/logging/PerRequestLoggerManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/logging/PerRequestLoggerManager.java?rev=225167&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/logging/PerRequestLoggerManager.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/logging/PerRequestLoggerManager.java Mon Jul 25 12:24:01 2005
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.logging;
+
+import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.cocoon.environment.Environment;
+
+/**
+ * This is an extension of the {@link LoggerManager}. It can be used to
+ * initialize a logging context on a per thread basis. This allows the
+ * logging implementation to access and log information about the current
+ * request.
+ *
+ * @version $Id:$
+ * @since 2.2
+ */
+public interface PerRequestLoggerManager extends LoggerManager {
+
+ /**
+ * Initialize the context for logging.
+ */
+ Object initializePerRequestLoggingContext(Environment env);
+
+ /**
+ * Clean up the logging context.
+ */
+ void cleanPerRequestLoggingContext(Object ctxMap);
+}
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/logging/PerRequestLoggerManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/logging/PerRequestLoggerManager.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/src/java/org/apache/cocoon/core/logging/SettingsContext.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/logging/SettingsContext.java?rev=225167&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/logging/SettingsContext.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/logging/SettingsContext.java Mon Jul 25 12:24:01 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.logging;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.cocoon.core.Settings;
+
+/**
+ * This is an extension the default context implementation.
+ * It first looks into the settings object and only if the key
+ * is not found there, it delegates to the parent.
+ *
+ * @version $Id:$
+ * @since 2.2
+ */
+public class SettingsContext extends DefaultContext {
+
+ private final Settings settings;
+
+ public SettingsContext(Context parentContext, Settings s) {
+ super(parentContext);
+ this.settings = s;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.context.Context#get(java.lang.Object)
+ */
+ public Object get(Object name) throws ContextException {
+ if ( this.settings.getProperty(name.toString()) != null ) {
+ return this.settings.getProperty(name.toString());
+ }
+ return super.get(name);
+ }
+
+}
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/logging/SettingsContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/logging/SettingsContext.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java Mon Jul 25 12:24:01 2005
@@ -399,7 +399,6 @@
this.addValue(Settings.KEY_FORCE_PROPERTIES, s.getForceProperties());
this.addValue(Settings.KEY_LOGGING_CONFIGURATION, s.getLoggingConfiguration());
this.addValue(Settings.KEY_LOGGING_BOOTSTRAP_LOGLEVEL, s.getBootstrapLogLevel());
- this.addValue(Settings.KEY_LOGGING_LOG4J_CONFIGURATION, s.getLog4jConfiguration());
this.addValue(Settings.KEY_LOGGING_MANAGER_CLASS, s.getLoggerManagerClassName());
this.addValue(Settings.KEY_PARENT_SERVICE_MANAGER, s.getParentServiceManagerClassName());
this.addValue(Settings.KEY_LOGGING_COCOON_LOGGER, s.getCocoonLogger());
Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java Mon Jul 25 12:24:01 2005
@@ -355,7 +355,7 @@
}
String contentType = null;
- Object ctxMap = null;
+ Object handle = null;
Environment env;
try{
@@ -377,7 +377,7 @@
try {
try {
- ctxMap = this.coreUtil.initializePerRequestLoggingContext(env);
+ handle = this.coreUtil.initializeRequest(env);
if (this.cocoon.process(env)) {
contentType = env.getContentType();
@@ -462,7 +462,7 @@
}
}
} finally {
- this.coreUtil.cleanPerRequestLoggingContext(ctxMap);
+ this.coreUtil.cleanUpRequest(handle);
try {
if (request instanceof MultipartHttpServletRequest) {
Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java Mon Jul 25 12:24:01 2005
@@ -50,9 +50,16 @@
s.setConfiguration("/WEB-INF/cocoon.xconf");
}
+ // upto 2.1.x the logging configuration was named "logkit-config"
+ // we still support this, but provide a new unbiased name as well
value = getInitParameter(config, "logkit-config");
if ( value != null ) {
s.setLoggingConfiguration("context:/" + value);
+ } else {
+ value = getInitParameter(config, "logging-config");
+ if ( value != null ) {
+ s.setLoggingConfiguration("context:/" + value);
+ }
}
value = getInitParameter(config, "servlet-logger");
@@ -73,11 +80,6 @@
value = getInitParameter(config, "logger-class");
if ( value != null ) {
s.setLoggerManagerClassName(value);
- }
-
- value = getInitParameter(config, "log4j-config");
- if ( value != null ) {
- s.setLog4jConfiguration("context:/" + value);
}
s.setAllowReload(getInitParameterAsBoolean(config, "allow-reload", s.isAllowReload()));
Modified: cocoon/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java (original)
+++ cocoon/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java Mon Jul 25 12:24:01 2005
@@ -37,7 +37,6 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.core.Core;
-import org.apache.cocoon.core.CoreUtil;
import org.apache.cocoon.core.MutableSettings;
/**
@@ -300,7 +299,7 @@
// Set up root manager for Core
Core core = new Core(new MutableSettings(), this.context);
((DefaultContext)this.context).put(Core.ROLE, core);
- CoreUtil.RootServiceManager rsm = new CoreUtil.RootServiceManager(null, core);
+ SingleComponentServiceManager rsm = new SingleComponentServiceManager(null, core, Core.ROLE);
// Set up the ComponentLocator
CoreServiceManager ecManager = new CoreServiceManager(rsm);
Modified: cocoon/trunk/src/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/WEB-INF/web.xml?rev=225167&r1=225166&r2=225167&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/WEB-INF/web.xml (original)
+++ cocoon/trunk/src/webapp/WEB-INF/web.xml Mon Jul 25 12:24:01 2005
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2004 The Apache Software Foundation
+ Copyright 1999-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@
This parameter indicates the configuration file of the LogKit management
-->
<init-param>
- <param-name>logkit-config</param-name>
+ <param-name>logging-config</param-name>
<param-value>/WEB-INF/logkit.xconf</param-value>
</init-param>
@@ -150,16 +150,12 @@
-->
<!--
- If you want to configure log4j using Cocoon, then you can define
- an XML configuration file here. You can use the usual log4j property
- substituation mechanism, e.g. ${context-root} is replaced by the
- context root of this web application etc.
- You can configure the log4j configuration even if you use LogKit
- for Cocoon logging. You can use this to configure third party code
- for example.
+ If you want to configure log4j using Cocoon, you can use the
+ following configuration. In this case the log configured defined
+ by the logging-config init parameter is used to initialize Log4J!
<init-param>
- <param-name>log4j-config</param-name>
- <param-value>/WEB-INF/log4j.xconf</param-value>
+ <param-name>logger-class</param-name>
+ <param-value>org.apache.avalon.excalibur.logger.Log4JConfLoggerManager</param-value>
</init-param>
-->