From 1fe315346425dcdea73feebd431aba7ae2a75f61 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Tue, 20 Apr 2010 15:38:13 +0100 Subject: [bug 307650] initial check-in from dm Server Virgo medic 0a647883a0176f60d8572f51c7eff591b7e408b6 --- .../ConfigurationPublicationFailedException.java | 30 +++++++ .../virgo/medic/log/DelegatingPrintStream.java | 34 ++++++++ .../org/eclipse/virgo/medic/log/EntryExitTrace.aj | 99 ++++++++++++++++++++++ .../virgo/medic/log/LoggingConfiguration.java | 19 +++++ .../medic/log/LoggingConfigurationPublisher.java | 34 ++++++++ 5 files changed, 216 insertions(+) create mode 100644 org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/ConfigurationPublicationFailedException.java create mode 100644 org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/DelegatingPrintStream.java create mode 100644 org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/EntryExitTrace.aj create mode 100644 org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfiguration.java create mode 100644 org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log/LoggingConfigurationPublisher.java (limited to 'org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/log') 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 DelegatingPrintStream is a {@link PrintStream} implementation that delegates to another + * {@link PrintStream} instance and allows the delegate to be changed at runtime. + *

+ * + * Concurrent Semantics
+ * Thread-safe. + * + */ +public interface DelegatingPrintStream { + + /** + * Sets the {@link PrintStream} to be used as a delegate. The given printStream may be + * null to disable delegation. + * + * @param printStream The delegate, or null 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. + * + * Concurrent Semantics
+ * + * 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 LoggingConfigurationPublisher is used to publish {@link LoggingConfiguration} into the service + * registry. LoggingConfiguration instances in the service registry are referenced by bundles using the + * Medic-LoggingConfiguration manifest header. + */ +public interface LoggingConfigurationPublisher { + + /** + * Publishes the configuration in the supplied File as a LoggingConfiguration instance, + * identified with the supplied id. The published configuration can then be referenced by a bundle using the + * Medic-LoggingConfiguration 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; +} -- cgit v1.2.3