author | emcmanus |
Wed, 21 Oct 2009 17:33:18 +0200 | |
changeset 4156 | acaa49a2768a |
parent 1225 | 6ef6227d36eb |
child 4172 | bceea7bc12b7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.util.logging; |
|
27 |
||
28 |
import java.util.Enumeration; |
|
29 |
import java.util.List; |
|
30 |
import java.util.ArrayList; |
|
31 |
||
4156 | 32 |
import javax.management.MalformedObjectNameException; |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
33 |
import javax.management.ObjectName; |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
34 |
|
2 | 35 |
/** |
36 |
* Logging is the implementation class of LoggingMXBean. |
|
37 |
* |
|
38 |
* The <tt>LoggingMXBean</tt> interface provides a standard |
|
39 |
* method for management access to the individual |
|
40 |
* java.util.Logger objects available at runtime. |
|
41 |
* |
|
42 |
* @author Ron Mann |
|
43 |
* @author Mandy Chung |
|
44 |
* @since 1.5 |
|
45 |
* |
|
46 |
* @see javax.management |
|
47 |
* @see java.util.Logger |
|
48 |
* @see java.util.LogManager |
|
49 |
*/ |
|
50 |
class Logging implements LoggingMXBean { |
|
51 |
||
52 |
private static LogManager logManager = LogManager.getLogManager(); |
|
53 |
||
54 |
/** Constructor of Logging which is the implementation class |
|
55 |
* of LoggingMXBean. |
|
56 |
*/ |
|
57 |
Logging() { |
|
58 |
} |
|
59 |
||
60 |
public List<String> getLoggerNames() { |
|
61 |
Enumeration loggers = logManager.getLoggerNames(); |
|
62 |
ArrayList<String> array = new ArrayList<String>(); |
|
63 |
||
64 |
for (; loggers.hasMoreElements();) { |
|
65 |
array.add((String) loggers.nextElement()); |
|
66 |
} |
|
67 |
return array; |
|
68 |
} |
|
69 |
||
70 |
private static String EMPTY_STRING = ""; |
|
71 |
public String getLoggerLevel(String loggerName) { |
|
72 |
Logger l = logManager.getLogger(loggerName); |
|
73 |
if (l == null) { |
|
74 |
return null; |
|
75 |
} |
|
76 |
||
77 |
Level level = l.getLevel(); |
|
78 |
if (level == null) { |
|
79 |
return EMPTY_STRING; |
|
80 |
} else { |
|
81 |
return level.getName(); |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
public void setLoggerLevel(String loggerName, String levelName) { |
|
86 |
if (loggerName == null) { |
|
87 |
throw new NullPointerException("loggerName is null"); |
|
88 |
} |
|
89 |
||
90 |
Logger logger = logManager.getLogger(loggerName); |
|
91 |
||
92 |
if (logger == null) { |
|
93 |
throw new IllegalArgumentException("Logger " + loggerName + |
|
94 |
"does not exist"); |
|
95 |
} |
|
96 |
||
97 |
Level level = null; |
|
98 |
if (levelName != null) { |
|
99 |
// parse will throw IAE if logLevel is invalid |
|
100 |
level = Level.parse(levelName); |
|
101 |
} |
|
102 |
||
103 |
logger.setLevel(level); |
|
104 |
} |
|
105 |
||
106 |
public String getParentLoggerName( String loggerName ) { |
|
107 |
Logger l = logManager.getLogger( loggerName ); |
|
108 |
if (l == null) { |
|
109 |
return null; |
|
110 |
} |
|
111 |
||
112 |
Logger p = l.getParent(); |
|
113 |
if (p == null) { |
|
114 |
// root logger |
|
115 |
return EMPTY_STRING; |
|
116 |
} else { |
|
117 |
return p.getName(); |
|
118 |
} |
|
119 |
} |
|
120 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
121 |
public ObjectName getObjectName() { |
4156 | 122 |
try { |
123 |
return ObjectName.getInstance(LogManager.LOGGING_MXBEAN_NAME); |
|
124 |
} catch (MalformedObjectNameException e) { |
|
125 |
throw new IllegalArgumentException(e); |
|
126 |
} |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
127 |
} |
2 | 128 |
} |