git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1052501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-12-24 13:09:27 +00:00
parent de66445d58
commit 1f9cc43890
4 changed files with 50 additions and 16 deletions

View File

@ -17,6 +17,7 @@
package org.apache.activemq.broker.jmx;
import org.apache.activemq.broker.util.AuditLog;
import org.apache.activemq.broker.util.AuditLogService;
import org.apache.activemq.broker.util.DefaultAuditLog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -42,7 +43,7 @@ public class AnnotatedMBean extends StandardMBean {
private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
private static boolean audit;
private static AuditLog auditLog;
private static AuditLogService auditLog;
static {
Class<?>[] p = { byte.class, short.class, int.class, long.class, float.class, double.class, char.class, boolean.class, };
@ -50,7 +51,9 @@ public class AnnotatedMBean extends StandardMBean {
primitives.put(c.getName(), c);
}
audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
auditLog = DefaultAuditLog.getAuditLog();
if (audit) {
auditLog = new AuditLogService();
}
}
@SuppressWarnings("unchecked")

View File

@ -0,0 +1,42 @@
/**
* 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 java.util.ArrayList;
import java.util.ServiceLoader;
public class AuditLogService {
private ArrayList<AuditLog> auditLogs = new ArrayList<AuditLog>();
public AuditLogService() {
ServiceLoader<AuditLog> logs = ServiceLoader.load(AuditLog.class);
for (AuditLog log : logs) {
auditLogs.add(log);
}
// add default audit log if non was found
if (auditLogs.size() == 0) {
auditLogs.add(new DefaultAuditLog());
}
}
public void log(String message) {
for (AuditLog log : auditLogs) {
log.log(message);
}
}
}

View File

@ -23,18 +23,6 @@ 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);
}

View File

@ -17,6 +17,7 @@
package org.apache.activemq.web;
import org.apache.activemq.broker.util.AuditLog;
import org.apache.activemq.broker.util.AuditLogService;
import org.apache.activemq.broker.util.DefaultAuditLog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -31,11 +32,11 @@ public class AuditFilter implements Filter {
private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
private boolean audit;
private AuditLog auditLog;
private AuditLogService auditLog;
public void init(FilterConfig filterConfig) throws ServletException {
audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
auditLog = DefaultAuditLog.getAuditLog();
auditLog = new AuditLogService();
}
public void destroy() {