Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2010-04-20 14:38:13 +0000
committerGlyn Normington2010-04-20 14:38:13 +0000
commit1fe315346425dcdea73feebd431aba7ae2a75f61 (patch)
tree617c48f3ec41fb2cde58e215bc42bc2b3a5d8678 /org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log
downloadorg.eclipse.virgo.medic-1fe315346425dcdea73feebd431aba7ae2a75f61.tar.gz
org.eclipse.virgo.medic-1fe315346425dcdea73feebd431aba7ae2a75f61.tar.xz
org.eclipse.virgo.medic-1fe315346425dcdea73feebd431aba7ae2a75f61.zip
[bug 307650] initial check-in from dm Server Virgo medic 0a647883a0176f60d8572f51c7eff591b7e408b6
Diffstat (limited to 'org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log')
-rw-r--r--org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/ConfigurationPublicationFailedException.java30
-rw-r--r--org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/DelegatingPrintStream.java34
-rw-r--r--org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/EntryExitTrace.aj99
-rw-r--r--org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfiguration.java19
-rw-r--r--org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfigurationPublisher.java34
5 files changed, 216 insertions, 0 deletions
diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/ConfigurationPublicationFailedException.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/ConfigurationPublicationFailedException.java
new file mode 100644
index 0000000..e2bbf0e
--- /dev/null
+++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/ConfigurationPublicationFailedException.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.log;
+
+/**
+ * Thrown by {@link LoggingConfigurationPublisher} when a request to publish logging configuration fails.
+ */
+public class ConfigurationPublicationFailedException extends Exception {
+
+ private static final long serialVersionUID = 4317804271280636565L;
+
+ /**
+ * Creates a new exception with the supplied message and cause.
+ *
+ * @param message The exception's message
+ * @param cause The exception's cause
+ */
+ public ConfigurationPublicationFailedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/DelegatingPrintStream.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/DelegatingPrintStream.java
new file mode 100644
index 0000000..131f597
--- /dev/null
+++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/DelegatingPrintStream.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.log;
+
+import java.io.PrintStream;
+
+/**
+ * A <code>DelegatingPrintStream</code> is a {@link PrintStream} implementation that delegates to another
+ * {@link PrintStream} instance and allows the delegate to be changed at runtime.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * Thread-safe.
+ *
+ */
+public interface DelegatingPrintStream {
+
+ /**
+ * Sets the {@link PrintStream} to be used as a delegate. The given <code>printStream</code> may be
+ * <code>null</code> to disable delegation.
+ *
+ * @param printStream The delegate, or <code>null</code> to disable delegation.
+ */
+ void setDelegate(PrintStream printStream);
+}
diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/EntryExitTrace.aj b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/EntryExitTrace.aj
new file mode 100644
index 0000000..5e4d2c0
--- /dev/null
+++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/EntryExitTrace.aj
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.log;
+
+import org.aspectj.lang.JoinPoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An aspect that will advise any method with entry and exit trace logging.
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Threadsafe
+ *
+ */
+public aspect EntryExitTrace pertypewithin(*) {
+
+ private volatile Logger logger;
+
+ pointcut performingEntryExitTrace() : cflowbelow(adviceexecution() && within(EntryExitTrace));
+
+ pointcut medic() : within(org.eclipse.virgo.medic..*);
+
+ pointcut util() : within(org.eclipse.virgo.util..*);
+
+ pointcut logback() : within(ch.qos.logback..*) || within(org.slf4j.impl..*);
+
+ pointcut infoCandidate() : execution(public * *(..)) && !medic() && !util() && !logback() && !performingEntryExitTrace();
+
+ pointcut debugCandidate() : execution(!public !private * *(..)) && !medic() && !util() && !logback() && !performingEntryExitTrace();
+
+ pointcut traceCandidate() : execution(private * *(..)) && !medic() && !util() && !logback() && !performingEntryExitTrace();
+
+ before() : infoCandidate() {
+ getLogger(thisJoinPointStaticPart).info("{} {}", ">", getSignature(thisJoinPointStaticPart));
+ }
+
+ after() returning : infoCandidate() {
+ getLogger(thisJoinPointStaticPart).info("{} {}", "<", getSignature(thisJoinPointStaticPart));
+ }
+
+ after() throwing(Throwable t) : infoCandidate() {
+ Logger logger = getLogger(thisJoinPointStaticPart);
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("< %s", getSignature(thisJoinPointStaticPart)), t);
+ }
+ }
+
+ before() : debugCandidate() {
+ getLogger(thisJoinPointStaticPart).debug("{} {}", ">", getSignature(thisJoinPointStaticPart));
+ }
+
+ after() returning : debugCandidate() {
+ getLogger(thisJoinPointStaticPart).debug("{} {}", "<", getSignature(thisJoinPointStaticPart));
+ }
+
+ after() throwing(Throwable t) : debugCandidate() {
+ Logger logger = getLogger(thisJoinPointStaticPart);
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("< %s", getSignature(thisJoinPointStaticPart)), t);
+ }
+ }
+
+ before() : traceCandidate() {
+ getLogger(thisJoinPointStaticPart).trace("{} {}", ">", getSignature(thisJoinPointStaticPart));
+ }
+
+ after() returning : traceCandidate() {
+ getLogger(thisJoinPointStaticPart).trace("{} {}", "<", getSignature(thisJoinPointStaticPart));
+ }
+
+ after() throwing(Throwable t) : traceCandidate() {
+ Logger logger = getLogger(thisJoinPointStaticPart);
+ if (logger.isTraceEnabled()) {
+ logger.trace(String.format("< %s", getSignature(thisJoinPointStaticPart)), t);
+ }
+ }
+
+ private Logger getLogger(JoinPoint.StaticPart sp) {
+ if (this.logger == null) {
+ this.logger = LoggerFactory.getLogger(sp.getSignature().getDeclaringType());
+ }
+ return this.logger;
+ }
+
+ private String getSignature(JoinPoint.StaticPart sp) {
+ return sp.getSignature().toLongString();
+ }
+}
diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfiguration.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfiguration.java
new file mode 100644
index 0000000..4156c90
--- /dev/null
+++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfiguration.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.log;
+
+public interface LoggingConfiguration {
+
+ String getConfiguration();
+
+ String getName();
+}
diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfigurationPublisher.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfigurationPublisher.java
new file mode 100644
index 0000000..e0d3c90
--- /dev/null
+++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfigurationPublisher.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.medic.log;
+
+import java.io.File;
+
+/**
+ * A <code>LoggingConfigurationPublisher</code> is used to publish {@link LoggingConfiguration} into the service
+ * registry. <code>LoggingConfiguration</code> instances in the service registry are referenced by bundles using the
+ * <code>Medic-LoggingConfiguration</code> manifest header.
+ */
+public interface LoggingConfigurationPublisher {
+
+ /**
+ * Publishes the configuration in the supplied <code>File</code> as a <code>LoggingConfiguration</code> instance,
+ * identified with the supplied id. The published configuration can then be referenced by a bundle using the
+ * <code>Medic-LoggingConfiguration</code> manifest header with a value equal to the supplied id.
+ *
+ * @param configuration The configuration to be published
+ * @param id The identifier to be applied to the configuration when its published
+ *
+ * @throws ConfigurationPublicationFailedException if the publication of the configuration fails
+ */
+ void publishConfiguration(File configuration, String id) throws ConfigurationPublicationFailedException;
+}

Back to the top