001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.logging;
019:
020: import java.util.Date;
021: import java.util.HashMap;
022: import java.util.LinkedList;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.log4j.AppenderSkeleton;
027: import org.apache.log4j.spi.ErrorCode;
028: import org.apache.log4j.spi.LoggingEvent;
029:
030: import de.finix.contelligent.CallData;
031: import de.finix.contelligent.Session;
032: import de.finix.contelligent.core.ContelligentSession;
033: import de.finix.contelligent.event.ContelligentEvent;
034: import de.finix.contelligent.event.EventQueueListener;
035: import de.finix.contelligent.util.ThreadedMem;
036:
037: public class EventAppender extends AppenderSkeleton {
038:
039: public boolean requiresLayout() {
040: // Do not make log4j prepare a layout for us
041: return false;
042: }
043:
044: /*
045: * public void activateOptions() { }
046: */
047:
048: public synchronized void append(LoggingEvent event) {
049: if (this .layout == null) {
050: errorHandler.error("No layout for appender " + name, null,
051: ErrorCode.MISSING_LAYOUT);
052: return;
053: }
054: Map info = new HashMap();
055: info.put("message", event.getMessage());
056: info.put("timestamp", (new Date(event.timeStamp)).toString());
057: info.put("callerFile", event.getLocationInformation()
058: .getFileName());
059: info.put("callerClass", event.getLocationInformation()
060: .getClassName());
061: info.put("callerMethod", event.getLocationInformation()
062: .getMethodName());
063: info.put("callerLine", event.getLocationInformation()
064: .getLineNumber());
065: info.put("loggerName", event.getLoggerName());
066: info.put("logLevel", event.getLevel().toString());
067: String[] strRep = event.getThrowableStrRep();
068: if (strRep != null) {
069: info.put("throwable", strRep[0]);
070: StringBuffer formattedRep = new StringBuffer();
071: for (int i = 0; i < strRep.length; i++) {
072: formattedRep.append(strRep[i]);
073: formattedRep.append("\n");
074: }
075: info.put("stackTrace", formattedRep.toString());
076: }
077: CallData callData = ThreadedMem.getCallData();
078: if (callData != null) {
079: ContelligentSession session = (ContelligentSession) callData
080: .getContelligentSession();
081: if (session != null) {
082: if (session.isClientSession()
083: || session.hasObserverSession()) {
084: if (session.hasObserverSession()) {
085: info.put("originType", "observed");
086: ContelligentEvent ce = new ContelligentEvent(
087: ContelligentEvent.LOG_EVENT, info);
088: List eventList = new LinkedList();
089: eventList.add(ce);
090: session.notifyObserverSessions(eventList);
091: }
092: if (session.isClientSession()) {
093: EventQueueListener listener = ((Session) session)
094: .getClientNotificator();
095: if (listener != null) {
096: info.put("originType", "self");
097: ContelligentEvent ce = new ContelligentEvent(
098: ContelligentEvent.LOG_EVENT, info);
099: List eventList = new LinkedList();
100: eventList.add(ce);
101: listener.onEvents(eventList);
102: }
103: }
104: }
105: }
106: }
107: }
108:
109: public synchronized void close() {
110: // Required method; we dont actually need to close anything here
111: }
112:
113: }
|