001: /* ====================================================================
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 1997-2003 The Apache Software Foundation. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by the
022: * Apache Software Foundation (http://www.apache.org/)."
023: * Alternately, this acknowledgment may appear in the software
024: * itself, if and wherever such third-party acknowledgments
025: * normally appear.
026: *
027: * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
028: * must not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation. For more
052: * information on the Apache Software Foundation, please see
053: * <http://www.apache.org/>.
054: */
055: package org.apache.log.output.lf5;
056:
057: import org.apache.log.*;
058: import org.apache.log.format.Formatter;
059: import org.apache.log.util.StackIntrospector;
060:
061: import java.util.Arrays;
062: import java.util.List;
063:
064: import org.apache.log4j.lf5.LogRecord;
065: import org.apache.log4j.lf5.LogLevel;
066:
067: /**
068: * An implementation of a LogFactor5 <code>LogRecord</code> based on a
069: * LogKit {@link LogEvent}.
070: *
071: * @author <a href="sylvain@apache.org">Sylvain Wallez</a>
072: * @version CVS $Revision: 1.4 $ $Date: 2003/02/09 23:33:24 $
073: */
074:
075: public class LogKitLogRecord extends LogRecord {
076: /** Is this a severe event ? */
077: private boolean m_severe;
078:
079: /**
080: * Create a LogFactor record from a LogKit event
081: */
082: public LogKitLogRecord(final LogEvent event, final Formatter fmt) {
083: final ContextMap contextMap = event.getContextMap();
084:
085: Object contextObject;
086:
087: // Category
088: this .setCategory(event.getCategory());
089:
090: // Level
091: this .setLevel(toLogLevel(event.getPriority()));
092: m_severe = event.getPriority().isGreater(Priority.INFO);
093:
094: // Location
095: if (null != contextMap
096: && null != (contextObject = contextMap.get("method"))) {
097: this .setLocation(contextObject.toString());
098: } else {
099: this .setLocation(StackIntrospector
100: .getCallerMethod(Logger.class));
101: }
102:
103: // Message
104: this .setMessage(event.getMessage());
105:
106: // Millis
107: this .setMillis(event.getTime());
108:
109: // NDC
110: this .setNDC(fmt.format(event));
111:
112: // SequenceNumber
113: //this.setSequenceNumber( 0L );
114:
115: // ThreadDescription
116: if (null != contextMap
117: && null != (contextObject = contextMap.get("thread"))) {
118: this .setThreadDescription(contextObject.toString());
119: } else {
120: this .setThreadDescription(Thread.currentThread().getName());
121: }
122:
123: // Thrown
124: this .setThrown(event.getThrowable());
125:
126: // ThrownStackTrace
127: //this.setThrownStackTrace("");
128: }
129:
130: public boolean isSevereLevel() {
131: return m_severe;
132: }
133:
134: /**
135: * Convert a LogKit <code>Priority</code> to a LogFactor <code>LogLevel</code>.
136: */
137: public LogLevel toLogLevel(final Priority priority) {
138: if (Priority.DEBUG == priority)
139: return LogLevel.DEBUG;
140: else if (Priority.INFO == priority)
141: return LogLevel.INFO;
142: else if (Priority.WARN == priority)
143: return LogLevel.WARN;
144: else if (Priority.ERROR == priority)
145: return LogLevel.ERROR;
146: else if (Priority.FATAL_ERROR == priority)
147: return LogLevel.FATAL;
148: else
149: return new LogLevel(priority.getName(), priority.getValue());
150: }
151:
152: /**
153: * The <code>LogLevel</code>s corresponding to LogKit priorities.
154: */
155: public static final List LOGKIT_LOGLEVELS = Arrays
156: .asList(new LogLevel[] { LogLevel.FATAL, LogLevel.ERROR,
157: LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG });
158: }
|