2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j.helpers;
20 import org.apache.log4j.spi.LoggingEvent;
24 <p>PatternConverter is an abtract class that provides the
25 formatting functionality that derived classes need.
27 <p>Conversion specifiers in a conversion patterns are parsed to
28 individual PatternConverters. Each of which is responsible for
29 converting a logging event in a converter specific manner.
31 @author <a href="mailto:cakalijp@Maritz.com">James P. Cakalic</a>
32 @author Ceki Gülcü
36 public abstract class PatternConverter {
37 public PatternConverter next;
40 boolean leftAlign = false;
43 PatternConverter() { }
46 PatternConverter(FormattingInfo fi) {
49 leftAlign = fi.leftAlign;
53 Derived pattern converters must override this method in order to
54 convert conversion specifiers in the correct way.
58 String convert(LoggingEvent event);
61 A template method for formatting in a converter specific way.
64 void format(StringBuffer sbuf, LoggingEvent e) {
65 String s = convert(e);
77 sbuf.append(s.substring(len-max));
78 } else if(len < min) {
81 spacePad(sbuf, min-len);
84 spacePad(sbuf, min-len);
92 static String[] SPACES = {" ", " ", " ", " ", //1,2,4,8 spaces
97 Fast space padding method.
100 void spacePad(StringBuffer sbuf, int length) {
101 while(length >= 32) {
102 sbuf.append(SPACES[5]);
106 for(int i = 4; i >= 0; i--) {
107 if((length & (1<<i)) != 0) {
108 sbuf.append(SPACES[i]);