KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > util > logging > Logging


1 /*
2  * @(#)Logging.java 1.5 04/04/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.util.logging;
9
10 import java.util.Enumeration JavaDoc;
11 import java.util.List JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import sun.management.MXBeanSupport;
14
15 /**
16  * Logging is the implementation class of LoggingMXBean.
17  *
18  * The <tt>LoggingMXBean</tt> interface provides a standard
19  * method for management access to the individual
20  * java.util.Logger objects available at runtime.
21  *
22  * @author Ron Mann
23  * @author Mandy Chung
24  * @version 1.5, 04/18/04
25  * @since 1.5
26  *
27  * @see javax.management
28  * @see java.util.Logger
29  * @see java.util.LogManager
30  */

31 class Logging extends MXBeanSupport implements LoggingMXBean JavaDoc {
32
33     private static LogManager JavaDoc logManager = LogManager.getLogManager();
34
35     /** Contructor of Logging which is the implementation class
36      * of LoggingMXBean.
37      */

38     Logging() {
39         super(LoggingMXBean JavaDoc.class);
40     }
41  
42     public List JavaDoc<String JavaDoc> getLoggerNames() {
43         Enumeration JavaDoc loggers = logManager.getLoggerNames();
44         ArrayList JavaDoc<String JavaDoc> array = new ArrayList JavaDoc<String JavaDoc>();
45
46         for (; loggers.hasMoreElements();) {
47             array.add((String JavaDoc) loggers.nextElement());
48         }
49         return array;
50     }
51
52     private static String JavaDoc EMPTY_STRING = "";
53     public String JavaDoc getLoggerLevel(String JavaDoc loggerName) {
54         Logger JavaDoc l = logManager.getLogger(loggerName);
55         if (l == null) {
56             return null;
57         }
58
59         Level JavaDoc level = l.getLevel();
60         if (level == null) {
61             return EMPTY_STRING;
62         } else {
63             return level.getName();
64         }
65     }
66
67     public void setLoggerLevel(String JavaDoc loggerName, String JavaDoc levelName) {
68         if (loggerName == null) {
69             throw new NullPointerException JavaDoc("loggerName is null");
70         }
71
72         Logger JavaDoc logger = logManager.getLogger(loggerName);
73         
74         if (logger == null) {
75             throw new IllegalArgumentException JavaDoc("Logger " + loggerName +
76                 "does not exist");
77         }
78  
79         Level JavaDoc level = null;
80         if (levelName != null) {
81             // parse will throw IAE if logLevel is invalid
82
level = Level.parse(levelName);
83         }
84
85         logger.setLevel(level);
86     }
87
88     public String JavaDoc getParentLoggerName( String JavaDoc loggerName ) {
89         Logger JavaDoc l = logManager.getLogger( loggerName );
90         if (l == null) {
91             return null;
92         }
93
94         Logger JavaDoc p = l.getParent();
95         if (p == null) {
96             // root logger
97
return EMPTY_STRING;
98         } else {
99             return p.getName();
100         }
101     }
102
103 }
104
Popular Tags