author | dfuchs |
Thu, 06 Apr 2017 14:38:15 +0100 | |
changeset 44538 | a603c475d649 |
parent 38370 | 61f46e1e7aee |
permissions | -rw-r--r-- |
2 | 1 |
/* |
21655
55f32ae4f920
8028229: Fix more raw types lint warning in core libraries
darcy
parents:
16100
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.logging; |
|
27 |
||
28 |
import java.util.Enumeration; |
|
29 |
import java.util.List; |
|
30 |
import java.util.ArrayList; |
|
31 |
||
32 |
/** |
|
33 |
* Logging is the implementation class of LoggingMXBean. |
|
34 |
* |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
35 |
* The {@code LoggingMXBean} interface provides a standard |
2 | 36 |
* method for management access to the individual |
16098 | 37 |
* {@code Logger} objects available at runtime. |
2 | 38 |
* |
39 |
* @author Ron Mann |
|
40 |
* @author Mandy Chung |
|
41 |
* @since 1.5 |
|
42 |
* |
|
43 |
* @see javax.management |
|
14014 | 44 |
* @see Logger |
45 |
* @see LogManager |
|
2 | 46 |
*/ |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
47 |
@SuppressWarnings("deprecation") // implements LoggingMXBean |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
48 |
final class Logging implements LoggingMXBean { |
2 | 49 |
|
50 |
private static LogManager logManager = LogManager.getLogManager(); |
|
51 |
||
52 |
/** Constructor of Logging which is the implementation class |
|
53 |
* of LoggingMXBean. |
|
54 |
*/ |
|
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
55 |
private Logging() { |
2 | 56 |
} |
57 |
||
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
58 |
@Override |
2 | 59 |
public List<String> getLoggerNames() { |
21655
55f32ae4f920
8028229: Fix more raw types lint warning in core libraries
darcy
parents:
16100
diff
changeset
|
60 |
Enumeration<String> loggers = logManager.getLoggerNames(); |
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
5506
diff
changeset
|
61 |
ArrayList<String> array = new ArrayList<>(); |
2 | 62 |
|
63 |
for (; loggers.hasMoreElements();) { |
|
21655
55f32ae4f920
8028229: Fix more raw types lint warning in core libraries
darcy
parents:
16100
diff
changeset
|
64 |
array.add(loggers.nextElement()); |
2 | 65 |
} |
66 |
return array; |
|
67 |
} |
|
68 |
||
69 |
private static String EMPTY_STRING = ""; |
|
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
70 |
@Override |
2 | 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 { |
|
16098 | 81 |
return level.getLevelName(); |
2 | 82 |
} |
83 |
} |
|
84 |
||
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
85 |
@Override |
2 | 86 |
public void setLoggerLevel(String loggerName, String levelName) { |
87 |
if (loggerName == null) { |
|
88 |
throw new NullPointerException("loggerName is null"); |
|
89 |
} |
|
90 |
||
91 |
Logger logger = logManager.getLogger(loggerName); |
|
92 |
if (logger == null) { |
|
93 |
throw new IllegalArgumentException("Logger " + loggerName + |
|
23882
7dbf42ed83ef
8009637: Some error messages are missing a space
igerasim
parents:
21655
diff
changeset
|
94 |
" does not exist"); |
2 | 95 |
} |
96 |
||
97 |
Level level = null; |
|
98 |
if (levelName != null) { |
|
99 |
// parse will throw IAE if logLevel is invalid |
|
16098 | 100 |
level = Level.findLevel(levelName); |
101 |
if (level == null) { |
|
102 |
throw new IllegalArgumentException("Unknown level \"" + levelName + "\""); |
|
103 |
} |
|
2 | 104 |
} |
105 |
||
106 |
logger.setLevel(level); |
|
107 |
} |
|
108 |
||
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
109 |
@Override |
2 | 110 |
public String getParentLoggerName( String loggerName ) { |
111 |
Logger l = logManager.getLogger( loggerName ); |
|
112 |
if (l == null) { |
|
113 |
return null; |
|
114 |
} |
|
115 |
||
116 |
Logger p = l.getParent(); |
|
117 |
if (p == null) { |
|
118 |
// root logger |
|
119 |
return EMPTY_STRING; |
|
120 |
} else { |
|
121 |
return p.getName(); |
|
122 |
} |
|
123 |
} |
|
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
124 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
125 |
static Logging getInstance() { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
126 |
return INSTANCE; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
127 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
128 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
129 |
private static final Logging INSTANCE = new Logging(); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
32037
diff
changeset
|
130 |
|
2 | 131 |
} |