KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > util > log > CocoonStreamTargetFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.util.log;
17
18 import org.apache.avalon.excalibur.logger.factory.StreamTargetFactory;
19 import org.apache.avalon.framework.configuration.Configuration;
20 import org.apache.log.format.Formatter;
21
22 /**
23  * TargetFactory for {@link org.apache.log.output.io.StreamTarget }.
24  *
25  * This factory is able to create different StreamTargets according to the following
26  * configuration syntax:
27  * <pre>
28  * &lt;stream id="foo"&gt;
29  * &lt;stream&gt;<i>stream-context-name</i>&lt;/stream&gt;
30  * &lt;format type="<i>raw|pattern|extended|xml|cocoon</i>"&gt;<i>pattern to be used if needed</i>&lt;/format&gt;
31  * &lt;/stream&gt;
32  * </pre>
33  *
34  * <p>The "stream-context-name" is the name of an <code>java.io.OutputStream</code> that
35  * is fetched in the context. This context contains two predefined streams :
36  * <li>"<code>System.out</code>" for the system output stream,</li>
37  * <li>"<code>System.err</code>" for the system error stream.</li>
38  * </p>
39  *
40  * <p>The syntax of "format" is the same as in <code>CocoonTargetFactory</code>.</p>
41  *
42  * @author <a HREF="mailto:giacomo@apache.org">Giacomo Pati</a>
43  * @version CVS $Id: CocoonStreamTargetFactory.java 105794 2004-11-19 07:41:03Z antonio $
44  */

45 public class CocoonStreamTargetFactory
46     extends StreamTargetFactory {
47         
48     //Format of default Cocoon formatter
49
private static final String JavaDoc CFORMAT =
50         "%7.7{priority} %{time} [%8.8{category}] (%{uri}) %{thread}/%{class:short}: %{message}\\n%{throwable}";
51
52     //Format of default Cocoon XML formatter
53
private static final String JavaDoc XFORMAT =
54         "priority time category uri thread class message throwable";
55
56     protected Formatter getFormatter(final Configuration conf) {
57         final String JavaDoc type = conf.getAttribute("type", "unknown");
58
59         if ("cocoon".equals(type)) {
60             int depth = conf.getAttributeAsInteger( "depth", 0 );
61             final CocoonLogFormatter formatter = new CocoonLogFormatter( depth );
62             final String JavaDoc format = conf.getValue(CFORMAT);
63             formatter.setFormat(format);
64             return formatter;
65         } else if ("xml".equals(type)) {
66             final XMLCocoonLogFormatter formatter = new XMLCocoonLogFormatter();
67             final String JavaDoc format = conf.getValue(XFORMAT);
68             formatter.setTypes(format);
69             return formatter;
70         }
71
72         // default formatter
73
return super.getFormatter(conf);
74     }
75 }
76
77
Popular Tags