KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > logger > factory > FormatterFactory


1 /*
2  * FormatterFactory.java
3  *
4  * Created on August 29, 2001, 10:43 PM
5  */

6
7 package org.apache.avalon.excalibur.logger.factory;
8
9 import org.apache.log.format.Formatter;
10 import org.apache.log.format.SyslogFormatter;
11 import org.apache.log.format.PatternFormatter;
12 import org.apache.log.format.ExtendedPatternFormatter;
13 import org.apache.log.format.RawFormatter;
14 import org.apache.log.format.XMLFormatter;
15
16 import org.apache.avalon.framework.logger.AvalonFormatter;
17 import org.apache.avalon.framework.configuration.Configuration;
18 import org.apache.avalon.framework.configuration.Configurable;
19 import org.apache.avalon.framework.configuration.ConfigurationException;
20
21 /**
22  * Factory for Formatter-s.
23  */

24 public class FormatterFactory {
25
26     //Format of default formatter
27
private static final String JavaDoc FORMAT =
28         "%7.7{priority} %5.5{time} [%8.8{category}] (%{context}): %{message}\\n%{throwable}";
29     
30     public Formatter createFormatter( final Configuration conf )
31     {
32         final String JavaDoc type = conf.getAttribute( "type", "pattern" );
33         final String JavaDoc format = conf.getValue( FORMAT );
34         
35         if( "avalon".equals( type ) )
36         {
37             int depth = conf.getAttributeAsInteger( "depth", AvalonFormatter.DEFAULT_STACK_DEPTH );
38             boolean printCascading = conf.getAttributeAsBoolean( "cascading", AvalonFormatter.DEFAULT_PRINT_CASCADING );
39             return new AvalonFormatter( format, depth, printCascading );
40         }
41         
42         if( "extended".equals( type ) )
43         {
44             return new ExtendedPatternFormatter( format );
45         }
46         
47         if( "raw".equals( type ) )
48         {
49             return new RawFormatter();
50         }
51
52         if( "xml".equals( type ) )
53         {
54             return new XMLFormatter();
55         }
56         
57         if( "syslog".equals( type ) )
58         {
59             return new SyslogFormatter();
60         }
61         
62         // default formatter
63
return new PatternFormatter( format );
64     }
65
66 }
67
Popular Tags