KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J - Log4jLogFactory.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 org.apache.log4j.Logger;
24 import java.util.Iterator JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 /**
29  * The <code>Log4jLogFactory</code> implements a SNMP4J LogFactory for
30  * Log4J. In order to use Log4J for logging SNMP4J log messages the
31  * static {@link LogFactory#setLogFactory} method has to be used before
32  * any SNMP4J class is referenced or instantiated.
33  *
34  * @author Frank Fock
35  * @version 1.6.1
36  * @since 1.2.1
37  */

38 public class Log4jLogFactory extends LogFactory {
39
40   public Log4jLogFactory() {
41   }
42
43   protected LogAdapter createLogger(Class JavaDoc c) {
44     return new Log4jLogAdapter(Logger.getLogger(c));
45   }
46
47   protected LogAdapter createLogger(String JavaDoc className) {
48     return new Log4jLogAdapter(Logger.getLogger(className));
49   }
50
51   public LogAdapter getRootLogger() {
52     return new Log4jLogAdapter(Logger.getRootLogger());
53   }
54
55   public Iterator JavaDoc loggers() {
56     ArrayList JavaDoc l = Collections.list(Logger.getRootLogger().
57                                    getLoggerRepository().
58                                    getCurrentLoggers());
59     for (int i=0; i < l.size(); i++) {
60       l.set(i, new Log4jLogAdapter((Logger)l.get(i)));
61     }
62     Collections.sort(l);
63     return l.iterator();
64   }
65 }
66
Popular Tags