KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > log > JavaLogFactory


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

20
21 package org.snmp4j.log;
22
23 import java.util.Iterator JavaDoc;
24 import java.util.logging.Logger JavaDoc;
25 import java.util.logging.LogManager JavaDoc;
26 import java.util.*;
27
28 /**
29  * The <code>JavaLogFactory</code> implements a SNMP4J LogFactory for
30  * Java logging. In order to use Java's <code>java.util.logging</code>
31  * for logging SNMP4J log messages the static {@link LogFactory#setLogFactory}
32  * method has to be used before any SNMP4J class is referenced or instantiated.
33  *
34  * @author Frank Fock
35  * @version 1.7.2
36  */

37 public class JavaLogFactory extends LogFactory {
38
39   public JavaLogFactory() {
40   }
41
42   protected LogAdapter createLogger(Class JavaDoc c) {
43     return new JavaLogAdapter(Logger.getLogger(c.getClass().getName()));
44   }
45
46   protected LogAdapter createLogger(String JavaDoc className) {
47     return new JavaLogAdapter(Logger.getLogger(className));
48   }
49
50   public LogAdapter getRootLogger() {
51     return new JavaLogAdapter(Logger.getLogger(""));
52   }
53
54   public Iterator JavaDoc loggers() {
55     Enumeration loggerNames = LogManager.getLogManager().getLoggerNames();
56     return new JavaLogAdapterIterator(loggerNames);
57   }
58
59   public class JavaLogAdapterIterator implements Iterator JavaDoc {
60     private Enumeration loggerNames;
61
62     protected JavaLogAdapterIterator(Enumeration loggerNames) {
63       this.loggerNames = loggerNames;
64     }
65
66     public void remove() {
67       throw new UnsupportedOperationException JavaDoc();
68     }
69
70     public final boolean hasNext() {
71       return loggerNames.hasMoreElements();
72     }
73
74     public Object JavaDoc next() {
75       String JavaDoc loggerName = (String JavaDoc) loggerNames.nextElement();
76       Logger JavaDoc logger = Logger.getLogger(loggerName);
77       return new JavaLogAdapter(logger);
78     }
79   }
80 }
81
Popular Tags