Author: berndf
Date: Mon Sep 17 08:26:09 2007
New Revision: 576478

URL: http://svn.apache.org/viewvc?rev=576478&view=rev
Log:
make log4j the default logging framework, log to a file and to console

Added:
    james/server/sandbox/spring-integration/spring-deployment/lib/log4j/
    
james/server/sandbox/spring-integration/spring-deployment/lib/log4j/log4j-1.2.15.jar
   (with props)
    
james/server/sandbox/spring-integration/spring-deployment/src/main/config/log4j.properties
    
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/
    
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/AvalonToLog4jLogger.java
    
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/LoggerToComponentMapper.java
Modified:
    james/server/sandbox/spring-integration/spring-deployment/build.xml
    
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
    
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/LoggerPropagator.java

Modified: james/server/sandbox/spring-integration/spring-deployment/build.xml
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/build.xml?rev=576478&r1=576477&r2=576478&view=diff
==============================================================================
--- james/server/sandbox/spring-integration/spring-deployment/build.xml 
(original)
+++ james/server/sandbox/spring-integration/spring-deployment/build.xml Mon Sep 
17 08:26:09 2007
@@ -169,11 +169,18 @@
         </fileset>
     </path>
 
+    <path id="classpath.misc">
+        <fileset dir="${basedir}/lib/log4j">
+            <include name="log4j-1.2.15.jar"/>
+        </fileset>
+    </path>
+
     <path id="classpath.all.libs">
         <path refid="classpath.phoenix.runtime" />
         <path refid="classpath.phoenix.implementations" />
         <path refid="classpath.james.target" />
         <path refid="classpath.spring" />
+        <path refid="classpath.misc" />
     </path>
 
     <path id="runclasspath">

Added: 
james/server/sandbox/spring-integration/spring-deployment/lib/log4j/log4j-1.2.15.jar
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/lib/log4j/log4j-1.2.15.jar?rev=576478&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
james/server/sandbox/spring-integration/spring-deployment/lib/log4j/log4j-1.2.15.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: 
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml?rev=576478&r1=576477&r2=576478&view=diff
==============================================================================
--- 
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
 (original)
+++ 
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
 Mon Sep 17 08:26:09 2007
@@ -41,11 +41,23 @@
         </property>
     </bean>
 
+    <!--
+        Logging to log4j
+    -->
+    <bean id="logger" 
class="org.apache.james.container.spring.logging.log4j.LoggerToComponentMapper" 
init-method="init">
+        <property name="configurationResource" value="log4j.properties"/>
+    </bean>
+    
+    <!--
+        Logging to System.out
+    -->
+    <!--
     <bean name="logWorker" 
class="org.apache.james.container.spring.logging.SystemConsoleLogWorker" />
 
     <bean name="logger, loggerMap" 
class="org.apache.james.container.spring.adaptor.LoggingBridge" >
         <property name="logWorker" ref="logWorker" />
     </bean>
+    -->
 
     <!-- 
          maps the default standard ports for SMTP, POP3, IMAP, NNTP to 
non-privileged ports in the
@@ -132,7 +144,7 @@
          beans managing bootstrapping and component lifecycle
     -->
     <bean id="loggerPropagator" 
class="org.apache.james.container.spring.lifecycle.LoggerPropagator" >
-        <property name="loggingBridge" ref="logger"/>
+        <property name="loggerFactory" ref="logger"/>
     </bean>
 
     <bean id="contextPropagator" 
class="org.apache.james.container.spring.lifecycle.ContextPropagator" >

Added: 
james/server/sandbox/spring-integration/spring-deployment/src/main/config/log4j.properties
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/config/log4j.properties?rev=576478&view=auto
==============================================================================
--- 
james/server/sandbox/spring-integration/spring-deployment/src/main/config/log4j.properties
 (added)
+++ 
james/server/sandbox/spring-integration/spring-deployment/src/main/config/log4j.properties
 Mon Sep 17 08:26:09 2007
@@ -0,0 +1,18 @@
+log4j.rootLogger=DEBUG
+
+log4j.appender.CONS=org.apache.log4j.ConsoleAppender
+log4j.appender.CONS.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONS.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n
+
+log4j.appender.FILE=org.apache.log4j.RollingFileAppender
+log4j.appender.FILE.File=log/james-server.log
+log4j.appender.FILE.MaxFileSize=1GB
+log4j.appender.FILE.MaxBackupIndex=40
+log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.FILE.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n
+
+log4j.logger.org.springframework=WARN, CONS, FILE
+log4j.logger.org.apache.james=DEBUG, CONS, FILE
+log4j.logger.james=DEBUG, CONS, FILE
+log4j.logger=DEBUG, CONS, FILE
+

Modified: 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/LoggerPropagator.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/LoggerPropagator.java?rev=576478&r1=576477&r2=576478&view=diff
==============================================================================
--- 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/LoggerPropagator.java
 (original)
+++ 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/LoggerPropagator.java
 Mon Sep 17 08:26:09 2007
@@ -18,9 +18,9 @@
  ****************************************************************/
 package org.apache.james.container.spring.lifecycle;
 
-import org.apache.avalon.framework.logger.LogEnabled;
 import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.container.spring.adaptor.LoggingBridge;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.james.container.spring.logging.LoggerToComponentMapper;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.core.Ordered;
@@ -30,21 +30,21 @@
  */
 public class LoggerPropagator extends AbstractPropagator implements 
BeanPostProcessor, Ordered {
 
-    private LoggingBridge loggingBridge;
+    private LoggerToComponentMapper loggerFactory;
 
     protected Class getLifecycleInterface() {
         return LogEnabled.class;
     }
 
     protected void invokeLifecycleWorker(String beanName, Object bean, 
BeanDefinition beanDefinition) {
-        ContainerUtil.enableLogging(bean, loggingBridge);
+        ContainerUtil.enableLogging(bean, 
loggerFactory.getComponentLogger("james." + beanName));
     }
 
     public int getOrder() {
         return 0;
     }
 
-    public void setLoggingBridge(LoggingBridge loggingBridge) {
-        this.loggingBridge = loggingBridge;
+    public void setLoggerFactory(LoggerToComponentMapper loggerFactory) {
+        this.loggerFactory = loggerFactory;
     }
 }

Added: 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/AvalonToLog4jLogger.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/AvalonToLog4jLogger.java?rev=576478&view=auto
==============================================================================
--- 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/AvalonToLog4jLogger.java
 (added)
+++ 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/AvalonToLog4jLogger.java
 Mon Sep 17 08:26:09 2007
@@ -0,0 +1,98 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.james.container.spring.logging.log4j;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+
+/**
+ * behaves like an avalon logger, but logs to log4j
+ */
+public class AvalonToLog4jLogger implements 
org.apache.avalon.framework.logger.Logger {
+    private Logger logger;
+
+    public AvalonToLog4jLogger(Logger logger) {
+        this.logger = logger;
+    }
+
+    public void debug(String s) {
+        logger.debug(s);
+    }
+
+    public void debug(String s, Throwable throwable) {
+        logger.debug(s, throwable);
+    }
+
+    public boolean isDebugEnabled() {
+        return logger.isDebugEnabled();
+    }
+
+    public void info(String s) {
+        logger.info(s);
+    }
+
+    public void info(String s, Throwable throwable) {
+        logger.info(s, throwable);
+    }
+
+    public boolean isInfoEnabled() {
+        return logger.isEnabledFor(Level.INFO);
+    }
+
+    public void warn(String s) {
+        logger.warn(s);
+    }
+
+    public void warn(String s, Throwable throwable) {
+        logger.warn(s, throwable);
+    }
+
+    public boolean isWarnEnabled() {
+        return logger.isEnabledFor(Level.WARN);
+    }
+
+    public void error(String s) {
+        logger.error(s);
+    }
+
+    public void error(String s, Throwable throwable) {
+        logger.error(s, throwable);
+    }
+
+    public boolean isErrorEnabled() {
+        return logger.isEnabledFor(Level.ERROR);
+    }
+
+    public void fatalError(String s) {
+        logger.fatal(s);
+    }
+
+    public void fatalError(String s, Throwable throwable) {
+        logger.fatal(s, throwable);
+    }
+
+    public boolean isFatalErrorEnabled() {
+        return logger.isEnabledFor(Level.FATAL);
+    }
+
+    public org.apache.avalon.framework.logger.Logger getChildLogger(String s) {
+        return new AvalonToLog4jLogger(Logger.getLogger(s));
+    }
+}

Added: 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/LoggerToComponentMapper.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/LoggerToComponentMapper.java?rev=576478&view=auto
==============================================================================
--- 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/LoggerToComponentMapper.java
 (added)
+++ 
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/logging/log4j/LoggerToComponentMapper.java
 Mon Sep 17 08:26:09 2007
@@ -0,0 +1,59 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.james.container.spring.logging.log4j;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.PropertyConfigurator;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
+import org.springframework.core.io.Resource;
+
+import java.util.Properties;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * simple default implementation. change the log4j configuration file to 
change specific logging behavior
+ */
+public class LoggerToComponentMapper implements 
org.apache.james.container.spring.logging.LoggerToComponentMapper {
+    private Resource propertiesResource;
+
+    public LoggerToComponentMapper() {
+    }
+
+    public void setConfigurationResource(Resource propertiesResource) {
+        this.propertiesResource = propertiesResource;    
+    }
+    
+    public void init() {
+        Properties properties;
+        URL url = null;
+        try {
+            url = propertiesResource.getURL();
+            properties = 
PropertiesLoaderUtils.loadProperties(propertiesResource);
+        } catch (IOException e) {
+            throw new RuntimeException("failed to load log4j properties from " 
+ url);
+        }
+        PropertyConfigurator.configure(properties);
+    } 
+    
+    public Logger getComponentLogger(String beanName) {
+        return new 
AvalonToLog4jLogger(org.apache.log4j.Logger.getLogger(beanName));
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to