1 55 package org.apache.log.format; 56 57 import org.apache.log.LogEvent; 58 import org.apache.log.format.ExtendedPatternFormatter; 59 import org.apache.log.format.PatternFormatter; 60 import org.apache.log.util.StackIntrospector; 61 62 78 public class AvalonFormatter 79 extends ExtendedPatternFormatter 80 { 81 private static final int TYPE_CLASS = MAX_TYPE + 1; 82 83 private static final String TYPE_CLASS_STR = "class"; 84 private static final String TYPE_CLASS_SHORT_STR = "short"; 85 86 90 public static final int DEFAULT_STACK_DEPTH = 8; 91 92 96 public static final boolean DEFAULT_PRINT_CASCADING = true; 97 98 private final int m_stackDepth; 100 101 private final boolean m_printCascading; 103 104 110 public AvalonFormatter( final String pattern ) 111 { 112 this( pattern, DEFAULT_STACK_DEPTH, DEFAULT_PRINT_CASCADING ); 113 } 114 115 124 public AvalonFormatter( final String pattern, final int stackDepth, 125 final boolean printCascading ) 126 { 127 super( pattern ); 128 m_stackDepth = stackDepth; 129 m_printCascading = printCascading; 130 } 131 132 139 protected String getStackTrace( final Throwable throwable, final String format ) 140 { 141 if( null == throwable ) 142 { 143 return ""; 144 } 145 return ExceptionUtil.printStackTrace( throwable, m_stackDepth, m_printCascading ); 146 } 147 148 154 protected int getTypeIdFor( final String type ) 155 { 156 if( type.equalsIgnoreCase( TYPE_CLASS_STR ) ) 157 { 158 return TYPE_CLASS; 159 } 160 else 161 { 162 return super.getTypeIdFor( type ); 163 } 164 } 165 166 protected String formatPatternRun( LogEvent event, PatternFormatter.PatternRun run ) 167 { 168 switch( run.m_type ) 169 { 170 case TYPE_CLASS: 171 return getClass( run.m_format ); 172 default: 173 return super.formatPatternRun( event, run ); 174 } 175 } 176 177 180 private String getClass( String format ) 181 { 182 return "Unknown-class"; 183 } 184 } 185 | Popular Tags |