diff options
author | Glyn Normington | 2010-04-20 14:38:13 +0000 |
---|---|---|
committer | Glyn Normington | 2010-04-20 14:38:13 +0000 |
commit | 1fe315346425dcdea73feebd431aba7ae2a75f61 (patch) | |
tree | 617c48f3ec41fb2cde58e215bc42bc2b3a5d8678 /org.eclipse.virgo.medic/src/main/java/org | |
download | org.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')
14 files changed, 658 insertions, 0 deletions
diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/Dump.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/Dump.java new file mode 100644 index 0000000..2d631c2 --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/Dump.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.dump; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.Writer; +import java.util.Map; + +/** + * A <code>Dump</code> represents a dump being generated by a {@link DumpGenerator}. During dump generation + * {@link DumpContributor DumpContributors} are called to contribute to the dump. Contributors can request a + * {@link Writer}, {@link File}, etc. which they may use to write out their contribution to the dump. + */ +public interface Dump { + + /** + * Returns a timestamp that identifies that time at which this dump was generated. + * + * @return The timestamp of the dump's generation + */ + long getTimestamp(); + + /** + * Returns the context that is associated with this dump. If there is no associated context an empty + * <code>Map</code> is returned. + * + * @return The dump's context + */ + Map<String, Object> getContext(); + + /** + * Returns the {@link Throwable Throwables} associated with this dump. + * + * @return The dump's <code>Throwable</code>s + */ + Throwable[] getThrowables(); + + /** + * Returns the cause of this dump. + * + * @return The dump's cause. + */ + String getCause(); + + /** + * Creates a {@link FileWriter} that writes to a file with the supplied name, within this dump's output location. + * @param name of file to write to + * + * @return a <code>FileWriter</code> to which a contribution to the dump can be written + * @throws DumpContributionFailedException + */ + FileWriter createFileWriter(String name) throws DumpContributionFailedException; + + /** + * Creates a {@link FileOutputStream} that writes to a file with the supplied name, within this dump's output + * location. + * @param name of file to write to + * + * @return a <code>FileOutputStream</code> to which a contribution to the dump can be written + * @throws DumpContributionFailedException + */ + FileOutputStream createFileOutputStream(String name) throws DumpContributionFailedException; + + /** + * Creates a {@link File} with the supplied name, within this dump's output location. + * @param name of file to write to + * + * @return a <code>File</code> to which a contribution to the dump can be written + */ + File createFile(String name); + +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpContributionFailedException.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpContributionFailedException.java new file mode 100644 index 0000000..edaf464 --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpContributionFailedException.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.dump; + +/** + * A <code>DumpContributionFailedException</code> is thrown by a {@link DumpContributor} to indicate that a failure has + * occurred when it was attempting to make a contribution to a dump. + * <p /> + * + * <strong>Concurrent Semantics</strong><br /> + * Thread-safe. + * + */ +public class DumpContributionFailedException extends DumpGenerationFailedException { + + private static final long serialVersionUID = -3196511149954617337L; + + /** + * Create a new DumpContributionFailedException with the supplied message that describes the failure + * + * @param message The message describing the failure + */ + public DumpContributionFailedException(String message) { + super(message); + } + + /** + * Create a new DumpContributionFailedException with the supplied failure cause and message that describes the + * failure + * + * @param message The message describing the failure + * @param cause The cause of the contribution failure + */ + public DumpContributionFailedException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpContributor.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpContributor.java new file mode 100644 index 0000000..ddffe7c --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpContributor.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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.dump; + +/** + * A <code>DumpContributor</code> is implemented to contribute information to a dump. Contributors are 'registered' with + * a {@link DumpGenerator} by publishing them in the service registry. + * <p /> + * + * <strong>Concurrent Semantics</strong><br /> + * <code>DumpContributor</code>s must be thread-safe. + */ +public interface DumpContributor { + + /** + * Contribute to the supplied {@link Dump}. + * + * @param dump The dump to which a contribution may be made. + * @throws DumpContributionFailedException if the dump contribution cannot be created + */ + void contribute(Dump dump) throws DumpContributionFailedException; + + /** + * Returns the name of this <code>DumpContributor</code>. The name is used by a {@link DumpGenerator} when + * determining which contributors should be excluded from contributing to a dump. + * + * @return The contributor's name + */ + String getName(); +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpGenerationFailedException.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpGenerationFailedException.java new file mode 100644 index 0000000..5dded04 --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpGenerationFailedException.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.dump; + +/** + * A <code>DumpGenerationFailedException</code> is thrown by a {@link DumpGenerator} to indicate that a failure has + * occurred during dump generation. + * + * <p /> + * + * <strong>Concurrent Semantics</strong><br /> + * Thread-safe. + * + */ +public class DumpGenerationFailedException extends Exception { + + private static final long serialVersionUID = -3196511149954617337L; + + /** + * Create a new DumpGenerationFailedException with the supplied message that describes the failure + * + * @param message The message describing the failure + */ + public DumpGenerationFailedException(String message) { + super(message); + } + + /** + * Create a new DumpGenerationFailedException with the supplied failure cause and message that describes the failure + * + * @param message The message describing the failure + * @param cause The cause of the generation failure + */ + public DumpGenerationFailedException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpGenerator.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpGenerator.java new file mode 100644 index 0000000..c07f9bc --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/dump/DumpGenerator.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.dump; + +import java.util.Map; + +/** + * A <code>DumpGenerator</code> can be used to request the generation of a dump. A + * <code>DumpGenerator</code> instance can be obtained from the service registry. + * <p /> + * + * When a dump is requested, the <code>DumpGenerator</code> will, by default, provide all {@link DumpContributor}s + * that are known to it with an opportunity to contribute to the dump. <code>DumpContributor</code> + * instances are made known to a {@link DumpGenerator} by publishing them in the service registry. + * <p /> + * + * A {@link DumpGenerator} can be configured to exclude {@link DumpContributor}s from contributing to dumps + * with a particular cause. <br/> + * TODO Expand the documentation on contributor exclusion + * <p /> + * + * <strong>Concurrent Semantics</strong><br /> + * <code>DumpGenerator</code>s must be thread-safe. + */ +public interface DumpGenerator { + + /** + * Generates a dump + * + * @param cause the cause of the dump + * @param throwables {@link Throwable} instances to be associated with the dump + */ + void generateDump(String cause, Throwable... throwables); + + /** + * Generates a dump, with additional context. + * + * @param cause the cause of the dump + * @param context additional context that can be used by the {@link DumpContributor}s + * @param throwables {@link Throwable} instances to be associated with the dump + */ + void generateDump(String cause, Map<String, Object> context, Throwable... throwables); +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/EventLogger.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/EventLogger.java new file mode 100644 index 0000000..1ffd641 --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/EventLogger.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * 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.eventlog; + +import java.util.ResourceBundle; + +/** + * An <code>EventLogger</code> provides support for logging events as human-readable, potentially internationalized, + * messages identified by a unique code. + * <p /> + * An <code>EventLogger</code> instance can be obtained directly from the service registry. Such instances will search + * the {@link org.osgi.framework.Bundle} that obtained the instance, and the <code>EventLogger</code> implementations <code>Bundle</code> + * for a properties file that contains entry for the an event's code. The implementation bundle is searched to support + * providing properties files in fragment bundles which are attached to the implementation. + * <p /> + * Alternatively, an <code>EventLogger</code> can be obtained from an {@link EventLoggerFactory} allowing a specific + * <code>Bundle</code> to be supplied that will be used to search for properties files. + * <p /> + * The algorithm used to find properties files matches that described in + * {@link ResourceBundle#getBundle(String, java.util.Locale, ClassLoader) ResourceBundle}, with the exception that no + * searching for class files is performed. + * <p /> + * <strong>Concurrent Semantics</strong><br /> + * Implementations <strong>must</strong> be thread-safe. + */ +public interface EventLogger { + + /** + * Logs an event in the form of a message identified by the supplied code. The message is resolved by searching the + * available {@link ResourceBundle ResourceBundles} for an entry with the key that matches the code. + * + * The event is logged at the supplied level, with the supplied inserts being applied to the message. + * + * @param code The code of the message to be logged + * @param level The level at which the event should be logged + * @param inserts The inserts for the message + */ + void log(String code, Level level, Object... inserts); + + /** + * Logs an event in the form of a message identified by the supplied code. The message is resolved by searching the + * available {@link ResourceBundle ResourceBundles} for an entry with the key that matches the code. + * + * The event is logged at the supplied level, with the supplied inserts being applied to the message. + * + * @param logEvent The log event to be logged + * @param inserts The inserts for the message + */ + void log(LogEvent logEvent, Object... inserts); + + /** + * Logs an event in the form of a message identified by the supplied code. The message is resolved by searching the + * available {@link ResourceBundle ResourceBundles} for an entry with the key that matches the code. + * + * The event is logged at the supplied level, with the supplied inserts being applied to the message. The supplied + * <code>Throwable</code> is logged with the message. + * + * @param code The code of the message to be logged + * @param level The level at which the event should be logged + * @param throwable The <code>Throwable</code> to be logged + * @param inserts The inserts for the message + */ + void log(String code, Level level, Throwable throwable, Object... inserts); + + /** + * Logs an event in the form of a message identified by the supplied code. The message is resolved by searching the + * available {@link ResourceBundle ResourceBundles} for an entry with the key that matches the code. + * + * The event is logged at the supplied level, with the supplied inserts being applied to the message. The supplied + * <code>Throwable</code> is logged with the message. + * + * @param logEvent The log event to be logged + * @param throwable The <code>Throwable</code> to be logged + * @param inserts The inserts for the message + */ + void log(LogEvent logEvent, Throwable throwable, Object... inserts); +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/EventLoggerFactory.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/EventLoggerFactory.java new file mode 100644 index 0000000..da99120 --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/EventLoggerFactory.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.eventlog; + +import java.util.ResourceBundle; + +import org.osgi.framework.Bundle; + +/** + * An <code>EventLoggerFactory</code> is used to create an <code>EventLogger</code> instance that will search a specific + * bundle, in addition to the EventLogger implementation's bundle, for {@link ResourceBundle ResourceBundles}. + * <p /> + * <strong>Concurrent Semantics</strong><br /> + * Implementations <strong>must</strong> be thread-safe. + */ +public interface EventLoggerFactory { + + /** + * Creates a new <code>EventLogger</code> that will search the supplied bundle, in addition to the + * <code>EventLogger</code> implementation's bundle, for {@link ResourceBundle ResourceBundles}. + * + * @param bundle The <code>Bundle</code> to search for <code>ResourceBundle</code>s. + * + * @return The <code>EventLogger</code> + */ + public EventLogger createEventLogger(Bundle bundle); +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/Level.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/Level.java new file mode 100644 index 0000000..b8d9eae --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/Level.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * 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.eventlog; + +public enum Level { + ERROR, WARNING, INFO +} diff --git a/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/LogEvent.java b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/LogEvent.java new file mode 100644 index 0000000..3387160 --- /dev/null +++ b/org.eclipse.virgo.medic/src/main/java/org/eclipse/virgo/medic/eventlog/LogEvent.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.eventlog; + +/** + * A <code>LogEvent</code> encapsulates the details of an event that is to be logged. + * <p/> + * + * <strong>Concurrent Semantics</strong><br /> + * Implementations <strong>must</strong> be thread-safe. + * + */ +public interface LogEvent { + + /** + * Returns the code that uniquely identifies this <code>LogEvent</code>. Typically, this code is used to locate the + * message for the event in a resource bundle. + * + * @return The event's code + */ + public String getEventCode(); + + /** + * Returns the {@link Level} at which this <code>LogEvent</code> should be published. + * + * @return The level of the event. + */ + public Level getLevel(); +} 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; +} |