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/06/30 18:15:42 UTC
svn commit: r208645 - in /cocoon:
blocks/portal/trunk/java/org/apache/cocoon/portlet/
trunk/src/java/org/apache/cocoon/core/
trunk/src/java/org/apache/cocoon/servlet/
trunk/src/java/org/apache/cocoon/util/log/
Author: cziegeler
Date: Thu Jun 30 09:15:40 2005
New Revision: 208645
URL: http://svn.apache.org/viewcvs?rev=208645&view=rev
Log:
Reduce dependency to LogKit
Make settings available to Log4J configuration
Modified:
cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
cocoon/trunk/src/java/org/apache/cocoon/util/log/Log4JConfigurator.java
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=208645&r1=208644&r2=208645&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 Thu Jun 30 09:15:40 2005
@@ -906,7 +906,7 @@
// let's configure log4j
final String log4jConfig = getInitParameter("log4j-config", null);
if ( log4jConfig != null ) {
- final Log4JConfigurator configurator = new Log4JConfigurator(subcontext);
+ final Log4JConfigurator configurator = new Log4JConfigurator(subcontext, null);
// test if this is a qualified url
InputStream is = null;
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=208645&r1=208644&r2=208645&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java Thu Jun 30 09:15:40 2005
@@ -49,12 +49,14 @@
import org.apache.cocoon.components.container.ComponentContext;
import org.apache.cocoon.configuration.ConfigurationBuilder;
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.TraversableSource;
+import org.apache.log.ContextMap;
import org.apache.log4j.LogManager;
/**
@@ -367,6 +369,35 @@
return s;
}
+ /**
+ * Initialize the context for logging.
+ * TODO - Move this to the logger manager and make it LogKit independent.
+ */
+ 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;
+ }
+
+ /**
+ * Initialize the context for logging.
+ */
+ public void cleanPerRequestLoggingContext(Object ctxMap) {
+ if ( ctxMap != null ) {
+ ((ContextMap)ctxMap).clear();
+ }
+ }
+
protected void initLogger() {
String logLevel = settings.getBootstrapLogLevel();
if (logLevel == null) {
@@ -502,7 +533,7 @@
// let's configure log4j
final String log4jConfig = settings.getLog4jConfiguration();
if (log4jConfig != null) {
- final Log4JConfigurator configurator = new Log4JConfigurator(subcontext);
+ final Log4JConfigurator configurator = new Log4JConfigurator(subcontext, this.settings);
Source source = null;
try {
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=208645&r1=208644&r2=208645&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java Thu Jun 30 09:15:40 2005
@@ -63,7 +63,6 @@
import org.apache.cocoon.util.IOUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.time.StopWatch;
-import org.apache.log.ContextMap;
/**
* This is the entry point for Cocoon execution as an HTTP Servlet.
@@ -353,7 +352,7 @@
}
String contentType = null;
- ContextMap ctxMap = null;
+ Object ctxMap = null;
Environment env;
try{
@@ -375,16 +374,7 @@
try {
try {
- // 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());
+ ctxMap = this.coreUtil.initializePerRequestLoggingContext(env);
if (this.cocoon.process(env)) {
contentType = env.getContentType();
@@ -469,9 +459,7 @@
}
}
} finally {
- if (ctxMap != null) {
- ctxMap.clear();
- }
+ this.coreUtil.cleanPerRequestLoggingContext(ctxMap);
try {
if (request instanceof MultipartHttpServletRequest) {
Modified: cocoon/trunk/src/java/org/apache/cocoon/util/log/Log4JConfigurator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/util/log/Log4JConfigurator.java?rev=208645&r1=208644&r2=208645&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/util/log/Log4JConfigurator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/util/log/Log4JConfigurator.java Thu Jun 30 09:15:40 2005
@@ -17,6 +17,7 @@
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
+import org.apache.cocoon.core.Settings;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.xml.DOMConfigurator;
@@ -28,10 +29,12 @@
*/
public class Log4JConfigurator extends DOMConfigurator {
- protected Context context;
-
- public Log4JConfigurator(Context context) {
+ protected final Context context;
+ protected final Settings settings;
+
+ public Log4JConfigurator(Context context, Settings settings) {
this.context = context;
+ this.settings = settings;
}
protected String subst(String value) {
@@ -81,8 +84,8 @@
}
j += DELIM_START_LEN;
String key = val.substring(j, k);
- // first try in System properties
- String replacement = this.getSystemProperty(key);
+ // first try in settigns and system properties
+ String replacement = this.getProperty(key);
// then try props parameter
if (replacement == null && this.context != null) {
try {
@@ -112,12 +115,19 @@
* This is directly copied from log4j's OptionConverter class.
* The only difference is the getting of a property.
*/
- public String getSystemProperty(String key) {
- try {
- return System.getProperty(key, null);
- } catch(Throwable e) { // MS-Java throws com.ms.security.SecurityExceptionEx
- LogLog.debug("Was not allowed to read system property \""+key+"\".");
- return null;
+ protected String getProperty(String key) {
+ String value = null;
+ if ( this.settings != null ) {
+ value = this.settings.getProperty(key);
+ }
+ if ( value == null ) {
+ try {
+ value = System.getProperty(key, null);
+ } catch(Throwable e) { // MS-Java throws com.ms.security.SecurityExceptionEx
+ LogLog.debug("Was not allowed to read system property \""+key+"\".");
+ value = null;
+ }
}
+ return value;
}
}