author | ohair |
Wed, 13 Apr 2011 16:56:16 -0700 | |
changeset 9050 | 26c2c1de1631 |
parent 9014 | 117374ccf1b7 |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
4 |
* |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
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 |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
10 |
* |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
16 |
* |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
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. |
|
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
24 |
*/ |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
25 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
26 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
27 |
package sun.util.logging; |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
28 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
29 |
import java.lang.reflect.Field; |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
30 |
import java.security.AccessController; |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
31 |
import java.security.PrivilegedAction; |
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
32 |
import java.util.Date; |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
33 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
34 |
/** |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
35 |
* Internal API to support JRE implementation to detect if the java.util.logging |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
36 |
* support is available but with no dependency on the java.util.logging |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
37 |
* classes. This LoggingSupport class provides several static methods to |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
38 |
* access the java.util.logging functionality that requires the caller |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
39 |
* to ensure that the logging support is {@linkplain #isAvailable available} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
40 |
* before invoking it. |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
41 |
* |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
42 |
* @see sun.util.logging.PlatformLogger if you want to log messages even |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
43 |
* if the logging support is not available |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
44 |
*/ |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
45 |
public class LoggingSupport { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
46 |
private LoggingSupport() { } |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
47 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
48 |
private static final LoggingProxy proxy = |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
49 |
AccessController.doPrivileged(new PrivilegedAction<LoggingProxy>() { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
50 |
public LoggingProxy run() { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
51 |
try { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
52 |
// create a LoggingProxyImpl instance when |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
53 |
// java.util.logging classes exist |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
54 |
Class<?> c = Class.forName("java.util.logging.LoggingProxyImpl", true, null); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
55 |
Field f = c.getDeclaredField("INSTANCE"); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
56 |
f.setAccessible(true); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
57 |
return (LoggingProxy) f.get(null); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
58 |
} catch (ClassNotFoundException cnf) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
59 |
return null; |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
60 |
} catch (NoSuchFieldException e) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
61 |
throw new AssertionError(e); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
62 |
} catch (IllegalAccessException e) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
63 |
throw new AssertionError(e); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
64 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
65 |
}}); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
66 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
67 |
/** |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
68 |
* Returns true if java.util.logging support is available. |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
69 |
*/ |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
70 |
public static boolean isAvailable() { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
71 |
return proxy != null; |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
72 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
73 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
74 |
private static void ensureAvailable() { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
75 |
if (proxy == null) |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
76 |
throw new AssertionError("Should not here"); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
77 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
78 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
79 |
public static java.util.List<String> getLoggerNames() { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
80 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
81 |
return proxy.getLoggerNames(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
82 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
83 |
public static String getLoggerLevel(String loggerName) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
84 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
85 |
return proxy.getLoggerLevel(loggerName); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
86 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
87 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
88 |
public static void setLoggerLevel(String loggerName, String levelName) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
89 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
90 |
proxy.setLoggerLevel(loggerName, levelName); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
91 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
92 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
93 |
public static String getParentLoggerName(String loggerName) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
94 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
95 |
return proxy.getParentLoggerName(loggerName); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
96 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
97 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
98 |
public static Object getLogger(String name) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
99 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
100 |
return proxy.getLogger(name); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
101 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
102 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
103 |
public static Object getLevel(Object logger) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
104 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
105 |
return proxy.getLevel(logger); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
106 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
107 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
108 |
public static void setLevel(Object logger, Object newLevel) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
109 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
110 |
proxy.setLevel(logger, newLevel); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
111 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
112 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
113 |
public static boolean isLoggable(Object logger, Object level) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
114 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
115 |
return proxy.isLoggable(logger,level); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
116 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
117 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
118 |
public static void log(Object logger, Object level, String msg) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
119 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
120 |
proxy.log(logger, level, msg); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
121 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
122 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
123 |
public static void log(Object logger, Object level, String msg, Throwable t) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
124 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
125 |
proxy.log(logger, level, msg, t); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
126 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
127 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
128 |
public static void log(Object logger, Object level, String msg, Object... params) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
129 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
130 |
proxy.log(logger, level, msg, params); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
131 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
132 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
133 |
public static Object parseLevel(String levelName) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
134 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
135 |
return proxy.parseLevel(levelName); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
136 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
137 |
|
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
138 |
public static String getLevelName(Object level) { |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
139 |
ensureAvailable(); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
140 |
return proxy.getLevelName(level); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
141 |
} |
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
142 |
|
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
143 |
private static final String DEFAULT_FORMAT = |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
144 |
"%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%6$s%n"; |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
145 |
|
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
146 |
private static final String FORMAT_PROP_KEY = "java.util.logging.SimpleFormatter.format"; |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
147 |
public static String getSimpleFormat() { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
148 |
return getSimpleFormat(true); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
149 |
} |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
150 |
|
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
151 |
// useProxy if true will cause initialization of |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
152 |
// java.util.logging and read its configuration |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
153 |
static String getSimpleFormat(boolean useProxy) { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
154 |
String format = |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
155 |
AccessController.doPrivileged( |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
156 |
new PrivilegedAction<String>() { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
157 |
public String run() { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
158 |
return System.getProperty(FORMAT_PROP_KEY); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
159 |
} |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
160 |
}); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
161 |
|
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
162 |
if (useProxy && proxy != null && format == null) { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
163 |
format = proxy.getProperty(FORMAT_PROP_KEY); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
164 |
} |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
165 |
|
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
166 |
if (format != null) { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
167 |
try { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
168 |
// validate the user-defined format string |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
169 |
String.format(format, new Date(), "", "", "", "", ""); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
170 |
} catch (IllegalArgumentException e) { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
171 |
// illegal syntax; fall back to the default format |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
172 |
format = DEFAULT_FORMAT; |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
173 |
} |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
174 |
} else { |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
175 |
format = DEFAULT_FORMAT; |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
176 |
} |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
177 |
return format; |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
178 |
} |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
5506
diff
changeset
|
179 |
|
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff
changeset
|
180 |
} |