KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */

19 package org.apache.avalon.excalibur.logger.factory;
20
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23 import org.apache.log.LogTarget;
24 import org.apache.log.format.Formatter;
25 import org.apache.log.output.io.StreamTarget;
26
27 /**
28  * ConsoleTargetFactory class.
29  *
30  * This factory is able to create a console target which can be used for
31  * debugging components.
32  *
33  * <pre>
34  * &lt;console id="console"&gt;
35  * &lt;format type="avalon|raw|pattern|extended"&gt;pattern to be used if needed&lt;/format&gt;
36  * &lt;/console&gt;
37  * </pre>
38  *
39  * <p>Some explanations about the Elements used in the configuration:</p>
40  * <dl>
41  * <dt>&lt;format&gt;</dt>
42  * <dd>
43  * The type attribute of the pattern element denotes the type of
44  * Formatter to be used and according to it the pattern to use for.
45  * This elements defaults to:
46  * <p>
47  * %7.7{priority} %5.5{time} [%8.8{category}] (%{context}): %{message}\\n%{throwable}
48  * </p>
49  * </dd>
50  * </dl>
51  *
52  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
53  * @version CVS $Revision: 1.1 $ $Date: 2004/03/16 09:07:57 $
54  * @since 1.2
55  */

56 public class ConsoleTargetFactory
57     extends AbstractTargetFactory
58 {
59
60     /**
61      * Create a LogTarget based on a Configuration
62      */

63     public final LogTarget createTarget( final Configuration configuration )
64         throws ConfigurationException
65     {
66         final Configuration confFormat = configuration.getChild( "format" );
67         final Formatter formatter = getFormatter( confFormat );
68
69         final LogTarget logtarget = new StreamTarget(System.out, formatter);
70
71         return logtarget;
72     }
73
74     protected Formatter getFormatter( final Configuration conf )
75     {
76         Formatter formatter = null;
77
78         if( null != conf )
79         {
80             final FormatterFactory formatterFactory = new FormatterFactory();
81             formatter = formatterFactory.createFormatter( conf );
82         }
83
84         return formatter;
85     }
86 }
87
Popular Tags