KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > logger > Facade


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;
20
21 import org.apache.avalon.excalibur.logger.LoggerManager;
22 import org.apache.avalon.excalibur.logger.logkit.LogKitAdapter;
23 import org.apache.avalon.excalibur.logger.logkit.LogKitLoggerHelper;
24 import org.apache.avalon.excalibur.logger.logkit.LogKitConfHelper;
25 import org.apache.avalon.excalibur.logger.log4j.Log4JConfAdapter;
26 import org.apache.avalon.excalibur.logger.decorator.LogToSelfDecorator;
27 import org.apache.avalon.excalibur.logger.decorator.PrefixDecorator;
28 import org.apache.avalon.excalibur.logger.decorator.CachingDecorator;
29 import org.apache.avalon.excalibur.logger.util.LoggerManagerTee;
30 import org.apache.log.Hierarchy;
31
32 /**
33  * A facade to the modularized *LoggerManager building system.
34  * Add methods here to create LoggerManagers to your preference.
35  *
36  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
37  * @version CVS $Revision: 1.3 $ $Date: 2004/03/10 13:54:50 $
38  * @since 4.0
39  */

40
41 public class Facade
42 {
43     /**
44      * Assemble a new LoggerManager running on top of LogKit
45      * configured from a configuration file logging to a supplied
46      * logger as a fallback.
47      * Use this method as a sample showing how to assemble your
48      * own LoggerManager running on top of LogKit flavour.
49      */

50     public static LoggerManager createLogKitConfigurable(
51             final String JavaDoc prefix, final String JavaDoc switchTo )
52     {
53         final org.apache.log.Hierarchy hierarchy = new Hierarchy();
54
55         final LoggerManager bare = new LogKitAdapter( hierarchy );
56         final LoggerManager decorated = applyDecorators( bare, prefix, switchTo );
57         final LoggerManagerTee tee = new LoggerManagerTee( decorated );
58
59         tee.addTee( new LogKitLoggerHelper( hierarchy ) );
60         tee.addTee( new LogKitConfHelper( hierarchy ) );
61         tee.makeReadOnly();
62
63         return tee;
64     }
65
66     /**
67      * Assemble LoggerManager for Log4J system configured
68      * via a configuration file. All the logging errors
69      * will go to System.err however.
70      */

71     public static LoggerManager createLog4JConfigurable(
72             final String JavaDoc prefix, final String JavaDoc switchTo )
73     {
74         final LoggerManager bare = new Log4JConfAdapter();
75         final LoggerManager decorated = applyDecorators( bare, prefix, switchTo );
76         return decorated;
77     }
78
79     private static LoggerManager applyDecorators( LoggerManager target,
80             final String JavaDoc prefix, final String JavaDoc switchTo )
81     {
82         if ( switchTo != null )
83         {
84             target = new LogToSelfDecorator( target, switchTo );
85         }
86         if ( prefix != null && prefix.length() > 0 )
87         {
88             target = new PrefixDecorator( target, prefix );
89         }
90         target = new CachingDecorator( target );
91         return target;
92     }
93 }
94
Popular Tags