author | ohair |
Wed, 13 Apr 2011 16:56:16 -0700 | |
changeset 9050 | 26c2c1de1631 |
parent 9014 | 117374ccf1b7 |
parent 9035 | 1255eb81cc2f |
child 12526 | c4838d55279c |
permissions | -rw-r--r-- |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8512
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
4 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on 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 |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on 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. |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
10 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
16 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on 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. |
|
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
24 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
25 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
26 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
27 |
package sun.util.logging; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
28 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
29 |
import java.lang.ref.WeakReference; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
30 |
import java.lang.reflect.InvocationTargetException; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
31 |
import java.lang.reflect.Method; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
32 |
import java.io.PrintStream; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
33 |
import java.io.PrintWriter; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
34 |
import java.io.StringWriter; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
35 |
import java.security.AccessController; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
36 |
import java.security.PrivilegedAction; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
37 |
import java.text.MessageFormat; |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3861
diff
changeset
|
38 |
import java.util.Date; |
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3861
diff
changeset
|
39 |
import java.util.HashMap; |
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3861
diff
changeset
|
40 |
import java.util.Map; |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
41 |
import sun.misc.JavaLangAccess; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
42 |
import sun.misc.SharedSecrets; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
43 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
44 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
45 |
* Platform logger provides an API for the JRE components to log |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
46 |
* messages. This enables the runtime components to eliminate the |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
47 |
* static dependency of the logging facility and also defers the |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
48 |
* java.util.logging initialization until it is enabled. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
49 |
* In addition, the PlatformLogger API can be used if the logging |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
50 |
* module does not exist. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
51 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
52 |
* If the logging facility is not enabled, the platform loggers |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
53 |
* will output log messages per the default logging configuration |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
54 |
* (see below). In this implementation, it does not log the |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
55 |
* the stack frame information issuing the log message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
56 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
57 |
* When the logging facility is enabled (at startup or runtime), |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
58 |
* the java.util.logging.Logger will be created for each platform |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
59 |
* logger and all log messages will be forwarded to the Logger |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
60 |
* to handle. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
61 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
62 |
* Logging facility is "enabled" when one of the following |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
63 |
* conditions is met: |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
64 |
* 1) a system property "java.util.logging.config.class" or |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
65 |
* "java.util.logging.config.file" is set |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
66 |
* 2) java.util.logging.LogManager or java.util.logging.Logger |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
67 |
* is referenced that will trigger the logging initialization. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
68 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
69 |
* Default logging configuration: |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
70 |
* global logging level = INFO |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
71 |
* handlers = java.util.logging.ConsoleHandler |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
72 |
* java.util.logging.ConsoleHandler.level = INFO |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
73 |
* java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
74 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
75 |
* Limitation: |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
76 |
* <JAVA_HOME>/lib/logging.properties is the system-wide logging |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
77 |
* configuration defined in the specification and read in the |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
78 |
* default case to configure any java.util.logging.Logger instances. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
79 |
* Platform loggers will not detect if <JAVA_HOME>/lib/logging.properties |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
80 |
* is modified. In other words, unless the java.util.logging API |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
81 |
* is used at runtime or the logging system properties is set, |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
82 |
* the platform loggers will use the default setting described above. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
83 |
* The platform loggers are designed for JDK developers use and |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
84 |
* this limitation can be workaround with setting |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
85 |
* -Djava.util.logging.config.file system property. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
86 |
* |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
87 |
* @since 1.7 |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
88 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
89 |
public class PlatformLogger { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
90 |
// Same values as java.util.logging.Level for easy mapping |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
91 |
public static final int OFF = Integer.MAX_VALUE; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
92 |
public static final int SEVERE = 1000; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
93 |
public static final int WARNING = 900; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
94 |
public static final int INFO = 800; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
95 |
public static final int CONFIG = 700; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
96 |
public static final int FINE = 500; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
97 |
public static final int FINER = 400; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
98 |
public static final int FINEST = 300; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
99 |
public static final int ALL = Integer.MIN_VALUE; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
100 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
101 |
private static final int defaultLevel = INFO; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
102 |
private static boolean loggingEnabled; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
103 |
static { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
104 |
loggingEnabled = AccessController.doPrivileged( |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
105 |
new PrivilegedAction<Boolean>() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
106 |
public Boolean run() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
107 |
String cname = System.getProperty("java.util.logging.config.class"); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
108 |
String fname = System.getProperty("java.util.logging.config.file"); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
109 |
return (cname != null || fname != null); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
110 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
111 |
}); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
112 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
113 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
114 |
// Table of known loggers. Maps names to PlatformLoggers. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
115 |
private static Map<String,WeakReference<PlatformLogger>> loggers = |
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
7026
diff
changeset
|
116 |
new HashMap<>(); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
117 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
118 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
119 |
* Returns a PlatformLogger of a given name. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
120 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
121 |
public static synchronized PlatformLogger getLogger(String name) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
122 |
PlatformLogger log = null; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
123 |
WeakReference<PlatformLogger> ref = loggers.get(name); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
124 |
if (ref != null) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
125 |
log = ref.get(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
126 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
127 |
if (log == null) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
128 |
log = new PlatformLogger(name); |
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
7026
diff
changeset
|
129 |
loggers.put(name, new WeakReference<>(log)); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
130 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
131 |
return log; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
132 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
133 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
134 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
135 |
* Initialize java.util.logging.Logger objects for all platform loggers. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
136 |
* This method is called from LogManager.readPrimordialConfiguration(). |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
137 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
138 |
public static synchronized void redirectPlatformLoggers() { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
139 |
if (loggingEnabled || !LoggingSupport.isAvailable()) return; |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
140 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
141 |
loggingEnabled = true; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
142 |
for (Map.Entry<String, WeakReference<PlatformLogger>> entry : loggers.entrySet()) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
143 |
WeakReference<PlatformLogger> ref = entry.getValue(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
144 |
PlatformLogger plog = ref.get(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
145 |
if (plog != null) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
146 |
plog.newJavaLogger(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
147 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
148 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
149 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
150 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
151 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
152 |
* Creates a new JavaLogger that the platform logger uses |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
153 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
154 |
private void newJavaLogger() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
155 |
logger = new JavaLogger(logger.name, logger.effectiveLevel); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
156 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
157 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
158 |
// logger may be replaced with a JavaLogger object |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
159 |
// when the logging facility is enabled |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
160 |
private volatile LoggerProxy logger; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
161 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
162 |
private PlatformLogger(String name) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
163 |
if (loggingEnabled) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
164 |
this.logger = new JavaLogger(name); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
165 |
} else { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
166 |
this.logger = new LoggerProxy(name); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
167 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
168 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
169 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
170 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
171 |
* A convenience method to test if the logger is turned off. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
172 |
* (i.e. its level is OFF). |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
173 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
174 |
public boolean isEnabled() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
175 |
return logger.isEnabled(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
176 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
177 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
178 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
179 |
* Gets the name for this platform logger. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
180 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
181 |
public String getName() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
182 |
return logger.name; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
183 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
184 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
185 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
186 |
* Returns true if a message of the given level would actually |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
187 |
* be logged by this logger. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
188 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
189 |
public boolean isLoggable(int level) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
190 |
return logger.isLoggable(level); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
191 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
192 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
193 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
194 |
* Gets the current log level. Returns 0 if the current effective level |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
195 |
* is not set (equivalent to Logger.getLevel() returns null). |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
196 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
197 |
public int getLevel() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
198 |
return logger.getLevel(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
199 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
200 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
201 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
202 |
* Sets the log level. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
203 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
204 |
public void setLevel(int newLevel) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
205 |
logger.setLevel(newLevel); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
206 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
207 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
208 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
209 |
* Logs a SEVERE message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
210 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
211 |
public void severe(String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
212 |
logger.doLog(SEVERE, msg); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
213 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
214 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
215 |
public void severe(String msg, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
216 |
logger.doLog(SEVERE, msg, t); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
217 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
218 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
219 |
public void severe(String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
220 |
logger.doLog(SEVERE, msg, params); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
221 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
222 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
223 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
224 |
* Logs a WARNING message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
225 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
226 |
public void warning(String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
227 |
logger.doLog(WARNING, msg); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
228 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
229 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
230 |
public void warning(String msg, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
231 |
logger.doLog(WARNING, msg, t); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
232 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
233 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
234 |
public void warning(String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
235 |
logger.doLog(WARNING, msg, params); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
236 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
237 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
238 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
239 |
* Logs an INFO message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
240 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
241 |
public void info(String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
242 |
logger.doLog(INFO, msg); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
243 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
244 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
245 |
public void info(String msg, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
246 |
logger.doLog(INFO, msg, t); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
247 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
248 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
249 |
public void info(String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
250 |
logger.doLog(INFO, msg, params); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
251 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
252 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
253 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
254 |
* Logs a CONFIG message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
255 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
256 |
public void config(String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
257 |
logger.doLog(CONFIG, msg); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
258 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
259 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
260 |
public void config(String msg, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
261 |
logger.doLog(CONFIG, msg, t); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
262 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
263 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
264 |
public void config(String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
265 |
logger.doLog(CONFIG, msg, params); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
266 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
267 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
268 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
269 |
* Logs a FINE message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
270 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
271 |
public void fine(String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
272 |
logger.doLog(FINE, msg); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
273 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
274 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
275 |
public void fine(String msg, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
276 |
logger.doLog(FINE, msg, t); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
277 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
278 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
279 |
public void fine(String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
280 |
logger.doLog(FINE, msg, params); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
281 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
282 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
283 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
284 |
* Logs a FINER message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
285 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
286 |
public void finer(String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
287 |
logger.doLog(FINER, msg); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
288 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
289 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
290 |
public void finer(String msg, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
291 |
logger.doLog(FINER, msg, t); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
292 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
293 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
294 |
public void finer(String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
295 |
logger.doLog(FINER, msg, params); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
296 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
297 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
298 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
299 |
* Logs a FINEST message. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
300 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
301 |
public void finest(String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
302 |
logger.doLog(FINEST, msg); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
303 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
304 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
305 |
public void finest(String msg, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
306 |
logger.doLog(FINEST, msg, t); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
307 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
308 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
309 |
public void finest(String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
310 |
logger.doLog(FINEST, msg, params); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
311 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
312 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
313 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
314 |
* Default platform logging support - output messages to |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
315 |
* System.err - equivalent to ConsoleHandler with SimpleFormatter. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
316 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
317 |
static class LoggerProxy { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
318 |
private static final PrintStream defaultStream = System.err; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
319 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
320 |
final String name; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
321 |
volatile int levelValue; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
322 |
volatile int effectiveLevel = 0; // current effective level value |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
323 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
324 |
LoggerProxy(String name) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
325 |
this(name, defaultLevel); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
326 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
327 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
328 |
LoggerProxy(String name, int level) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
329 |
this.name = name; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
330 |
this.levelValue = level == 0 ? defaultLevel : level; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
331 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
332 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
333 |
boolean isEnabled() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
334 |
return levelValue != OFF; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
335 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
336 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
337 |
int getLevel() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
338 |
return effectiveLevel; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
339 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
340 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
341 |
void setLevel(int newLevel) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
342 |
levelValue = newLevel; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
343 |
effectiveLevel = newLevel; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
344 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
345 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
346 |
void doLog(int level, String msg) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
347 |
if (level < levelValue || levelValue == OFF) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
348 |
return; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
349 |
} |
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
350 |
defaultStream.print(format(level, msg, null)); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
351 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
352 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
353 |
void doLog(int level, String msg, Throwable thrown) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
354 |
if (level < levelValue || levelValue == OFF) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
355 |
return; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
356 |
} |
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
357 |
defaultStream.print(format(level, msg, thrown)); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
358 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
359 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
360 |
void doLog(int level, String msg, Object... params) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
361 |
if (level < levelValue || levelValue == OFF) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
362 |
return; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
363 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
364 |
String newMsg = formatMessage(msg, params); |
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
365 |
defaultStream.print(format(level, newMsg, null)); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
366 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
367 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
368 |
public boolean isLoggable(int level) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
369 |
if (level < levelValue || levelValue == OFF) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
370 |
return false; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
371 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
372 |
return true; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
373 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
374 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
375 |
// Copied from java.util.logging.Formatter.formatMessage |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
376 |
private String formatMessage(String format, Object... parameters) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
377 |
// Do the formatting. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
378 |
try { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
379 |
if (parameters == null || parameters.length == 0) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
380 |
// No parameters. Just return format string. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
381 |
return format; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
382 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
383 |
// Is it a java.text style format? |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
384 |
// Ideally we could match with |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
385 |
// Pattern.compile("\\{\\d").matcher(format).find()) |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
386 |
// However the cost is 14% higher, so we cheaply check for |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
387 |
// 1 of the first 4 parameters |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
388 |
if (format.indexOf("{0") >= 0 || format.indexOf("{1") >=0 || |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
389 |
format.indexOf("{2") >=0|| format.indexOf("{3") >=0) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
390 |
return java.text.MessageFormat.format(format, parameters); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
391 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
392 |
return format; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
393 |
} catch (Exception ex) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
394 |
// Formatting failed: use format string. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
395 |
return format; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
396 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
397 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
398 |
|
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
399 |
private static final String formatString = |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
400 |
LoggingSupport.getSimpleFormat(false); // don't check logging.properties |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
401 |
|
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
402 |
// minimize memory allocation |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
403 |
private Date date = new Date(); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
404 |
private synchronized String format(int level, String msg, Throwable thrown) { |
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
405 |
date.setTime(System.currentTimeMillis()); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
406 |
String throwable = ""; |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
407 |
if (thrown != null) { |
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
408 |
StringWriter sw = new StringWriter(); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
409 |
PrintWriter pw = new PrintWriter(sw); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
410 |
pw.println(); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
411 |
thrown.printStackTrace(pw); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
412 |
pw.close(); |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
413 |
throwable = sw.toString(); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
414 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
415 |
|
9014
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
416 |
return String.format(formatString, |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
417 |
date, |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
418 |
getCallerInfo(), |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
419 |
name, |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
420 |
PlatformLogger.getLevelName(level), |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
421 |
msg, |
117374ccf1b7
6381464: SimpleFormatter should use one single line format
mchung
parents:
8512
diff
changeset
|
422 |
throwable); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
423 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
424 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
425 |
// Returns the caller's class and method's name; best effort |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
426 |
// if cannot infer, return the logger's name. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
427 |
private String getCallerInfo() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
428 |
String sourceClassName = null; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
429 |
String sourceMethodName = null; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
430 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
431 |
JavaLangAccess access = SharedSecrets.getJavaLangAccess(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
432 |
Throwable throwable = new Throwable(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
433 |
int depth = access.getStackTraceDepth(throwable); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
434 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
435 |
String logClassName = "sun.util.logging.PlatformLogger"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
436 |
boolean lookingForLogger = true; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
437 |
for (int ix = 0; ix < depth; ix++) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
438 |
// Calling getStackTraceElement directly prevents the VM |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
439 |
// from paying the cost of building the entire stack frame. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
440 |
StackTraceElement frame = |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
441 |
access.getStackTraceElement(throwable, ix); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
442 |
String cname = frame.getClassName(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
443 |
if (lookingForLogger) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
444 |
// Skip all frames until we have found the first logger frame. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
445 |
if (cname.equals(logClassName)) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
446 |
lookingForLogger = false; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
447 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
448 |
} else { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
449 |
if (!cname.equals(logClassName)) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
450 |
// We've found the relevant frame. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
451 |
sourceClassName = cname; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
452 |
sourceMethodName = frame.getMethodName(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
453 |
break; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
454 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
455 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
456 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
457 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
458 |
if (sourceClassName != null) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
459 |
return sourceClassName + " " + sourceMethodName; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
460 |
} else { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
461 |
return name; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
462 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
463 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
464 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
465 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
466 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
467 |
* JavaLogger forwards all the calls to its corresponding |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
468 |
* java.util.logging.Logger object. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
469 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
470 |
static class JavaLogger extends LoggerProxy { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
471 |
private static final Map<Integer, Object> levelObjects = |
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
7026
diff
changeset
|
472 |
new HashMap<>(); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
473 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
474 |
static { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
475 |
if (LoggingSupport.isAvailable()) { |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
476 |
// initialize the map to Level objects |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
477 |
getLevelObjects(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
478 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
479 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
480 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
481 |
private static void getLevelObjects() { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
482 |
// get all java.util.logging.Level objects |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
483 |
int[] levelArray = new int[] {OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL}; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
484 |
for (int l : levelArray) { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
485 |
Object level = LoggingSupport.parseLevel(getLevelName(l)); |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
486 |
levelObjects.put(l, level); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
487 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
488 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
489 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
490 |
private final Object javaLogger; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
491 |
JavaLogger(String name) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
492 |
this(name, 0); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
493 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
494 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
495 |
JavaLogger(String name, int level) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
496 |
super(name, level); |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
497 |
this.javaLogger = LoggingSupport.getLogger(name); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
498 |
if (level != 0) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
499 |
// level has been updated and so set the Logger's level |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
500 |
LoggingSupport.setLevel(javaLogger, levelObjects.get(level)); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
501 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
502 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
503 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
504 |
/** |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
505 |
* Let Logger.log() do the filtering since if the level of a |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
506 |
* platform logger is altered directly from |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
507 |
* java.util.logging.Logger.setLevel(), the levelValue will |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
508 |
* not be updated. |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
509 |
*/ |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
510 |
void doLog(int level, String msg) { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
511 |
LoggingSupport.log(javaLogger, levelObjects.get(level), msg); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
512 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
513 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
514 |
void doLog(int level, String msg, Throwable t) { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
515 |
LoggingSupport.log(javaLogger, levelObjects.get(level), msg, t); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
516 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
517 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
518 |
void doLog(int level, String msg, Object... params) { |
8512 | 519 |
// only pass String objects to the j.u.l.Logger which may |
520 |
// be created by untrusted code |
|
521 |
int len = (params != null) ? params.length : 0; |
|
522 |
Object[] sparams = new String[len]; |
|
523 |
for (int i = 0; i < len; i++) { |
|
524 |
sparams [i] = String.valueOf(params[i]); |
|
525 |
} |
|
526 |
LoggingSupport.log(javaLogger, levelObjects.get(level), msg, sparams); |
|
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
527 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
528 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
529 |
boolean isEnabled() { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
530 |
Object level = LoggingSupport.getLevel(javaLogger); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
531 |
return level == null || level.equals(levelObjects.get(OFF)) == false; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
532 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
533 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
534 |
int getLevel() { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
535 |
Object level = LoggingSupport.getLevel(javaLogger); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
536 |
if (level != null) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
537 |
for (Map.Entry<Integer, Object> l : levelObjects.entrySet()) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
538 |
if (level == l.getValue()) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
539 |
return l.getKey(); |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
540 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
541 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
542 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
543 |
return 0; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
544 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
545 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
546 |
void setLevel(int newLevel) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
547 |
levelValue = newLevel; |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
548 |
LoggingSupport.setLevel(javaLogger, levelObjects.get(newLevel)); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
549 |
} |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3861
diff
changeset
|
550 |
|
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3861
diff
changeset
|
551 |
public boolean isLoggable(int level) { |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3866
diff
changeset
|
552 |
return LoggingSupport.isLoggable(javaLogger, levelObjects.get(level)); |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3861
diff
changeset
|
553 |
} |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
554 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
555 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
556 |
private static String getLevelName(int level) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
557 |
switch (level) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
558 |
case OFF : return "OFF"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
559 |
case SEVERE : return "SEVERE"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
560 |
case WARNING : return "WARNING"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
561 |
case INFO : return "INFO"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
562 |
case CONFIG : return "CONFIG"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
563 |
case FINE : return "FINE"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
564 |
case FINER : return "FINER"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
565 |
case FINEST : return "FINEST"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
566 |
case ALL : return "ALL"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
567 |
default : return "UNKNOWN"; |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
568 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
569 |
} |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
570 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
diff
changeset
|
571 |
} |