1 17 package org.apache.log.output.lf5; 18 19 import java.util.Arrays ; 20 import java.util.List ; 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 37 38 public class LogKitLogRecord 39 extends LogRecord 40 { 41 42 private boolean m_severe; 43 44 47 public LogKitLogRecord( final LogEvent event, final Formatter fmt ) 48 { 49 final ContextMap contextMap = event.getContextMap(); 50 51 Object contextObject; 52 53 setCategory( event.getCategory() ); 55 56 setLevel( toLogLevel( event.getPriority() ) ); 58 m_severe = event.getPriority().isGreater( Priority.INFO ); 59 60 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 setMessage( event.getMessage() ); 72 73 setMillis( event.getTime() ); 75 76 setNDC( fmt.format( event ) ); 78 79 82 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 setThrown( event.getThrowable() ); 94 95 } 98 99 public boolean isSevereLevel() 100 { 101 return m_severe; 102 } 103 104 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 138 public static final List LOGKIT_LOGLEVELS = 139 Arrays.asList( new LogLevel[]{ 140 LogLevel.FATAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG 141 } ); 142 } 143 | Popular Tags |