View Javadoc

1   /**
2    * LOGBack: the reliable, fast and flexible logging library for Java.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.core.pattern;
11  
12  public class CompositeConverter<E> extends FormattingConverter<E> {
13  
14    StringBuffer buf = new StringBuffer();
15    Converter<E> childConverter;
16  
17    public String convert(E event) {
18      if (buf.capacity() > MAX_CAPACITY) {
19        buf = new StringBuffer(INITIAL_BUF_SIZE);
20      } else {
21        buf.setLength(0);
22      }
23  
24      for (Converter<E> c = childConverter; c != null; c = c.next) {
25        c.write(buf, event);
26      }
27      return buf.toString();
28    }
29  
30    public void setChildConverter(Converter<E> child) {
31      childConverter = child;
32    }
33  
34    public String toString() {
35      StringBuffer buf = new StringBuffer();
36      buf.append("CompositeConverter<");
37      
38      if(formattingInfo != null)
39      buf.append(formattingInfo);
40      
41      if (childConverter != null) {
42        buf.append(", children: "+childConverter);
43      }
44      buf.append(">");
45      return buf.toString();
46    }
47  }