001: /*
002: * Copyright 2002-2006 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 IMessageHandler interface that routes
028: * AspectJ weaving messages through the same logging system as the
029: * regular Spring messages.
030: *
031: * Pass the option
032: * "-XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler"
033: * to the weaver (for example, using <weaver options="..."/> in a
034: * "META-INF/aop.xml" file).
035: *
036: * @author Adrian Colyer
037: * @author Juergen Hoeller
038: * @since 2.0
039: */
040: public class AspectJWeaverMessageHandler implements IMessageHandler {
041:
042: private static final String AJ_ID = "[AspectJ] ";
043:
044: private static final Log logger = LogFactory
045: .getLog("AspectJ Weaver");
046:
047: public boolean handleMessage(IMessage message)
048: throws AbortException {
049: Kind messageKind = message.getKind();
050:
051: if (logger.isDebugEnabled() || logger.isTraceEnabled()) {
052: if (messageKind == IMessage.DEBUG) {
053: logger.debug(makeMessageFor(message));
054: return true;
055: }
056: }
057:
058: if (logger.isInfoEnabled()) {
059: if ((messageKind == IMessage.INFO)
060: || (messageKind == IMessage.WEAVEINFO)) {
061: logger.info(makeMessageFor(message));
062: return true;
063: }
064: }
065:
066: if (logger.isWarnEnabled()) {
067: if (messageKind == IMessage.WARNING) {
068: logger.warn(makeMessageFor(message));
069: return true;
070: }
071: }
072:
073: if (logger.isErrorEnabled()) {
074: if (messageKind == IMessage.ERROR) {
075: logger.error(makeMessageFor(message));
076: return true;
077: }
078: }
079:
080: if (logger.isFatalEnabled()) {
081: if (messageKind == IMessage.ABORT) {
082: logger.fatal(makeMessageFor(message));
083: return true;
084: }
085: }
086:
087: return false;
088: }
089:
090: private String makeMessageFor(IMessage aMessage) {
091: return AJ_ID + aMessage.getMessage();
092: }
093:
094: public boolean isIgnoring(Kind messageKind) {
095: // We want to see everything, and allow configuration of log levels dynamically.
096: return false;
097: }
098:
099: public void dontIgnore(Kind messageKind) {
100: // We weren't ignoring anything anyway...
101: }
102:
103: public void ignore(Kind kind) {
104: // We weren't ignoring anything anyway...
105: }
106:
107: }
|