activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1051972 - in /activemq/trunk: activemq-core/src/main/java/org/apache/activemq/broker/jmx/ activemq-core/src/main/java/org/apache/activemq/broker/util/ activemq-web/src/main/java/org/apache/activemq/web/
Date Wed, 22 Dec 2010 16:28:35 GMT
Author: dejanb
Date: Wed Dec 22 16:28:35 2010
New Revision: 1051972

URL: http://svn.apache.org/viewvc?rev=1051972&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3100 - refactoring to enable different logger implementations

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
    activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java?rev=1051972&r1=1051971&r2=1051972&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
Wed Dec 22 16:28:35 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.broker.jmx;
 
+import org.apache.activemq.broker.util.AuditLog;
+import org.apache.activemq.broker.util.DefaultAuditLog;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -40,6 +42,7 @@ public class AnnotatedMBean extends Stan
   private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
 
   private static boolean audit;
+  private static AuditLog auditLog;
 
   static {
     Class<?>[] p = { byte.class, short.class, int.class, long.class, float.class, double.class,
char.class, boolean.class, };
@@ -47,6 +50,7 @@ public class AnnotatedMBean extends Stan
       primitives.put(c.getName(), c);
     }
     audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
+    auditLog = DefaultAuditLog.getAuditLog();
   }
   
   @SuppressWarnings("unchecked")
@@ -172,7 +176,7 @@ public class AnnotatedMBean extends Stan
                     caller += principal.getName() + " ";
                 }
             }
-            LOG.info(caller.trim() + " called " + this.getMBeanInfo().getClassName() + "."
+ s  + Arrays.toString(objects));
+            auditLog.log(caller.trim() + " called " + this.getMBeanInfo().getClassName()
+ "." + s  + Arrays.toString(objects));
         }
         return super.invoke(s, objects, strings);
     }

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java?rev=1051972&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
(added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
Wed Dec 22 16:28:35 2010
@@ -0,0 +1,24 @@
+/**
+ * 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.activemq.broker.util;
+
+public interface AuditLog {
+
+    public void log(String message);
+
+}

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java?rev=1051972&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
(added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
Wed Dec 22 16:28:35 2010
@@ -0,0 +1,41 @@
+/**
+ * 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.activemq.broker.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class DefaultAuditLog implements AuditLog {
+
+    private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
+
+    public static AuditLog getAuditLog() {
+        String auditLogClass = System.getProperty("org.apache.activemq.audit.class", "org.apache.activemq.broker.util.DefaultAuditLog");
+        AuditLog log;
+        try {
+            log = (AuditLog) Class.forName(auditLogClass).newInstance();
+        } catch (Exception e) {
+            LOG.warn("Cannot instantiate audit log class '" + auditLogClass + "', using default
audit log", e);
+            log = new DefaultAuditLog();
+        }
+        return log;
+    }
+
+    public void log(String message) {
+         LOG.info(message);
+    }
+}

Modified: activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java?rev=1051972&r1=1051971&r2=1051972&view=diff
==============================================================================
--- activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java (original)
+++ activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java Wed
Dec 22 16:28:35 2010
@@ -16,13 +16,14 @@
  */
 package org.apache.activemq.web;
 
+import org.apache.activemq.broker.util.AuditLog;
+import org.apache.activemq.broker.util.DefaultAuditLog;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.servlet.*;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Enumeration;
 
 public class AuditFilter implements Filter {
@@ -30,9 +31,11 @@ public class AuditFilter implements Filt
     private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
 
     private boolean audit;
+    private AuditLog auditLog;
 
     public void init(FilterConfig filterConfig) throws ServletException {
-       audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
+        audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
+        auditLog = DefaultAuditLog.getAuditLog();
     }
 
     public void destroy() {
@@ -53,7 +56,7 @@ public class AuditFilter implements Filt
             if (http.getRemoteUser() != null) {
                 user = http.getRemoteUser();
             }
-            LOG.info(user + " requested " + http.getRequestURI() + " [" + formattedParams
+ "] from " + http.getRemoteAddr());
+            auditLog.log(user + " requested " + http.getRequestURI() + " [" + formattedParams
+ "] from " + http.getRemoteAddr());
         }
         chain.doFilter(request, response);
     }



Mime
View raw message