KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > log > LogManager


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27 package org.apache.tomcat.util.log;
28
29 import java.io.*;
30 import java.lang.reflect.*;
31 import java.util.*;
32
33
34 /**
35  * Allows the control the log properties at runtime.
36  * Normal applications will just use Log, without having to
37  * deal with the way the log is configured or managed.
38  *
39  *
40  * @author Alex Chaffee [alex@jguru.com]
41  * @author Costin Manolache
42  **/

43 public class LogManager {
44
45     //static LogHandler defaultChannel=new LogHandler();
46
static LogHandler defaultChannel=new CommonLogHandler();
47     
48     protected Hashtable loggers=new Hashtable();
49     protected Hashtable channels=new Hashtable();
50
51     public Hashtable getLoggers() {
52     return loggers;
53     }
54
55     public Hashtable getChannels() {
56     return channels;
57     }
58     
59     public static void setDefault( LogHandler l ) {
60     if( defaultChannel==null)
61         defaultChannel=l;
62     }
63
64     public void addChannel( String JavaDoc name, LogHandler logH ) {
65     if(name==null) name="";
66
67     channels.put( name, logH );
68     Enumeration enumeration=loggers.keys();
69     while( enumeration.hasMoreElements() ) {
70         String JavaDoc k=(String JavaDoc)enumeration.nextElement();
71         Log l=(Log)loggers.get( k );
72         if( name.equals( l.getChannel( this ) )) {
73         l.setProxy( this, logH );
74         }
75     }
76     }
77     
78     /** Default method to create a log facade.
79      */

80     public Log getLog( String JavaDoc channel, String JavaDoc prefix,
81                Object JavaDoc owner ) {
82     if( prefix==null && owner!=null ) {
83         String JavaDoc cname = owner.getClass().getName();
84         prefix = cname.substring( cname.lastIndexOf(".") +1);
85     }
86
87     LogHandler proxy=(LogHandler)channels.get(channel);
88     if( proxy==null ) proxy=defaultChannel;
89     
90     // user-level loggers
91
Log log=new Log( channel, prefix, proxy, owner );
92     loggers.put( channel + ":" + prefix, log );
93     if( dL > 0 )
94         System.out.println("getLog facade " + channel + ":" + prefix);
95     return log;
96     }
97
98     private static int dL=0;
99
100 }
101
Popular Tags