001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.aop.aspectj;
018:
019: import org.apache.commons.logging.Log;
020: import org.apache.commons.logging.LogFactory;
021: import org.aspectj.bridge.AbortException;
022: import org.aspectj.bridge.IMessage;
023: import org.aspectj.bridge.IMessage.Kind;
024: import org.aspectj.bridge.IMessageHandler;
025:
026: /**
027: * Implementation of AspectJ's {@link IMessageHandler} interface that
028: * routes AspectJ weaving messages through the same logging system as the
029: * regular Spring messages.
030: *
031: * <p>Pass the option...
032: *
033: * <p><code class="code">-XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler</code>
034: *
035: * <p>to the weaver; for example, specifying the following in a
036: * "<code>META-INF/aop.xml</code> file:
037: *
038: * <p><code class="code"><weaver options="..."/></code>
039: *
040: * @author Adrian Colyer
041: * @author Juergen Hoeller
042: * @since 2.0
043: */
044: public class AspectJWeaverMessageHandler implements IMessageHandler {
045:
046: private static final String AJ_ID = "[AspectJ] ";
047:
048: private static final Log LOGGER = LogFactory
049: .getLog("AspectJ Weaver");
050:
051: public boolean handleMessage(IMessage message)
052: throws AbortException {
053: Kind messageKind = message.getKind();
054:
055: if (LOGGER.isDebugEnabled() || LOGGER.isTraceEnabled()) {
056: if (messageKind == IMessage.DEBUG) {
057: LOGGER.debug(makeMessageFor(message));
058: return true;
059: }
060: }
061:
062: if (LOGGER.isInfoEnabled()) {
063: if ((messageKind == IMessage.INFO)
064: || (messageKind == IMessage.WEAVEINFO)) {
065: LOGGER.info(makeMessageFor(message));
066: return true;
067: }
068: }
069:
070: if (LOGGER.isWarnEnabled()) {
071: if (messageKind == IMessage.WARNING) {
072: LOGGER.warn(makeMessageFor(message));
073: return true;
074: }
075: }
076:
077: if (LOGGER.isErrorEnabled()) {
078: if (messageKind == IMessage.ERROR) {
079: LOGGER.error(makeMessageFor(message));
080: return true;
081: }
082: }
083:
084: if (LOGGER.isFatalEnabled()) {
085: if (messageKind == IMessage.ABORT) {
086: LOGGER.fatal(makeMessageFor(message));
087: return true;
088: }
089: }
090:
091: return false;
092: }
093:
094: private String makeMessageFor(IMessage aMessage) {
095: return AJ_ID + aMessage.getMessage();
096: }
097:
098: public boolean isIgnoring(Kind messageKind) {
099: // We want to see everything, and allow configuration of log levels dynamically.
100: return false;
101: }
102:
103: public void dontIgnore(Kind messageKind) {
104: // We weren't ignoring anything anyway...
105: }
106:
107: public void ignore(Kind kind) {
108: // We weren't ignoring anything anyway...
109: }
110:
111: }
|