FileDocCategorySizeDatePackage
PatternConverter.javaAPI DocApache log4j 1.2.152847Sat Aug 25 00:09:40 BST 2007org.apache.log4j.helpers

PatternConverter

public abstract class PatternConverter extends Object

PatternConverter is an abtract class that provides the formatting functionality that derived classes need.

Conversion specifiers in a conversion patterns are parsed to individual PatternConverters. Each of which is responsible for converting a logging event in a converter specific manner.

author
James P. Cakalic
author
Ceki Gülcü
since
0.8.2

Fields Summary
public PatternConverter
next
int
min
int
max
boolean
leftAlign
static String[]
SPACES
Constructors Summary
protected PatternConverter()


  
     
protected PatternConverter(FormattingInfo fi)

    min = fi.min;
    max = fi.max;
    leftAlign = fi.leftAlign;
  
Methods Summary
protected abstract java.lang.Stringconvert(org.apache.log4j.spi.LoggingEvent event)
Derived pattern converters must override this method in order to convert conversion specifiers in the correct way.

public voidformat(java.lang.StringBuffer sbuf, org.apache.log4j.spi.LoggingEvent e)
A template method for formatting in a converter specific way.

    String s = convert(e);

    if(s == null) {
      if(0 < min)
	spacePad(sbuf, min);
      return;
    }

    int len = s.length();

    if(len > max)
      sbuf.append(s.substring(len-max));
    else if(len < min) {
      if(leftAlign) {	
	sbuf.append(s);
	spacePad(sbuf, min-len);
      }
      else {
	spacePad(sbuf, min-len);
	sbuf.append(s);
      }
    }
    else
      sbuf.append(s);
  
public voidspacePad(java.lang.StringBuffer sbuf, int length)
Fast space padding method.

 // 32 spaces

            
  
       
    while(length >= 32) {
      sbuf.append(SPACES[5]);
      length -= 32;
    }
    
    for(int i = 4; i >= 0; i--) {	
      if((length & (1<<i)) != 0) {
	sbuf.append(SPACES[i]);
      }
    }