01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.util.log;
18:
19: import org.apache.avalon.excalibur.logger.factory.StreamTargetFactory;
20: import org.apache.avalon.framework.configuration.Configuration;
21: import org.apache.log.format.Formatter;
22:
23: /**
24: * TargetFactory for {@link org.apache.log.output.io.StreamTarget }.
25: *
26: * This factory is able to create different StreamTargets according to the following
27: * configuration syntax:
28: * <pre>
29: * <stream id="foo">
30: * <stream><i>stream-context-name</i></stream>
31: * <format type="<i>raw|pattern|extended|xml|cocoon</i>"><i>pattern to be used if needed</i></format>
32: * </stream>
33: * </pre>
34: *
35: * <p>The "stream-context-name" is the name of an <code>java.io.OutputStream</code> that
36: * is fetched in the context. This context contains two predefined streams :
37: * <li>"<code>System.out</code>" for the system output stream,</li>
38: * <li>"<code>System.err</code>" for the system error stream.</li>
39: * </p>
40: *
41: * <p>The syntax of "format" is the same as in <code>CocoonTargetFactory</code>.</p>
42: *
43: * @deprecated This class will be removed in 2.2
44: * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
45: * @version CVS $Id: CocoonStreamTargetFactory.java 433543 2006-08-22 06:22:54Z crossley $
46: */
47: public class CocoonStreamTargetFactory extends StreamTargetFactory {
48:
49: //Format of default Cocoon formatter
50: private static final String CFORMAT = "%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 XFORMAT = "priority time category uri thread class message throwable";
54:
55: protected Formatter getFormatter(final Configuration conf) {
56: final String type = conf.getAttribute("type", "unknown");
57:
58: if ("cocoon".equals(type)) {
59: int depth = conf.getAttributeAsInteger("depth", 0);
60: final CocoonLogFormatter formatter = new CocoonLogFormatter(
61: depth);
62: final String 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 format = conf.getValue(XFORMAT);
68: formatter.setTypes(format);
69: return formatter;
70: }
71:
72: // default formatter
73: return super.getFormatter(conf);
74: }
75: }
|