KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log > output > lf5 > LogKitLogRecord


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.log.output.lf5;
18
19 import java.util.Arrays JavaDoc;
20 import java.util.List JavaDoc;
21 import org.apache.log.ContextMap;
22 import org.apache.log.LogEvent;
23 import org.apache.log.Logger;
24 import org.apache.log.Priority;
25 import org.apache.log.format.Formatter;
26 import org.apache.log.util.StackIntrospector;
27 import org.apache.log4j.lf5.LogLevel;
28 import org.apache.log4j.lf5.LogRecord;
29
30 /**
31  * An implementation of a LogFactor5 <code>LogRecord</code> based on a
32  * LogKit {@link LogEvent}.
33  *
34  * @author <a HREF="sylvain@apache.org">Sylvain Wallez</a>
35  * @version CVS $Revision: 1.7 $ $Date: 2004/02/28 11:31:26 $
36  */

37
38 public class LogKitLogRecord
39     extends LogRecord
40 {
41     /** Is this a severe event ? */
42     private boolean m_severe;
43
44     /**
45      * Create a LogFactor record from a LogKit event
46      */

47     public LogKitLogRecord( final LogEvent event, final Formatter fmt )
48     {
49         final ContextMap contextMap = event.getContextMap();
50
51         Object JavaDoc contextObject;
52
53         // Category
54
setCategory( event.getCategory() );
55
56         // Level
57
setLevel( toLogLevel( event.getPriority() ) );
58         m_severe = event.getPriority().isGreater( Priority.INFO );
59
60         // Location
61
if( null != contextMap && null != ( contextObject = contextMap.get( "method" ) ) )
62         {
63             setLocation( contextObject.toString() );
64         }
65         else
66         {
67             setLocation( StackIntrospector.getCallerMethod( Logger.class ) );
68         }
69
70         // Message
71
setMessage( event.getMessage() );
72
73         // Millis
74
setMillis( event.getTime() );
75
76         // NDC
77
setNDC( fmt.format( event ) );
78
79         // SequenceNumber
80
//setSequenceNumber( 0L );
81

82         // ThreadDescription
83
if( null != contextMap && null != ( contextObject = contextMap.get( "thread" ) ) )
84         {
85             setThreadDescription( contextObject.toString() );
86         }
87         else
88         {
89             setThreadDescription( Thread.currentThread().getName() );
90         }
91
92         // Thrown
93
setThrown( event.getThrowable() );
94
95         // ThrownStackTrace
96
//setThrownStackTrace("");
97
}
98
99     public boolean isSevereLevel()
100     {
101         return m_severe;
102     }
103
104     /**
105      * Convert a LogKit <code>Priority</code> to a LogFactor <code>LogLevel</code>.
106      */

107     public LogLevel toLogLevel( final Priority priority )
108     {
109         if( Priority.DEBUG == priority )
110         {
111             return LogLevel.DEBUG;
112         }
113         else if( Priority.INFO == priority )
114         {
115             return LogLevel.INFO;
116         }
117         else if( Priority.WARN == priority )
118         {
119             return LogLevel.WARN;
120         }
121         else if( Priority.ERROR == priority )
122         {
123             return LogLevel.ERROR;
124         }
125         else if( Priority.FATAL_ERROR == priority )
126         {
127             return LogLevel.FATAL;
128         }
129         else
130         {
131             return new LogLevel( priority.getName(), priority.getValue() );
132         }
133     }
134
135     /**
136      * The <code>LogLevel</code>s corresponding to LogKit priorities.
137      */

138     public static final List JavaDoc LOGKIT_LOGLEVELS =
139         Arrays.asList( new LogLevel[]{
140             LogLevel.FATAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG
141         } );
142 }
143
Popular Tags