author | dfuchs |
Wed, 14 May 2014 15:40:39 +0200 | |
changeset 27074 | 4abca40e7d0c |
parent 26961 | 8203ecb092af |
child 29094 | a4fd2b5e49f8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
27074 | 2 |
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
||
27 |
package java.util.logging; |
|
28 |
||
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
29 |
import java.lang.ref.WeakReference; |
16483 | 30 |
import java.security.AccessController; |
31 |
import java.security.PrivilegedAction; |
|
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
32 |
import java.util.ArrayList; |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
33 |
import java.util.Iterator; |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
34 |
import java.util.Locale; |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
35 |
import java.util.MissingResourceException; |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
36 |
import java.util.ResourceBundle; |
1933 | 37 |
import java.util.concurrent.CopyOnWriteArrayList; |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
38 |
import java.util.function.Supplier; |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16483
diff
changeset
|
39 |
import sun.reflect.CallerSensitive; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16483
diff
changeset
|
40 |
import sun.reflect.Reflection; |
2 | 41 |
|
42 |
/** |
|
43 |
* A Logger object is used to log messages for a specific |
|
44 |
* system or application component. Loggers are normally named, |
|
45 |
* using a hierarchical dot-separated namespace. Logger names |
|
46 |
* can be arbitrary strings, but they should normally be based on |
|
47 |
* the package name or class name of the logged component, such |
|
48 |
* as java.net or javax.swing. In addition it is possible to create |
|
49 |
* "anonymous" Loggers that are not stored in the Logger namespace. |
|
50 |
* <p> |
|
51 |
* Logger objects may be obtained by calls on one of the getLogger |
|
52 |
* factory methods. These will either create a new Logger or |
|
6675
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
53 |
* return a suitable existing Logger. It is important to note that |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
54 |
* the Logger returned by one of the {@code getLogger} factory methods |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
55 |
* may be garbage collected at any time if a strong reference to the |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
56 |
* Logger is not kept. |
2 | 57 |
* <p> |
58 |
* Logging messages will be forwarded to registered Handler |
|
59 |
* objects, which can forward the messages to a variety of |
|
60 |
* destinations, including consoles, files, OS logs, etc. |
|
61 |
* <p> |
|
62 |
* Each Logger keeps track of a "parent" Logger, which is its |
|
63 |
* nearest existing ancestor in the Logger namespace. |
|
64 |
* <p> |
|
65 |
* Each Logger has a "Level" associated with it. This reflects |
|
66 |
* a minimum Level that this logger cares about. If a Logger's |
|
67 |
* level is set to <tt>null</tt>, then its effective level is inherited |
|
68 |
* from its parent, which may in turn obtain it recursively from its |
|
69 |
* parent, and so on up the tree. |
|
70 |
* <p> |
|
71 |
* The log level can be configured based on the properties from the |
|
72 |
* logging configuration file, as described in the description |
|
73 |
* of the LogManager class. However it may also be dynamically changed |
|
74 |
* by calls on the Logger.setLevel method. If a logger's level is |
|
75 |
* changed the change may also affect child loggers, since any child |
|
76 |
* logger that has <tt>null</tt> as its level will inherit its |
|
77 |
* effective level from its parent. |
|
78 |
* <p> |
|
79 |
* On each logging call the Logger initially performs a cheap |
|
3853 | 80 |
* check of the request level (e.g., SEVERE or FINE) against the |
2 | 81 |
* effective log level of the logger. If the request level is |
82 |
* lower than the log level, the logging call returns immediately. |
|
83 |
* <p> |
|
84 |
* After passing this initial (cheap) test, the Logger will allocate |
|
85 |
* a LogRecord to describe the logging message. It will then call a |
|
86 |
* Filter (if present) to do a more detailed check on whether the |
|
87 |
* record should be published. If that passes it will then publish |
|
88 |
* the LogRecord to its output Handlers. By default, loggers also |
|
89 |
* publish to their parent's Handlers, recursively up the tree. |
|
90 |
* <p> |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
91 |
* Each Logger may have a {@code ResourceBundle} associated with it. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
92 |
* The {@code ResourceBundle} may be specified by name, using the |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
93 |
* {@link #getLogger(java.lang.String, java.lang.String)} factory |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
94 |
* method, or by value - using the {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
95 |
* #setResourceBundle(java.util.ResourceBundle) setResourceBundle} method. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
96 |
* This bundle will be used for localizing logging messages. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
97 |
* If a Logger does not have its own {@code ResourceBundle} or resource bundle |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
98 |
* name, then it will inherit the {@code ResourceBundle} or resource bundle name |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
99 |
* from its parent, recursively up the tree. |
2 | 100 |
* <p> |
101 |
* Most of the logger output methods take a "msg" argument. This |
|
102 |
* msg argument may be either a raw value or a localization key. |
|
103 |
* During formatting, if the logger has (or inherits) a localization |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
104 |
* {@code ResourceBundle} and if the {@code ResourceBundle} has a mapping for |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
105 |
* the msg string, then the msg string is replaced by the localized value. |
2 | 106 |
* Otherwise the original msg string is used. Typically, formatters use |
107 |
* java.text.MessageFormat style formatting to format parameters, so |
|
108 |
* for example a format string "{0} {1}" would format two parameters |
|
109 |
* as strings. |
|
110 |
* <p> |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
111 |
* A set of methods alternatively take a "msgSupplier" instead of a "msg" |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
112 |
* argument. These methods take a {@link Supplier}{@code <String>} function |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
113 |
* which is invoked to construct the desired log message only when the message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
114 |
* actually is to be logged based on the effective log level thus eliminating |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
115 |
* unnecessary message construction. For example, if the developer wants to |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
116 |
* log system health status for diagnosis, with the String-accepting version, |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
117 |
* the code would look like: |
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
118 |
<pre><code> |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
119 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
120 |
class DiagnosisMessages { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
121 |
static String systemHealthStatus() { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
122 |
// collect system health information |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
123 |
... |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
124 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
125 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
126 |
... |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
127 |
logger.log(Level.FINER, DiagnosisMessages.systemHealthStatus()); |
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
128 |
</code></pre> |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
129 |
* With the above code, the health status is collected unnecessarily even when |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
130 |
* the log level FINER is disabled. With the Supplier-accepting version as |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
131 |
* below, the status will only be collected when the log level FINER is |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
132 |
* enabled. |
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
133 |
<pre><code> |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
134 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
135 |
logger.log(Level.FINER, DiagnosisMessages::systemHealthStatus); |
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
136 |
</code></pre> |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
137 |
* <p> |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
138 |
* When looking for a {@code ResourceBundle}, the logger will first look at |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
139 |
* whether a bundle was specified using {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
140 |
* #setResourceBundle(java.util.ResourceBundle) setResourceBundle}, and then |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
141 |
* only whether a resource bundle name was specified through the {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
142 |
* #getLogger(java.lang.String, java.lang.String) getLogger} factory method. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
143 |
* If no {@code ResourceBundle} or no resource bundle name is found, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
144 |
* then it will use the nearest {@code ResourceBundle} or resource bundle |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
145 |
* name inherited from its parent tree.<br> |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
146 |
* When a {@code ResourceBundle} was inherited or specified through the |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
147 |
* {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
148 |
* #setResourceBundle(java.util.ResourceBundle) setResourceBundle} method, then |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
149 |
* that {@code ResourceBundle} will be used. Otherwise if the logger only |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
150 |
* has or inherited a resource bundle name, then that resource bundle name |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
151 |
* will be mapped to a {@code ResourceBundle} object, using the default Locale |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
152 |
* at the time of logging. |
21334 | 153 |
* <br id="ResourceBundleMapping">When mapping resource bundle names to |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
154 |
* {@code ResourceBundle} objects, the logger will first try to use the |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
155 |
* Thread's {@linkplain java.lang.Thread#getContextClassLoader() context class |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
156 |
* loader} to map the given resource bundle name to a {@code ResourceBundle}. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
157 |
* If the thread context class loader is {@code null}, it will try the |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
158 |
* {@linkplain java.lang.ClassLoader#getSystemClassLoader() system class loader} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
159 |
* instead. If the {@code ResourceBundle} is still not found, it will use the |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
160 |
* class loader of the first caller of the {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
161 |
* #getLogger(java.lang.String, java.lang.String) getLogger} factory method. |
2 | 162 |
* <p> |
163 |
* Formatting (including localization) is the responsibility of |
|
164 |
* the output Handler, which will typically call a Formatter. |
|
165 |
* <p> |
|
166 |
* Note that formatting need not occur synchronously. It may be delayed |
|
167 |
* until a LogRecord is actually written to an external sink. |
|
168 |
* <p> |
|
169 |
* The logging methods are grouped in five main categories: |
|
170 |
* <ul> |
|
171 |
* <li><p> |
|
172 |
* There are a set of "log" methods that take a log level, a message |
|
173 |
* string, and optionally some parameters to the message string. |
|
174 |
* <li><p> |
|
175 |
* There are a set of "logp" methods (for "log precise") that are |
|
176 |
* like the "log" methods, but also take an explicit source class name |
|
177 |
* and method name. |
|
178 |
* <li><p> |
|
179 |
* There are a set of "logrb" method (for "log with resource bundle") |
|
180 |
* that are like the "logp" method, but also take an explicit resource |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
181 |
* bundle object for use in localizing the log message. |
2 | 182 |
* <li><p> |
183 |
* There are convenience methods for tracing method entries (the |
|
184 |
* "entering" methods), method returns (the "exiting" methods) and |
|
185 |
* throwing exceptions (the "throwing" methods). |
|
186 |
* <li><p> |
|
187 |
* Finally, there are a set of convenience methods for use in the |
|
188 |
* very simplest cases, when a developer simply wants to log a |
|
189 |
* simple string at a given log level. These methods are named |
|
190 |
* after the standard Level names ("severe", "warning", "info", etc.) |
|
191 |
* and take a single argument, a message string. |
|
192 |
* </ul> |
|
193 |
* <p> |
|
194 |
* For the methods that do not take an explicit source name and |
|
195 |
* method name, the Logging framework will make a "best effort" |
|
196 |
* to determine which class and method called into the logging method. |
|
197 |
* However, it is important to realize that this automatically inferred |
|
198 |
* information may only be approximate (or may even be quite wrong!). |
|
199 |
* Virtual machines are allowed to do extensive optimizations when |
|
200 |
* JITing and may entirely remove stack frames, making it impossible |
|
201 |
* to reliably locate the calling class and method. |
|
202 |
* <P> |
|
203 |
* All methods on Logger are multi-thread safe. |
|
204 |
* <p> |
|
205 |
* <b>Subclassing Information:</b> Note that a LogManager class may |
|
206 |
* provide its own implementation of named Loggers for any point in |
|
207 |
* the namespace. Therefore, any subclasses of Logger (unless they |
|
208 |
* are implemented in conjunction with a new LogManager class) should |
|
209 |
* take care to obtain a Logger instance from the LogManager class and |
|
210 |
* should delegate operations such as "isLoggable" and "log(LogRecord)" |
|
211 |
* to that instance. Note that in order to intercept all logging |
|
212 |
* output, subclasses need only override the log(LogRecord) method. |
|
213 |
* All the other logging methods are implemented as calls on this |
|
214 |
* log(LogRecord) method. |
|
215 |
* |
|
216 |
* @since 1.4 |
|
217 |
*/ |
|
218 |
public class Logger { |
|
219 |
private static final Handler emptyHandlers[] = new Handler[0]; |
|
220 |
private static final int offValue = Level.OFF.intValue(); |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
221 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
222 |
static final String SYSTEM_LOGGER_RB_NAME = "sun.util.logging.resources.logging"; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
223 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
224 |
// This class is immutable and it is important that it remains so. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
225 |
private static final class LoggerBundle { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
226 |
final String resourceBundleName; // Base name of the bundle. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
227 |
final ResourceBundle userBundle; // Bundle set through setResourceBundle. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
228 |
private LoggerBundle(String resourceBundleName, ResourceBundle bundle) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
229 |
this.resourceBundleName = resourceBundleName; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
230 |
this.userBundle = bundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
231 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
232 |
boolean isSystemBundle() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
233 |
return SYSTEM_LOGGER_RB_NAME.equals(resourceBundleName); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
234 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
235 |
static LoggerBundle get(String name, ResourceBundle bundle) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
236 |
if (name == null && bundle == null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
237 |
return NO_RESOURCE_BUNDLE; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
238 |
} else if (SYSTEM_LOGGER_RB_NAME.equals(name) && bundle == null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
239 |
return SYSTEM_BUNDLE; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
240 |
} else { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
241 |
return new LoggerBundle(name, bundle); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
242 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
243 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
244 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
245 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
246 |
// This instance will be shared by all loggers created by the system |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
247 |
// code |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
248 |
private static final LoggerBundle SYSTEM_BUNDLE = |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
249 |
new LoggerBundle(SYSTEM_LOGGER_RB_NAME, null); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
250 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
251 |
// This instance indicates that no resource bundle has been specified yet, |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
252 |
// and it will be shared by all loggers which have no resource bundle. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
253 |
private static final LoggerBundle NO_RESOURCE_BUNDLE = |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
254 |
new LoggerBundle(null, null); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
255 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
256 |
private volatile LogManager manager; |
2 | 257 |
private String name; |
1933 | 258 |
private final CopyOnWriteArrayList<Handler> handlers = |
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
6675
diff
changeset
|
259 |
new CopyOnWriteArrayList<>(); |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
260 |
private volatile LoggerBundle loggerBundle = NO_RESOURCE_BUNDLE; |
1933 | 261 |
private volatile boolean useParentHandlers = true; |
262 |
private volatile Filter filter; |
|
2 | 263 |
private boolean anonymous; |
264 |
||
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
265 |
// Cache to speed up behavior of findResourceBundle: |
2 | 266 |
private ResourceBundle catalog; // Cached resource bundle |
267 |
private String catalogName; // name associated with catalog |
|
268 |
private Locale catalogLocale; // locale associated with catalog |
|
269 |
||
270 |
// The fields relating to parent-child relationships and levels |
|
271 |
// are managed under a separate lock, the treeLock. |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
272 |
private static final Object treeLock = new Object(); |
2 | 273 |
// We keep weak references from parents to children, but strong |
274 |
// references from children to parents. |
|
1933 | 275 |
private volatile Logger parent; // our nearest parent. |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
276 |
private ArrayList<LogManager.LoggerWeakRef> kids; // WeakReferences to loggers that have us as parent |
1933 | 277 |
private volatile Level levelObject; |
2 | 278 |
private volatile int levelValue; // current effective level value |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
279 |
private WeakReference<ClassLoader> callersClassLoaderRef; |
23899 | 280 |
private final boolean isSystemLogger; |
2 | 281 |
|
282 |
/** |
|
283 |
* GLOBAL_LOGGER_NAME is a name for the global logger. |
|
284 |
* |
|
285 |
* @since 1.6 |
|
286 |
*/ |
|
287 |
public static final String GLOBAL_LOGGER_NAME = "global"; |
|
288 |
||
289 |
/** |
|
290 |
* Return global logger object with the name Logger.GLOBAL_LOGGER_NAME. |
|
291 |
* |
|
292 |
* @return global logger object |
|
293 |
* @since 1.7 |
|
294 |
*/ |
|
295 |
public static final Logger getGlobal() { |
|
18595
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
296 |
// In order to break a cyclic dependence between the LogManager |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
297 |
// and Logger static initializers causing deadlocks, the global |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
298 |
// logger is created with a special constructor that does not |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
299 |
// initialize its log manager. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
300 |
// |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
301 |
// If an application calls Logger.getGlobal() before any logger |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
302 |
// has been initialized, it is therefore possible that the |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
303 |
// LogManager class has not been initialized yet, and therefore |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
304 |
// Logger.global.manager will be null. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
305 |
// |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
306 |
// In order to finish the initialization of the global logger, we |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
307 |
// will therefore call LogManager.getLogManager() here. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
17487
diff
changeset
|
308 |
// |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
309 |
// To prevent race conditions we also need to call |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
310 |
// LogManager.getLogManager() unconditionally here. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
311 |
// Indeed we cannot rely on the observed value of global.manager, |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
312 |
// because global.manager will become not null somewhere during |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
313 |
// the initialization of LogManager. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
314 |
// If two threads are calling getGlobal() concurrently, one thread |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
315 |
// will see global.manager null and call LogManager.getLogManager(), |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
316 |
// but the other thread could come in at a time when global.manager |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
317 |
// is already set although ensureLogManagerInitialized is not finished |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
318 |
// yet... |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
319 |
// Calling LogManager.getLogManager() unconditionally will fix that. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
320 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
321 |
LogManager.getLogManager(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
322 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
323 |
// Now the global LogManager should be initialized, |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
324 |
// and the global logger should have been added to |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
325 |
// it, unless we were called within the constructor of a LogManager |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
326 |
// subclass installed as LogManager, in which case global.manager |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
327 |
// would still be null, and global will be lazily initialized later on. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
328 |
|
2 | 329 |
return global; |
330 |
} |
|
331 |
||
332 |
/** |
|
333 |
* The "global" Logger object is provided as a convenience to developers |
|
334 |
* who are making casual use of the Logging package. Developers |
|
335 |
* who are making serious use of the logging package (for example |
|
336 |
* in products) should create and use their own Logger objects, |
|
337 |
* with appropriate names, so that logging can be controlled on a |
|
6675
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
338 |
* suitable per-Logger granularity. Developers also need to keep a |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
339 |
* strong reference to their Logger objects to prevent them from |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
340 |
* being garbage collected. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
341 |
* |
2 | 342 |
* @deprecated Initialization of this field is prone to deadlocks. |
343 |
* The field must be initialized by the Logger class initialization |
|
344 |
* which may cause deadlocks with the LogManager class initialization. |
|
345 |
* In such cases two class initialization wait for each other to complete. |
|
346 |
* The preferred way to get the global logger object is via the call |
|
347 |
* <code>Logger.getGlobal()</code>. |
|
348 |
* For compatibility with old JDK versions where the |
|
349 |
* <code>Logger.getGlobal()</code> is not available use the call |
|
350 |
* <code>Logger.getLogger(Logger.GLOBAL_LOGGER_NAME)</code> |
|
351 |
* or <code>Logger.getLogger("global")</code>. |
|
352 |
*/ |
|
353 |
@Deprecated |
|
354 |
public static final Logger global = new Logger(GLOBAL_LOGGER_NAME); |
|
355 |
||
356 |
/** |
|
357 |
* Protected method to construct a logger for a named subsystem. |
|
358 |
* <p> |
|
359 |
* The logger will be initially configured with a null Level |
|
3853 | 360 |
* and with useParentHandlers set to true. |
2 | 361 |
* |
362 |
* @param name A name for the logger. This should |
|
363 |
* be a dot-separated name and should normally |
|
364 |
* be based on the package name or class name |
|
365 |
* of the subsystem, such as java.net |
|
366 |
* or javax.swing. It may be null for anonymous Loggers. |
|
367 |
* @param resourceBundleName name of ResourceBundle to be used for localizing |
|
368 |
* messages for this logger. May be null if none |
|
369 |
* of the messages require localization. |
|
3853 | 370 |
* @throws MissingResourceException if the resourceBundleName is non-null and |
2 | 371 |
* no corresponding resource can be found. |
372 |
*/ |
|
373 |
protected Logger(String name, String resourceBundleName) { |
|
23899 | 374 |
this(name, resourceBundleName, null, LogManager.getLogManager(), false); |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
375 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
376 |
|
23899 | 377 |
Logger(String name, String resourceBundleName, Class<?> caller, LogManager manager, boolean isSystemLogger) { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
378 |
this.manager = manager; |
23899 | 379 |
this.isSystemLogger = isSystemLogger; |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
380 |
setupResourceInfo(resourceBundleName, caller); |
2 | 381 |
this.name = name; |
382 |
levelValue = Level.INFO.intValue(); |
|
383 |
} |
|
384 |
||
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
385 |
private void setCallersClassLoaderRef(Class<?> caller) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
386 |
ClassLoader callersClassLoader = ((caller != null) |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
387 |
? caller.getClassLoader() |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
388 |
: null); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
389 |
if (callersClassLoader != null) { |
21655
55f32ae4f920
8028229: Fix more raw types lint warning in core libraries
darcy
parents:
21369
diff
changeset
|
390 |
this.callersClassLoaderRef = new WeakReference<>(callersClassLoader); |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
391 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
392 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
393 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
394 |
private ClassLoader getCallersClassLoader() { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
395 |
return (callersClassLoaderRef != null) |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
396 |
? callersClassLoaderRef.get() |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
397 |
: null; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
398 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
399 |
|
2 | 400 |
// This constructor is used only to create the global Logger. |
401 |
// It is needed to break a cyclic dependence between the LogManager |
|
402 |
// and Logger static initializers causing deadlocks. |
|
403 |
private Logger(String name) { |
|
404 |
// The manager field is not initialized here. |
|
405 |
this.name = name; |
|
23899 | 406 |
this.isSystemLogger = true; |
2 | 407 |
levelValue = Level.INFO.intValue(); |
408 |
} |
|
409 |
||
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
410 |
// It is called from LoggerContext.addLocalLogger() when the logger |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19584
diff
changeset
|
411 |
// is actually added to a LogManager. |
2 | 412 |
void setLogManager(LogManager manager) { |
413 |
this.manager = manager; |
|
414 |
} |
|
415 |
||
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
10046
diff
changeset
|
416 |
private void checkPermission() throws SecurityException { |
2 | 417 |
if (!anonymous) { |
418 |
if (manager == null) { |
|
419 |
// Complete initialization of the global Logger. |
|
420 |
manager = LogManager.getLogManager(); |
|
421 |
} |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
10046
diff
changeset
|
422 |
manager.checkPermission(); |
2 | 423 |
} |
424 |
} |
|
425 |
||
16098 | 426 |
// Until all JDK code converted to call sun.util.logging.PlatformLogger |
427 |
// (see 7054233), we need to determine if Logger.getLogger is to add |
|
428 |
// a system logger or user logger. |
|
429 |
// |
|
430 |
// As an interim solution, if the immediate caller whose caller loader is |
|
431 |
// null, we assume it's a system logger and add it to the system context. |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
432 |
// These system loggers only set the resource bundle to the given |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
433 |
// resource bundle name (rather than the default system resource bundle). |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
434 |
private static class SystemLoggerHelper { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
435 |
static boolean disableCallerCheck = getBooleanProperty("sun.util.logging.disableCallerCheck"); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
436 |
private static boolean getBooleanProperty(final String key) { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
437 |
String s = AccessController.doPrivileged(new PrivilegedAction<String>() { |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
438 |
@Override |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
439 |
public String run() { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
440 |
return System.getProperty(key); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
441 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
442 |
}); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
443 |
return Boolean.valueOf(s); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
444 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
445 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
446 |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16483
diff
changeset
|
447 |
private static Logger demandLogger(String name, String resourceBundleName, Class<?> caller) { |
16098 | 448 |
LogManager manager = LogManager.getLogManager(); |
449 |
SecurityManager sm = System.getSecurityManager(); |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
450 |
if (sm != null && !SystemLoggerHelper.disableCallerCheck) { |
16098 | 451 |
if (caller.getClassLoader() == null) { |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
452 |
return manager.demandSystemLogger(name, resourceBundleName); |
16098 | 453 |
} |
454 |
} |
|
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
455 |
return manager.demandLogger(name, resourceBundleName, caller); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
456 |
// ends up calling new Logger(name, resourceBundleName, caller) |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
457 |
// iff the logger doesn't exist already |
16098 | 458 |
} |
459 |
||
2 | 460 |
/** |
461 |
* Find or create a logger for a named subsystem. If a logger has |
|
462 |
* already been created with the given name it is returned. Otherwise |
|
463 |
* a new logger is created. |
|
464 |
* <p> |
|
465 |
* If a new logger is created its log level will be configured |
|
466 |
* based on the LogManager configuration and it will configured |
|
3853 | 467 |
* to also send logging output to its parent's Handlers. It will |
2 | 468 |
* be registered in the LogManager global namespace. |
6675
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
469 |
* <p> |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
470 |
* Note: The LogManager may only retain a weak reference to the newly |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
471 |
* created Logger. It is important to understand that a previously |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
472 |
* created Logger with the given name may be garbage collected at any |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
473 |
* time if there is no strong reference to the Logger. In particular, |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
474 |
* this means that two back-to-back calls like |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
475 |
* {@code getLogger("MyLogger").log(...)} may use different Logger |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
476 |
* objects named "MyLogger" if there is no strong reference to the |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
477 |
* Logger named "MyLogger" elsewhere in the program. |
2 | 478 |
* |
479 |
* @param name A name for the logger. This should |
|
480 |
* be a dot-separated name and should normally |
|
481 |
* be based on the package name or class name |
|
482 |
* of the subsystem, such as java.net |
|
483 |
* or javax.swing |
|
484 |
* @return a suitable Logger |
|
485 |
* @throws NullPointerException if the name is null. |
|
486 |
*/ |
|
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
487 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
488 |
// Synchronization is not required here. All synchronization for |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
489 |
// adding a new Logger object is handled by LogManager.addLogger(). |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16483
diff
changeset
|
490 |
@CallerSensitive |
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
491 |
public static Logger getLogger(String name) { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
492 |
// This method is intentionally not a wrapper around a call |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
493 |
// to getLogger(name, resourceBundleName). If it were then |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
494 |
// this sequence: |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
495 |
// |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
496 |
// getLogger("Foo", "resourceBundleForFoo"); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
497 |
// getLogger("Foo"); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
498 |
// |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
499 |
// would throw an IllegalArgumentException in the second call |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
500 |
// because the wrapper would result in an attempt to replace |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
501 |
// the existing "resourceBundleForFoo" with null. |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16483
diff
changeset
|
502 |
return demandLogger(name, null, Reflection.getCallerClass()); |
2 | 503 |
} |
504 |
||
505 |
/** |
|
506 |
* Find or create a logger for a named subsystem. If a logger has |
|
507 |
* already been created with the given name it is returned. Otherwise |
|
508 |
* a new logger is created. |
|
509 |
* <p> |
|
510 |
* If a new logger is created its log level will be configured |
|
511 |
* based on the LogManager and it will configured to also send logging |
|
3853 | 512 |
* output to its parent's Handlers. It will be registered in |
2 | 513 |
* the LogManager global namespace. |
514 |
* <p> |
|
6675
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
515 |
* Note: The LogManager may only retain a weak reference to the newly |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
516 |
* created Logger. It is important to understand that a previously |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
517 |
* created Logger with the given name may be garbage collected at any |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
518 |
* time if there is no strong reference to the Logger. In particular, |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
519 |
* this means that two back-to-back calls like |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
520 |
* {@code getLogger("MyLogger", ...).log(...)} may use different Logger |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
521 |
* objects named "MyLogger" if there is no strong reference to the |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
522 |
* Logger named "MyLogger" elsewhere in the program. |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
523 |
* <p> |
2 | 524 |
* If the named Logger already exists and does not yet have a |
525 |
* localization resource bundle then the given resource bundle |
|
526 |
* name is used. If the named Logger already exists and has |
|
527 |
* a different resource bundle name then an IllegalArgumentException |
|
528 |
* is thrown. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
529 |
* |
2 | 530 |
* @param name A name for the logger. This should |
531 |
* be a dot-separated name and should normally |
|
532 |
* be based on the package name or class name |
|
533 |
* of the subsystem, such as java.net |
|
534 |
* or javax.swing |
|
535 |
* @param resourceBundleName name of ResourceBundle to be used for localizing |
|
19584
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
536 |
* messages for this logger. May be {@code null} |
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
537 |
* if none of the messages require localization. |
2 | 538 |
* @return a suitable Logger |
3853 | 539 |
* @throws MissingResourceException if the resourceBundleName is non-null and |
540 |
* no corresponding resource can be found. |
|
2 | 541 |
* @throws IllegalArgumentException if the Logger already exists and uses |
19584
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
542 |
* a different resource bundle name; or if |
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
543 |
* {@code resourceBundleName} is {@code null} but the named |
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
544 |
* logger has a resource bundle set. |
2 | 545 |
* @throws NullPointerException if the name is null. |
546 |
*/ |
|
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
547 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
548 |
// Synchronization is not required here. All synchronization for |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
549 |
// adding a new Logger object is handled by LogManager.addLogger(). |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16483
diff
changeset
|
550 |
@CallerSensitive |
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
551 |
public static Logger getLogger(String name, String resourceBundleName) { |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
552 |
Class<?> callerClass = Reflection.getCallerClass(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
553 |
Logger result = demandLogger(name, resourceBundleName, callerClass); |
10046
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
554 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
555 |
// MissingResourceException or IllegalArgumentException can be |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
556 |
// thrown by setupResourceInfo(). |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
557 |
// We have to set the callers ClassLoader here in case demandLogger |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
558 |
// above found a previously created Logger. This can happen, for |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
559 |
// example, if Logger.getLogger(name) is called and subsequently |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
560 |
// Logger.getLogger(name, resourceBundleName) is called. In this case |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
561 |
// we won't necessarily have the correct classloader saved away, so |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
562 |
// we need to set it here, too. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
563 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
564 |
result.setupResourceInfo(resourceBundleName, callerClass); |
2 | 565 |
return result; |
566 |
} |
|
567 |
||
16098 | 568 |
// package-private |
569 |
// Add a platform logger to the system context. |
|
570 |
// i.e. caller of sun.util.logging.PlatformLogger.getLogger |
|
571 |
static Logger getPlatformLogger(String name) { |
|
572 |
LogManager manager = LogManager.getLogManager(); |
|
573 |
||
574 |
// all loggers in the system context will default to |
|
575 |
// the system logger's resource bundle |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
576 |
Logger result = manager.demandSystemLogger(name, SYSTEM_LOGGER_RB_NAME); |
16098 | 577 |
return result; |
578 |
} |
|
2 | 579 |
|
580 |
/** |
|
581 |
* Create an anonymous Logger. The newly created Logger is not |
|
582 |
* registered in the LogManager namespace. There will be no |
|
583 |
* access checks on updates to the logger. |
|
584 |
* <p> |
|
585 |
* This factory method is primarily intended for use from applets. |
|
586 |
* Because the resulting Logger is anonymous it can be kept private |
|
587 |
* by the creating class. This removes the need for normal security |
|
588 |
* checks, which in turn allows untrusted applet code to update |
|
589 |
* the control state of the Logger. For example an applet can do |
|
590 |
* a setLevel or an addHandler on an anonymous Logger. |
|
591 |
* <p> |
|
592 |
* Even although the new logger is anonymous, it is configured |
|
593 |
* to have the root logger ("") as its parent. This means that |
|
594 |
* by default it inherits its effective level and handlers |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
595 |
* from the root logger. Changing its parent via the |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
596 |
* {@link #setParent(java.util.logging.Logger) setParent} method |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
597 |
* will still require the security permission specified by that method. |
2 | 598 |
* |
599 |
* @return a newly created private Logger |
|
600 |
*/ |
|
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
601 |
public static Logger getAnonymousLogger() { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
602 |
return getAnonymousLogger(null); |
2 | 603 |
} |
604 |
||
605 |
/** |
|
606 |
* Create an anonymous Logger. The newly created Logger is not |
|
607 |
* registered in the LogManager namespace. There will be no |
|
608 |
* access checks on updates to the logger. |
|
609 |
* <p> |
|
610 |
* This factory method is primarily intended for use from applets. |
|
611 |
* Because the resulting Logger is anonymous it can be kept private |
|
612 |
* by the creating class. This removes the need for normal security |
|
613 |
* checks, which in turn allows untrusted applet code to update |
|
614 |
* the control state of the Logger. For example an applet can do |
|
615 |
* a setLevel or an addHandler on an anonymous Logger. |
|
616 |
* <p> |
|
617 |
* Even although the new logger is anonymous, it is configured |
|
618 |
* to have the root logger ("") as its parent. This means that |
|
619 |
* by default it inherits its effective level and handlers |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
620 |
* from the root logger. Changing its parent via the |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
621 |
* {@link #setParent(java.util.logging.Logger) setParent} method |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
622 |
* will still require the security permission specified by that method. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
623 |
* |
2 | 624 |
* @param resourceBundleName name of ResourceBundle to be used for localizing |
625 |
* messages for this logger. |
|
626 |
* May be null if none of the messages require localization. |
|
627 |
* @return a newly created private Logger |
|
3853 | 628 |
* @throws MissingResourceException if the resourceBundleName is non-null and |
629 |
* no corresponding resource can be found. |
|
2 | 630 |
*/ |
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
631 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
632 |
// Synchronization is not required here. All synchronization for |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
633 |
// adding a new anonymous Logger object is handled by doSetParent(). |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
634 |
@CallerSensitive |
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
9035
diff
changeset
|
635 |
public static Logger getAnonymousLogger(String resourceBundleName) { |
2 | 636 |
LogManager manager = LogManager.getLogManager(); |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
637 |
// cleanup some Loggers that have been GC'ed |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
638 |
manager.drainLoggerRefQueueBounded(); |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
639 |
Logger result = new Logger(null, resourceBundleName, |
23899 | 640 |
Reflection.getCallerClass(), manager, false); |
2 | 641 |
result.anonymous = true; |
642 |
Logger root = manager.getLogger(""); |
|
643 |
result.doSetParent(root); |
|
644 |
return result; |
|
645 |
} |
|
646 |
||
647 |
/** |
|
648 |
* Retrieve the localization resource bundle for this |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
649 |
* logger. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
650 |
* This method will return a {@code ResourceBundle} that was either |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
651 |
* set by the {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
652 |
* #setResourceBundle(java.util.ResourceBundle) setResourceBundle} method or |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
653 |
* <a href="#ResourceBundleMapping">mapped from the |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
654 |
* the resource bundle name</a> set via the {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
655 |
* Logger#getLogger(java.lang.String, java.lang.String) getLogger} factory |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
656 |
* method for the current default locale. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
657 |
* <br>Note that if the result is {@code null}, then the Logger will use a resource |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
658 |
* bundle or resource bundle name inherited from its parent. |
2 | 659 |
* |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
660 |
* @return localization bundle (may be {@code null}) |
2 | 661 |
*/ |
662 |
public ResourceBundle getResourceBundle() { |
|
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
663 |
return findResourceBundle(getResourceBundleName(), true); |
2 | 664 |
} |
665 |
||
666 |
/** |
|
667 |
* Retrieve the localization resource bundle name for this |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
668 |
* logger. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
669 |
* This is either the name specified through the {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
670 |
* #getLogger(java.lang.String, java.lang.String) getLogger} factory method, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
671 |
* or the {@linkplain ResourceBundle#getBaseBundleName() base name} of the |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
672 |
* ResourceBundle set through {@link |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
673 |
* #setResourceBundle(java.util.ResourceBundle) setResourceBundle} method. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
674 |
* <br>Note that if the result is {@code null}, then the Logger will use a resource |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
675 |
* bundle or resource bundle name inherited from its parent. |
2 | 676 |
* |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
677 |
* @return localization bundle name (may be {@code null}) |
2 | 678 |
*/ |
679 |
public String getResourceBundleName() { |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
680 |
return loggerBundle.resourceBundleName; |
2 | 681 |
} |
682 |
||
683 |
/** |
|
684 |
* Set a filter to control output on this Logger. |
|
685 |
* <P> |
|
686 |
* After passing the initial "level" check, the Logger will |
|
687 |
* call this Filter to check if a log record should really |
|
688 |
* be published. |
|
689 |
* |
|
690 |
* @param newFilter a filter object (may be null) |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
691 |
* @throws SecurityException if a security manager exists, |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
692 |
* this logger is not anonymous, and the caller |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
693 |
* does not have LoggingPermission("control"). |
2 | 694 |
*/ |
1933 | 695 |
public void setFilter(Filter newFilter) throws SecurityException { |
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
10046
diff
changeset
|
696 |
checkPermission(); |
2 | 697 |
filter = newFilter; |
698 |
} |
|
699 |
||
700 |
/** |
|
701 |
* Get the current filter for this Logger. |
|
702 |
* |
|
703 |
* @return a filter object (may be null) |
|
704 |
*/ |
|
1933 | 705 |
public Filter getFilter() { |
2 | 706 |
return filter; |
707 |
} |
|
708 |
||
709 |
/** |
|
710 |
* Log a LogRecord. |
|
711 |
* <p> |
|
712 |
* All the other logging methods in this class call through |
|
713 |
* this method to actually perform any logging. Subclasses can |
|
714 |
* override this single method to capture all log activity. |
|
715 |
* |
|
716 |
* @param record the LogRecord to be published |
|
717 |
*/ |
|
718 |
public void log(LogRecord record) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
719 |
if (!isLoggable(record.getLevel())) { |
2 | 720 |
return; |
721 |
} |
|
1933 | 722 |
Filter theFilter = filter; |
723 |
if (theFilter != null && !theFilter.isLoggable(record)) { |
|
724 |
return; |
|
2 | 725 |
} |
726 |
||
727 |
// Post the LogRecord to all our Handlers, and then to |
|
728 |
// our parents' handlers, all the way up the tree. |
|
729 |
||
730 |
Logger logger = this; |
|
731 |
while (logger != null) { |
|
23899 | 732 |
final Handler[] loggerHandlers = isSystemLogger |
733 |
? logger.accessCheckedHandlers() |
|
734 |
: logger.getHandlers(); |
|
735 |
||
736 |
for (Handler handler : loggerHandlers) { |
|
1933 | 737 |
handler.publish(record); |
2 | 738 |
} |
739 |
||
23899 | 740 |
final boolean useParentHdls = isSystemLogger |
741 |
? logger.useParentHandlers |
|
742 |
: logger.getUseParentHandlers(); |
|
743 |
||
744 |
if (!useParentHdls) { |
|
2 | 745 |
break; |
746 |
} |
|
747 |
||
23899 | 748 |
logger = isSystemLogger ? logger.parent : logger.getParent(); |
2 | 749 |
} |
750 |
} |
|
751 |
||
752 |
// private support method for logging. |
|
753 |
// We fill in the logger name, resource bundle name, and |
|
754 |
// resource bundle and then call "void log(LogRecord)". |
|
755 |
private void doLog(LogRecord lr) { |
|
756 |
lr.setLoggerName(name); |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
757 |
final LoggerBundle lb = getEffectiveLoggerBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
758 |
final ResourceBundle bundle = lb.userBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
759 |
final String ebname = lb.resourceBundleName; |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
760 |
if (ebname != null && bundle != null) { |
2 | 761 |
lr.setResourceBundleName(ebname); |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
762 |
lr.setResourceBundle(bundle); |
2 | 763 |
} |
764 |
log(lr); |
|
765 |
} |
|
766 |
||
767 |
||
768 |
//================================================================ |
|
769 |
// Start of convenience methods WITHOUT className and methodName |
|
770 |
//================================================================ |
|
771 |
||
772 |
/** |
|
773 |
* Log a message, with no arguments. |
|
774 |
* <p> |
|
775 |
* If the logger is currently enabled for the given message |
|
776 |
* level then the given message is forwarded to all the |
|
777 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
778 |
* |
3853 | 779 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 780 |
* @param msg The string message (or a key in the message catalog) |
781 |
*/ |
|
782 |
public void log(Level level, String msg) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
783 |
if (!isLoggable(level)) { |
2 | 784 |
return; |
785 |
} |
|
786 |
LogRecord lr = new LogRecord(level, msg); |
|
787 |
doLog(lr); |
|
788 |
} |
|
789 |
||
790 |
/** |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
791 |
* Log a message, which is only to be constructed if the logging level |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
792 |
* is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
793 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
794 |
* If the logger is currently enabled for the given message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
795 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
796 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
797 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
798 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
799 |
* @param level One of the message level identifiers, e.g., SEVERE |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
800 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
801 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
802 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
803 |
public void log(Level level, Supplier<String> msgSupplier) { |
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
804 |
if (!isLoggable(level)) { |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
805 |
return; |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
806 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
807 |
LogRecord lr = new LogRecord(level, msgSupplier.get()); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
808 |
doLog(lr); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
809 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
810 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
811 |
/** |
2 | 812 |
* Log a message, with one object parameter. |
813 |
* <p> |
|
814 |
* If the logger is currently enabled for the given message |
|
815 |
* level then a corresponding LogRecord is created and forwarded |
|
816 |
* to all the registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
817 |
* |
3853 | 818 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 819 |
* @param msg The string message (or a key in the message catalog) |
820 |
* @param param1 parameter to the message |
|
821 |
*/ |
|
822 |
public void log(Level level, String msg, Object param1) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
823 |
if (!isLoggable(level)) { |
2 | 824 |
return; |
825 |
} |
|
826 |
LogRecord lr = new LogRecord(level, msg); |
|
827 |
Object params[] = { param1 }; |
|
828 |
lr.setParameters(params); |
|
829 |
doLog(lr); |
|
830 |
} |
|
831 |
||
832 |
/** |
|
833 |
* Log a message, with an array of object arguments. |
|
834 |
* <p> |
|
835 |
* If the logger is currently enabled for the given message |
|
836 |
* level then a corresponding LogRecord is created and forwarded |
|
837 |
* to all the registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
838 |
* |
3853 | 839 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 840 |
* @param msg The string message (or a key in the message catalog) |
841 |
* @param params array of parameters to the message |
|
842 |
*/ |
|
843 |
public void log(Level level, String msg, Object params[]) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
844 |
if (!isLoggable(level)) { |
2 | 845 |
return; |
846 |
} |
|
847 |
LogRecord lr = new LogRecord(level, msg); |
|
848 |
lr.setParameters(params); |
|
849 |
doLog(lr); |
|
850 |
} |
|
851 |
||
852 |
/** |
|
853 |
* Log a message, with associated Throwable information. |
|
854 |
* <p> |
|
855 |
* If the logger is currently enabled for the given message |
|
856 |
* level then the given arguments are stored in a LogRecord |
|
857 |
* which is forwarded to all registered output handlers. |
|
858 |
* <p> |
|
859 |
* Note that the thrown argument is stored in the LogRecord thrown |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
860 |
* property, rather than the LogRecord parameters property. Thus it is |
2 | 861 |
* processed specially by output Formatters and is not treated |
862 |
* as a formatting parameter to the LogRecord message property. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
863 |
* |
3853 | 864 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 865 |
* @param msg The string message (or a key in the message catalog) |
866 |
* @param thrown Throwable associated with log message. |
|
867 |
*/ |
|
868 |
public void log(Level level, String msg, Throwable thrown) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
869 |
if (!isLoggable(level)) { |
2 | 870 |
return; |
871 |
} |
|
872 |
LogRecord lr = new LogRecord(level, msg); |
|
873 |
lr.setThrown(thrown); |
|
874 |
doLog(lr); |
|
875 |
} |
|
876 |
||
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
877 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
878 |
* Log a lazily constructed message, with associated Throwable information. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
879 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
880 |
* If the logger is currently enabled for the given message level then the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
881 |
* message is constructed by invoking the provided supplier function. The |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
882 |
* message and the given {@link Throwable} are then stored in a {@link |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
883 |
* LogRecord} which is forwarded to all registered output handlers. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
884 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
885 |
* Note that the thrown argument is stored in the LogRecord thrown |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
886 |
* property, rather than the LogRecord parameters property. Thus it is |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
887 |
* processed specially by output Formatters and is not treated |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
888 |
* as a formatting parameter to the LogRecord message property. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
889 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
890 |
* @param level One of the message level identifiers, e.g., SEVERE |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
891 |
* @param thrown Throwable associated with log message. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
892 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
893 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
894 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
895 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
896 |
public void log(Level level, Throwable thrown, Supplier<String> msgSupplier) { |
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
897 |
if (!isLoggable(level)) { |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
898 |
return; |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
899 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
900 |
LogRecord lr = new LogRecord(level, msgSupplier.get()); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
901 |
lr.setThrown(thrown); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
902 |
doLog(lr); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
903 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
904 |
|
2 | 905 |
//================================================================ |
906 |
// Start of convenience methods WITH className and methodName |
|
907 |
//================================================================ |
|
908 |
||
909 |
/** |
|
910 |
* Log a message, specifying source class and method, |
|
911 |
* with no arguments. |
|
912 |
* <p> |
|
913 |
* If the logger is currently enabled for the given message |
|
914 |
* level then the given message is forwarded to all the |
|
915 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
916 |
* |
3853 | 917 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 918 |
* @param sourceClass name of class that issued the logging request |
919 |
* @param sourceMethod name of method that issued the logging request |
|
920 |
* @param msg The string message (or a key in the message catalog) |
|
921 |
*/ |
|
922 |
public void logp(Level level, String sourceClass, String sourceMethod, String msg) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
923 |
if (!isLoggable(level)) { |
2 | 924 |
return; |
925 |
} |
|
926 |
LogRecord lr = new LogRecord(level, msg); |
|
927 |
lr.setSourceClassName(sourceClass); |
|
928 |
lr.setSourceMethodName(sourceMethod); |
|
929 |
doLog(lr); |
|
930 |
} |
|
931 |
||
932 |
/** |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
933 |
* Log a lazily constructed message, specifying source class and method, |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
934 |
* with no arguments. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
935 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
936 |
* If the logger is currently enabled for the given message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
937 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
938 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
939 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
940 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
941 |
* @param level One of the message level identifiers, e.g., SEVERE |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
942 |
* @param sourceClass name of class that issued the logging request |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
943 |
* @param sourceMethod name of method that issued the logging request |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
944 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
945 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
946 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
947 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
948 |
public void logp(Level level, String sourceClass, String sourceMethod, |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
949 |
Supplier<String> msgSupplier) { |
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
950 |
if (!isLoggable(level)) { |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
951 |
return; |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
952 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
953 |
LogRecord lr = new LogRecord(level, msgSupplier.get()); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
954 |
lr.setSourceClassName(sourceClass); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
955 |
lr.setSourceMethodName(sourceMethod); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
956 |
doLog(lr); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
957 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
958 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
959 |
/** |
2 | 960 |
* Log a message, specifying source class and method, |
961 |
* with a single object parameter to the log message. |
|
962 |
* <p> |
|
963 |
* If the logger is currently enabled for the given message |
|
964 |
* level then a corresponding LogRecord is created and forwarded |
|
965 |
* to all the registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
966 |
* |
3853 | 967 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 968 |
* @param sourceClass name of class that issued the logging request |
969 |
* @param sourceMethod name of method that issued the logging request |
|
970 |
* @param msg The string message (or a key in the message catalog) |
|
971 |
* @param param1 Parameter to the log message. |
|
972 |
*/ |
|
973 |
public void logp(Level level, String sourceClass, String sourceMethod, |
|
974 |
String msg, Object param1) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
975 |
if (!isLoggable(level)) { |
2 | 976 |
return; |
977 |
} |
|
978 |
LogRecord lr = new LogRecord(level, msg); |
|
979 |
lr.setSourceClassName(sourceClass); |
|
980 |
lr.setSourceMethodName(sourceMethod); |
|
981 |
Object params[] = { param1 }; |
|
982 |
lr.setParameters(params); |
|
983 |
doLog(lr); |
|
984 |
} |
|
985 |
||
986 |
/** |
|
987 |
* Log a message, specifying source class and method, |
|
988 |
* with an array of object arguments. |
|
989 |
* <p> |
|
990 |
* If the logger is currently enabled for the given message |
|
991 |
* level then a corresponding LogRecord is created and forwarded |
|
992 |
* to all the registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
993 |
* |
3853 | 994 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 995 |
* @param sourceClass name of class that issued the logging request |
996 |
* @param sourceMethod name of method that issued the logging request |
|
997 |
* @param msg The string message (or a key in the message catalog) |
|
998 |
* @param params Array of parameters to the message |
|
999 |
*/ |
|
1000 |
public void logp(Level level, String sourceClass, String sourceMethod, |
|
1001 |
String msg, Object params[]) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1002 |
if (!isLoggable(level)) { |
2 | 1003 |
return; |
1004 |
} |
|
1005 |
LogRecord lr = new LogRecord(level, msg); |
|
1006 |
lr.setSourceClassName(sourceClass); |
|
1007 |
lr.setSourceMethodName(sourceMethod); |
|
1008 |
lr.setParameters(params); |
|
1009 |
doLog(lr); |
|
1010 |
} |
|
1011 |
||
1012 |
/** |
|
1013 |
* Log a message, specifying source class and method, |
|
1014 |
* with associated Throwable information. |
|
1015 |
* <p> |
|
1016 |
* If the logger is currently enabled for the given message |
|
1017 |
* level then the given arguments are stored in a LogRecord |
|
1018 |
* which is forwarded to all registered output handlers. |
|
1019 |
* <p> |
|
1020 |
* Note that the thrown argument is stored in the LogRecord thrown |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1021 |
* property, rather than the LogRecord parameters property. Thus it is |
2 | 1022 |
* processed specially by output Formatters and is not treated |
1023 |
* as a formatting parameter to the LogRecord message property. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1024 |
* |
3853 | 1025 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 1026 |
* @param sourceClass name of class that issued the logging request |
1027 |
* @param sourceMethod name of method that issued the logging request |
|
1028 |
* @param msg The string message (or a key in the message catalog) |
|
1029 |
* @param thrown Throwable associated with log message. |
|
1030 |
*/ |
|
1031 |
public void logp(Level level, String sourceClass, String sourceMethod, |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1032 |
String msg, Throwable thrown) { |
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1033 |
if (!isLoggable(level)) { |
2 | 1034 |
return; |
1035 |
} |
|
1036 |
LogRecord lr = new LogRecord(level, msg); |
|
1037 |
lr.setSourceClassName(sourceClass); |
|
1038 |
lr.setSourceMethodName(sourceMethod); |
|
1039 |
lr.setThrown(thrown); |
|
1040 |
doLog(lr); |
|
1041 |
} |
|
1042 |
||
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1043 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1044 |
* Log a lazily constructed message, specifying source class and method, |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1045 |
* with associated Throwable information. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1046 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1047 |
* If the logger is currently enabled for the given message level then the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1048 |
* message is constructed by invoking the provided supplier function. The |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1049 |
* message and the given {@link Throwable} are then stored in a {@link |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1050 |
* LogRecord} which is forwarded to all registered output handlers. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1051 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1052 |
* Note that the thrown argument is stored in the LogRecord thrown |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1053 |
* property, rather than the LogRecord parameters property. Thus it is |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1054 |
* processed specially by output Formatters and is not treated |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1055 |
* as a formatting parameter to the LogRecord message property. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1056 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1057 |
* @param level One of the message level identifiers, e.g., SEVERE |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1058 |
* @param sourceClass name of class that issued the logging request |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1059 |
* @param sourceMethod name of method that issued the logging request |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1060 |
* @param thrown Throwable associated with log message. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1061 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1062 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1063 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1064 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1065 |
public void logp(Level level, String sourceClass, String sourceMethod, |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1066 |
Throwable thrown, Supplier<String> msgSupplier) { |
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1067 |
if (!isLoggable(level)) { |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1068 |
return; |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1069 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1070 |
LogRecord lr = new LogRecord(level, msgSupplier.get()); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1071 |
lr.setSourceClassName(sourceClass); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1072 |
lr.setSourceMethodName(sourceMethod); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1073 |
lr.setThrown(thrown); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1074 |
doLog(lr); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1075 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1076 |
|
2 | 1077 |
|
1078 |
//========================================================================= |
|
1079 |
// Start of convenience methods WITH className, methodName and bundle name. |
|
1080 |
//========================================================================= |
|
1081 |
||
1082 |
// Private support method for logging for "logrb" methods. |
|
1083 |
// We fill in the logger name, resource bundle name, and |
|
1084 |
// resource bundle and then call "void log(LogRecord)". |
|
1085 |
private void doLog(LogRecord lr, String rbname) { |
|
1086 |
lr.setLoggerName(name); |
|
1087 |
if (rbname != null) { |
|
1088 |
lr.setResourceBundleName(rbname); |
|
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1089 |
lr.setResourceBundle(findResourceBundle(rbname, false)); |
2 | 1090 |
} |
1091 |
log(lr); |
|
1092 |
} |
|
1093 |
||
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1094 |
// Private support method for logging for "logrb" methods. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1095 |
private void doLog(LogRecord lr, ResourceBundle rb) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1096 |
lr.setLoggerName(name); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1097 |
if (rb != null) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1098 |
lr.setResourceBundleName(rb.getBaseBundleName()); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1099 |
lr.setResourceBundle(rb); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1100 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1101 |
log(lr); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1102 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1103 |
|
2 | 1104 |
/** |
1105 |
* Log a message, specifying source class, method, and resource bundle name |
|
1106 |
* with no arguments. |
|
1107 |
* <p> |
|
1108 |
* If the logger is currently enabled for the given message |
|
1109 |
* level then the given message is forwarded to all the |
|
1110 |
* registered output Handler objects. |
|
1111 |
* <p> |
|
1112 |
* The msg string is localized using the named resource bundle. If the |
|
1113 |
* resource bundle name is null, or an empty String or invalid |
|
1114 |
* then the msg string is not localized. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1115 |
* |
3853 | 1116 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 1117 |
* @param sourceClass name of class that issued the logging request |
1118 |
* @param sourceMethod name of method that issued the logging request |
|
1119 |
* @param bundleName name of resource bundle to localize msg, |
|
1120 |
* can be null |
|
1121 |
* @param msg The string message (or a key in the message catalog) |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1122 |
* @deprecated Use {@link #logrb(java.util.logging.Level, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1123 |
* java.lang.String, java.util.ResourceBundle, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1124 |
* java.lang.Object...)} instead. |
2 | 1125 |
*/ |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1126 |
@Deprecated |
2 | 1127 |
public void logrb(Level level, String sourceClass, String sourceMethod, |
1128 |
String bundleName, String msg) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1129 |
if (!isLoggable(level)) { |
2 | 1130 |
return; |
1131 |
} |
|
1132 |
LogRecord lr = new LogRecord(level, msg); |
|
1133 |
lr.setSourceClassName(sourceClass); |
|
1134 |
lr.setSourceMethodName(sourceMethod); |
|
1135 |
doLog(lr, bundleName); |
|
1136 |
} |
|
1137 |
||
1138 |
/** |
|
1139 |
* Log a message, specifying source class, method, and resource bundle name, |
|
1140 |
* with a single object parameter to the log message. |
|
1141 |
* <p> |
|
1142 |
* If the logger is currently enabled for the given message |
|
1143 |
* level then a corresponding LogRecord is created and forwarded |
|
1144 |
* to all the registered output Handler objects. |
|
1145 |
* <p> |
|
1146 |
* The msg string is localized using the named resource bundle. If the |
|
1147 |
* resource bundle name is null, or an empty String or invalid |
|
1148 |
* then the msg string is not localized. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1149 |
* |
3853 | 1150 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 1151 |
* @param sourceClass name of class that issued the logging request |
1152 |
* @param sourceMethod name of method that issued the logging request |
|
1153 |
* @param bundleName name of resource bundle to localize msg, |
|
1154 |
* can be null |
|
1155 |
* @param msg The string message (or a key in the message catalog) |
|
1156 |
* @param param1 Parameter to the log message. |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1157 |
* @deprecated Use {@link #logrb(java.util.logging.Level, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1158 |
* java.lang.String, java.util.ResourceBundle, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1159 |
* java.lang.Object...)} instead |
2 | 1160 |
*/ |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1161 |
@Deprecated |
2 | 1162 |
public void logrb(Level level, String sourceClass, String sourceMethod, |
1163 |
String bundleName, String msg, Object param1) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1164 |
if (!isLoggable(level)) { |
2 | 1165 |
return; |
1166 |
} |
|
1167 |
LogRecord lr = new LogRecord(level, msg); |
|
1168 |
lr.setSourceClassName(sourceClass); |
|
1169 |
lr.setSourceMethodName(sourceMethod); |
|
1170 |
Object params[] = { param1 }; |
|
1171 |
lr.setParameters(params); |
|
1172 |
doLog(lr, bundleName); |
|
1173 |
} |
|
1174 |
||
1175 |
/** |
|
1176 |
* Log a message, specifying source class, method, and resource bundle name, |
|
1177 |
* with an array of object arguments. |
|
1178 |
* <p> |
|
1179 |
* If the logger is currently enabled for the given message |
|
1180 |
* level then a corresponding LogRecord is created and forwarded |
|
1181 |
* to all the registered output Handler objects. |
|
1182 |
* <p> |
|
1183 |
* The msg string is localized using the named resource bundle. If the |
|
1184 |
* resource bundle name is null, or an empty String or invalid |
|
1185 |
* then the msg string is not localized. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1186 |
* |
3853 | 1187 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 1188 |
* @param sourceClass name of class that issued the logging request |
1189 |
* @param sourceMethod name of method that issued the logging request |
|
1190 |
* @param bundleName name of resource bundle to localize msg, |
|
1191 |
* can be null. |
|
1192 |
* @param msg The string message (or a key in the message catalog) |
|
1193 |
* @param params Array of parameters to the message |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1194 |
* @deprecated Use {@link #logrb(java.util.logging.Level, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1195 |
* java.lang.String, java.util.ResourceBundle, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1196 |
* java.lang.Object...)} instead. |
2 | 1197 |
*/ |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1198 |
@Deprecated |
2 | 1199 |
public void logrb(Level level, String sourceClass, String sourceMethod, |
1200 |
String bundleName, String msg, Object params[]) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1201 |
if (!isLoggable(level)) { |
2 | 1202 |
return; |
1203 |
} |
|
1204 |
LogRecord lr = new LogRecord(level, msg); |
|
1205 |
lr.setSourceClassName(sourceClass); |
|
1206 |
lr.setSourceMethodName(sourceMethod); |
|
1207 |
lr.setParameters(params); |
|
1208 |
doLog(lr, bundleName); |
|
1209 |
} |
|
1210 |
||
1211 |
/** |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1212 |
* Log a message, specifying source class, method, and resource bundle, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1213 |
* with an optional list of message parameters. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1214 |
* <p> |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1215 |
* If the logger is currently enabled for the given message |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1216 |
* level then a corresponding LogRecord is created and forwarded |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1217 |
* to all the registered output Handler objects. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1218 |
* <p> |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1219 |
* The {@code msg} string is localized using the given resource bundle. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1220 |
* If the resource bundle is {@code null}, then the {@code msg} string is not |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1221 |
* localized. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1222 |
* |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1223 |
* @param level One of the message level identifiers, e.g., SEVERE |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1224 |
* @param sourceClass Name of the class that issued the logging request |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1225 |
* @param sourceMethod Name of the method that issued the logging request |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1226 |
* @param bundle Resource bundle to localize {@code msg}, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1227 |
* can be {@code null}. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1228 |
* @param msg The string message (or a key in the message catalog) |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1229 |
* @param params Parameters to the message (optional, may be none). |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1230 |
* @since 1.8 |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1231 |
*/ |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1232 |
public void logrb(Level level, String sourceClass, String sourceMethod, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1233 |
ResourceBundle bundle, String msg, Object... params) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1234 |
if (!isLoggable(level)) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1235 |
return; |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1236 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1237 |
LogRecord lr = new LogRecord(level, msg); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1238 |
lr.setSourceClassName(sourceClass); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1239 |
lr.setSourceMethodName(sourceMethod); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1240 |
if (params != null && params.length != 0) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1241 |
lr.setParameters(params); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1242 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1243 |
doLog(lr, bundle); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1244 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1245 |
|
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1246 |
/** |
2 | 1247 |
* Log a message, specifying source class, method, and resource bundle name, |
1248 |
* with associated Throwable information. |
|
1249 |
* <p> |
|
1250 |
* If the logger is currently enabled for the given message |
|
1251 |
* level then the given arguments are stored in a LogRecord |
|
1252 |
* which is forwarded to all registered output handlers. |
|
1253 |
* <p> |
|
1254 |
* The msg string is localized using the named resource bundle. If the |
|
1255 |
* resource bundle name is null, or an empty String or invalid |
|
1256 |
* then the msg string is not localized. |
|
1257 |
* <p> |
|
1258 |
* Note that the thrown argument is stored in the LogRecord thrown |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1259 |
* property, rather than the LogRecord parameters property. Thus it is |
2 | 1260 |
* processed specially by output Formatters and is not treated |
1261 |
* as a formatting parameter to the LogRecord message property. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1262 |
* |
3853 | 1263 |
* @param level One of the message level identifiers, e.g., SEVERE |
2 | 1264 |
* @param sourceClass name of class that issued the logging request |
1265 |
* @param sourceMethod name of method that issued the logging request |
|
1266 |
* @param bundleName name of resource bundle to localize msg, |
|
1267 |
* can be null |
|
1268 |
* @param msg The string message (or a key in the message catalog) |
|
1269 |
* @param thrown Throwable associated with log message. |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1270 |
* @deprecated Use {@link #logrb(java.util.logging.Level, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1271 |
* java.lang.String, java.util.ResourceBundle, java.lang.String, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1272 |
* java.lang.Throwable)} instead. |
2 | 1273 |
*/ |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1274 |
@Deprecated |
2 | 1275 |
public void logrb(Level level, String sourceClass, String sourceMethod, |
1276 |
String bundleName, String msg, Throwable thrown) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1277 |
if (!isLoggable(level)) { |
2 | 1278 |
return; |
1279 |
} |
|
1280 |
LogRecord lr = new LogRecord(level, msg); |
|
1281 |
lr.setSourceClassName(sourceClass); |
|
1282 |
lr.setSourceMethodName(sourceMethod); |
|
1283 |
lr.setThrown(thrown); |
|
1284 |
doLog(lr, bundleName); |
|
1285 |
} |
|
1286 |
||
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1287 |
/** |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1288 |
* Log a message, specifying source class, method, and resource bundle, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1289 |
* with associated Throwable information. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1290 |
* <p> |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1291 |
* If the logger is currently enabled for the given message |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1292 |
* level then the given arguments are stored in a LogRecord |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1293 |
* which is forwarded to all registered output handlers. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1294 |
* <p> |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1295 |
* The {@code msg} string is localized using the given resource bundle. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1296 |
* If the resource bundle is {@code null}, then the {@code msg} string is not |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1297 |
* localized. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1298 |
* <p> |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1299 |
* Note that the thrown argument is stored in the LogRecord thrown |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1300 |
* property, rather than the LogRecord parameters property. Thus it is |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1301 |
* processed specially by output Formatters and is not treated |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1302 |
* as a formatting parameter to the LogRecord message property. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1303 |
* |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1304 |
* @param level One of the message level identifiers, e.g., SEVERE |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1305 |
* @param sourceClass Name of the class that issued the logging request |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1306 |
* @param sourceMethod Name of the method that issued the logging request |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1307 |
* @param bundle Resource bundle to localize {@code msg}, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1308 |
* can be {@code null} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1309 |
* @param msg The string message (or a key in the message catalog) |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1310 |
* @param thrown Throwable associated with the log message. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1311 |
* @since 1.8 |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1312 |
*/ |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1313 |
public void logrb(Level level, String sourceClass, String sourceMethod, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1314 |
ResourceBundle bundle, String msg, Throwable thrown) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1315 |
if (!isLoggable(level)) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1316 |
return; |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1317 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1318 |
LogRecord lr = new LogRecord(level, msg); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1319 |
lr.setSourceClassName(sourceClass); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1320 |
lr.setSourceMethodName(sourceMethod); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1321 |
lr.setThrown(thrown); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1322 |
doLog(lr, bundle); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1323 |
} |
2 | 1324 |
|
1325 |
//====================================================================== |
|
1326 |
// Start of convenience methods for logging method entries and returns. |
|
1327 |
//====================================================================== |
|
1328 |
||
1329 |
/** |
|
1330 |
* Log a method entry. |
|
1331 |
* <p> |
|
1332 |
* This is a convenience method that can be used to log entry |
|
1333 |
* to a method. A LogRecord with message "ENTRY", log level |
|
1334 |
* FINER, and the given sourceMethod and sourceClass is logged. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1335 |
* |
2 | 1336 |
* @param sourceClass name of class that issued the logging request |
1337 |
* @param sourceMethod name of method that is being entered |
|
1338 |
*/ |
|
1339 |
public void entering(String sourceClass, String sourceMethod) { |
|
1340 |
logp(Level.FINER, sourceClass, sourceMethod, "ENTRY"); |
|
1341 |
} |
|
1342 |
||
1343 |
/** |
|
1344 |
* Log a method entry, with one parameter. |
|
1345 |
* <p> |
|
1346 |
* This is a convenience method that can be used to log entry |
|
1347 |
* to a method. A LogRecord with message "ENTRY {0}", log level |
|
1348 |
* FINER, and the given sourceMethod, sourceClass, and parameter |
|
1349 |
* is logged. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1350 |
* |
2 | 1351 |
* @param sourceClass name of class that issued the logging request |
1352 |
* @param sourceMethod name of method that is being entered |
|
1353 |
* @param param1 parameter to the method being entered |
|
1354 |
*/ |
|
1355 |
public void entering(String sourceClass, String sourceMethod, Object param1) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1356 |
logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", param1); |
2 | 1357 |
} |
1358 |
||
1359 |
/** |
|
1360 |
* Log a method entry, with an array of parameters. |
|
1361 |
* <p> |
|
1362 |
* This is a convenience method that can be used to log entry |
|
1363 |
* to a method. A LogRecord with message "ENTRY" (followed by a |
|
1364 |
* format {N} indicator for each entry in the parameter array), |
|
1365 |
* log level FINER, and the given sourceMethod, sourceClass, and |
|
1366 |
* parameters is logged. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1367 |
* |
2 | 1368 |
* @param sourceClass name of class that issued the logging request |
1369 |
* @param sourceMethod name of method that is being entered |
|
1370 |
* @param params array of parameters to the method being entered |
|
1371 |
*/ |
|
1372 |
public void entering(String sourceClass, String sourceMethod, Object params[]) { |
|
1373 |
String msg = "ENTRY"; |
|
1374 |
if (params == null ) { |
|
1375 |
logp(Level.FINER, sourceClass, sourceMethod, msg); |
|
1376 |
return; |
|
1377 |
} |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1378 |
if (!isLoggable(Level.FINER)) return; |
26961
8203ecb092af
8028788: Logger.enterring uses String concatenation in a loop
dfuchs
parents:
25859
diff
changeset
|
1379 |
if (params.length > 0) { |
8203ecb092af
8028788: Logger.enterring uses String concatenation in a loop
dfuchs
parents:
25859
diff
changeset
|
1380 |
final StringBuilder b = new StringBuilder(msg); |
8203ecb092af
8028788: Logger.enterring uses String concatenation in a loop
dfuchs
parents:
25859
diff
changeset
|
1381 |
for (int i = 0; i < params.length; i++) { |
8203ecb092af
8028788: Logger.enterring uses String concatenation in a loop
dfuchs
parents:
25859
diff
changeset
|
1382 |
b.append(' ').append('{').append(i).append('}'); |
8203ecb092af
8028788: Logger.enterring uses String concatenation in a loop
dfuchs
parents:
25859
diff
changeset
|
1383 |
} |
8203ecb092af
8028788: Logger.enterring uses String concatenation in a loop
dfuchs
parents:
25859
diff
changeset
|
1384 |
msg = b.toString(); |
2 | 1385 |
} |
1386 |
logp(Level.FINER, sourceClass, sourceMethod, msg, params); |
|
1387 |
} |
|
1388 |
||
1389 |
/** |
|
1390 |
* Log a method return. |
|
1391 |
* <p> |
|
1392 |
* This is a convenience method that can be used to log returning |
|
1393 |
* from a method. A LogRecord with message "RETURN", log level |
|
1394 |
* FINER, and the given sourceMethod and sourceClass is logged. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1395 |
* |
2 | 1396 |
* @param sourceClass name of class that issued the logging request |
1397 |
* @param sourceMethod name of the method |
|
1398 |
*/ |
|
1399 |
public void exiting(String sourceClass, String sourceMethod) { |
|
1400 |
logp(Level.FINER, sourceClass, sourceMethod, "RETURN"); |
|
1401 |
} |
|
1402 |
||
1403 |
||
1404 |
/** |
|
1405 |
* Log a method return, with result object. |
|
1406 |
* <p> |
|
1407 |
* This is a convenience method that can be used to log returning |
|
1408 |
* from a method. A LogRecord with message "RETURN {0}", log level |
|
1409 |
* FINER, and the gives sourceMethod, sourceClass, and result |
|
1410 |
* object is logged. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1411 |
* |
2 | 1412 |
* @param sourceClass name of class that issued the logging request |
1413 |
* @param sourceMethod name of the method |
|
1414 |
* @param result Object that is being returned |
|
1415 |
*/ |
|
1416 |
public void exiting(String sourceClass, String sourceMethod, Object result) { |
|
1417 |
logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result); |
|
1418 |
} |
|
1419 |
||
1420 |
/** |
|
1421 |
* Log throwing an exception. |
|
1422 |
* <p> |
|
1423 |
* This is a convenience method to log that a method is |
|
1424 |
* terminating by throwing an exception. The logging is done |
|
1425 |
* using the FINER level. |
|
1426 |
* <p> |
|
1427 |
* If the logger is currently enabled for the given message |
|
1428 |
* level then the given arguments are stored in a LogRecord |
|
1429 |
* which is forwarded to all registered output handlers. The |
|
1430 |
* LogRecord's message is set to "THROW". |
|
1431 |
* <p> |
|
1432 |
* Note that the thrown argument is stored in the LogRecord thrown |
|
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1433 |
* property, rather than the LogRecord parameters property. Thus it is |
2 | 1434 |
* processed specially by output Formatters and is not treated |
1435 |
* as a formatting parameter to the LogRecord message property. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1436 |
* |
2 | 1437 |
* @param sourceClass name of class that issued the logging request |
1438 |
* @param sourceMethod name of the method. |
|
1439 |
* @param thrown The Throwable that is being thrown. |
|
1440 |
*/ |
|
1441 |
public void throwing(String sourceClass, String sourceMethod, Throwable thrown) { |
|
19847
e481217d82f2
8024525: Make Logger log methods call isLoggable()
dfuchs
parents:
19825
diff
changeset
|
1442 |
if (!isLoggable(Level.FINER)) { |
2 | 1443 |
return; |
1444 |
} |
|
1445 |
LogRecord lr = new LogRecord(Level.FINER, "THROW"); |
|
1446 |
lr.setSourceClassName(sourceClass); |
|
1447 |
lr.setSourceMethodName(sourceMethod); |
|
1448 |
lr.setThrown(thrown); |
|
1449 |
doLog(lr); |
|
1450 |
} |
|
1451 |
||
1452 |
//======================================================================= |
|
1453 |
// Start of simple convenience methods using level names as method names |
|
1454 |
//======================================================================= |
|
1455 |
||
1456 |
/** |
|
1457 |
* Log a SEVERE message. |
|
1458 |
* <p> |
|
1459 |
* If the logger is currently enabled for the SEVERE message |
|
1460 |
* level then the given message is forwarded to all the |
|
1461 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1462 |
* |
2 | 1463 |
* @param msg The string message (or a key in the message catalog) |
1464 |
*/ |
|
1465 |
public void severe(String msg) { |
|
1466 |
log(Level.SEVERE, msg); |
|
1467 |
} |
|
1468 |
||
1469 |
/** |
|
1470 |
* Log a WARNING message. |
|
1471 |
* <p> |
|
1472 |
* If the logger is currently enabled for the WARNING message |
|
1473 |
* level then the given message is forwarded to all the |
|
1474 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1475 |
* |
2 | 1476 |
* @param msg The string message (or a key in the message catalog) |
1477 |
*/ |
|
1478 |
public void warning(String msg) { |
|
1479 |
log(Level.WARNING, msg); |
|
1480 |
} |
|
1481 |
||
1482 |
/** |
|
1483 |
* Log an INFO message. |
|
1484 |
* <p> |
|
1485 |
* If the logger is currently enabled for the INFO message |
|
1486 |
* level then the given message is forwarded to all the |
|
1487 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1488 |
* |
2 | 1489 |
* @param msg The string message (or a key in the message catalog) |
1490 |
*/ |
|
1491 |
public void info(String msg) { |
|
1492 |
log(Level.INFO, msg); |
|
1493 |
} |
|
1494 |
||
1495 |
/** |
|
1496 |
* Log a CONFIG message. |
|
1497 |
* <p> |
|
1498 |
* If the logger is currently enabled for the CONFIG message |
|
1499 |
* level then the given message is forwarded to all the |
|
1500 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1501 |
* |
2 | 1502 |
* @param msg The string message (or a key in the message catalog) |
1503 |
*/ |
|
1504 |
public void config(String msg) { |
|
1505 |
log(Level.CONFIG, msg); |
|
1506 |
} |
|
1507 |
||
1508 |
/** |
|
1509 |
* Log a FINE message. |
|
1510 |
* <p> |
|
1511 |
* If the logger is currently enabled for the FINE message |
|
1512 |
* level then the given message is forwarded to all the |
|
1513 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1514 |
* |
2 | 1515 |
* @param msg The string message (or a key in the message catalog) |
1516 |
*/ |
|
1517 |
public void fine(String msg) { |
|
1518 |
log(Level.FINE, msg); |
|
1519 |
} |
|
1520 |
||
1521 |
/** |
|
1522 |
* Log a FINER message. |
|
1523 |
* <p> |
|
1524 |
* If the logger is currently enabled for the FINER message |
|
1525 |
* level then the given message is forwarded to all the |
|
1526 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1527 |
* |
2 | 1528 |
* @param msg The string message (or a key in the message catalog) |
1529 |
*/ |
|
1530 |
public void finer(String msg) { |
|
1531 |
log(Level.FINER, msg); |
|
1532 |
} |
|
1533 |
||
1534 |
/** |
|
1535 |
* Log a FINEST message. |
|
1536 |
* <p> |
|
1537 |
* If the logger is currently enabled for the FINEST message |
|
1538 |
* level then the given message is forwarded to all the |
|
1539 |
* registered output Handler objects. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1540 |
* |
2 | 1541 |
* @param msg The string message (or a key in the message catalog) |
1542 |
*/ |
|
1543 |
public void finest(String msg) { |
|
1544 |
log(Level.FINEST, msg); |
|
1545 |
} |
|
1546 |
||
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1547 |
//======================================================================= |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1548 |
// Start of simple convenience methods using level names as method names |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1549 |
// and use Supplier<String> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1550 |
//======================================================================= |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1551 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1552 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1553 |
* Log a SEVERE message, which is only to be constructed if the logging |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1554 |
* level is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1555 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1556 |
* If the logger is currently enabled for the SEVERE message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1557 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1558 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1559 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1560 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1561 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1562 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1563 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1564 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1565 |
public void severe(Supplier<String> msgSupplier) { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1566 |
log(Level.SEVERE, msgSupplier); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1567 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1568 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1569 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1570 |
* Log a WARNING message, which is only to be constructed if the logging |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1571 |
* level is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1572 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1573 |
* If the logger is currently enabled for the WARNING message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1574 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1575 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1576 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1577 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1578 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1579 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1580 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1581 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1582 |
public void warning(Supplier<String> msgSupplier) { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1583 |
log(Level.WARNING, msgSupplier); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1584 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1585 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1586 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1587 |
* Log a INFO message, which is only to be constructed if the logging |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1588 |
* level is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1589 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1590 |
* If the logger is currently enabled for the INFO message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1591 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1592 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1593 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1594 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1595 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1596 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1597 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1598 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1599 |
public void info(Supplier<String> msgSupplier) { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1600 |
log(Level.INFO, msgSupplier); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1601 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1602 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1603 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1604 |
* Log a CONFIG message, which is only to be constructed if the logging |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1605 |
* level is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1606 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1607 |
* If the logger is currently enabled for the CONFIG message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1608 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1609 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1610 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1611 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1612 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1613 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1614 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1615 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1616 |
public void config(Supplier<String> msgSupplier) { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1617 |
log(Level.CONFIG, msgSupplier); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1618 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1619 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1620 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1621 |
* Log a FINE message, which is only to be constructed if the logging |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1622 |
* level is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1623 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1624 |
* If the logger is currently enabled for the FINE message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1625 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1626 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1627 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1628 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1629 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1630 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1631 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1632 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1633 |
public void fine(Supplier<String> msgSupplier) { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1634 |
log(Level.FINE, msgSupplier); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1635 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1636 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1637 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1638 |
* Log a FINER message, which is only to be constructed if the logging |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1639 |
* level is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1640 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1641 |
* If the logger is currently enabled for the FINER message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1642 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1643 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1644 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1645 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1646 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1647 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1648 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1649 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1650 |
public void finer(Supplier<String> msgSupplier) { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1651 |
log(Level.FINER, msgSupplier); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1652 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1653 |
|
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1654 |
/** |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1655 |
* Log a FINEST message, which is only to be constructed if the logging |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1656 |
* level is such that the message will actually be logged. |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1657 |
* <p> |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1658 |
* If the logger is currently enabled for the FINEST message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1659 |
* level then the message is constructed by invoking the provided |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1660 |
* supplier function and forwarded to all the registered output |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1661 |
* Handler objects. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1662 |
* |
15310
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1663 |
* @param msgSupplier A function, which when called, produces the |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1664 |
* desired log message |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1665 |
* @since 1.8 |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1666 |
*/ |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1667 |
public void finest(Supplier<String> msgSupplier) { |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1668 |
log(Level.FINEST, msgSupplier); |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1669 |
} |
77bdd8c8467e
8005632: Extend java.util.Logger to use Supplier<String> for messages
mduigou
parents:
14342
diff
changeset
|
1670 |
|
2 | 1671 |
//================================================================ |
1672 |
// End of convenience methods |
|
1673 |
//================================================================ |
|
1674 |
||
1675 |
/** |
|
1676 |
* Set the log level specifying which message levels will be |
|
1677 |
* logged by this logger. Message levels lower than this |
|
1678 |
* value will be discarded. The level value Level.OFF |
|
1679 |
* can be used to turn off logging. |
|
1680 |
* <p> |
|
1681 |
* If the new level is null, it means that this node should |
|
1682 |
* inherit its level from its nearest ancestor with a specific |
|
1683 |
* (non-null) level value. |
|
1684 |
* |
|
1685 |
* @param newLevel the new value for the log level (may be null) |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1686 |
* @throws SecurityException if a security manager exists, |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1687 |
* this logger is not anonymous, and the caller |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1688 |
* does not have LoggingPermission("control"). |
2 | 1689 |
*/ |
1690 |
public void setLevel(Level newLevel) throws SecurityException { |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
10046
diff
changeset
|
1691 |
checkPermission(); |
2 | 1692 |
synchronized (treeLock) { |
1693 |
levelObject = newLevel; |
|
1694 |
updateEffectiveLevel(); |
|
1695 |
} |
|
1696 |
} |
|
1697 |
||
21304
7971ecf0fbed
8026499: Root Logger level can be reset unexpectedly
dfuchs
parents:
20865
diff
changeset
|
1698 |
final boolean isLevelInitialized() { |
7971ecf0fbed
8026499: Root Logger level can be reset unexpectedly
dfuchs
parents:
20865
diff
changeset
|
1699 |
return levelObject != null; |
7971ecf0fbed
8026499: Root Logger level can be reset unexpectedly
dfuchs
parents:
20865
diff
changeset
|
1700 |
} |
7971ecf0fbed
8026499: Root Logger level can be reset unexpectedly
dfuchs
parents:
20865
diff
changeset
|
1701 |
|
2 | 1702 |
/** |
1703 |
* Get the log Level that has been specified for this Logger. |
|
1704 |
* The result may be null, which means that this logger's |
|
1705 |
* effective level will be inherited from its parent. |
|
1706 |
* |
|
1707 |
* @return this Logger's level |
|
1708 |
*/ |
|
1709 |
public Level getLevel() { |
|
1710 |
return levelObject; |
|
1711 |
} |
|
1712 |
||
1713 |
/** |
|
1714 |
* Check if a message of the given level would actually be logged |
|
1715 |
* by this logger. This check is based on the Loggers effective level, |
|
1716 |
* which may be inherited from its parent. |
|
1717 |
* |
|
1718 |
* @param level a message logging level |
|
1719 |
* @return true if the given message level is currently being logged. |
|
1720 |
*/ |
|
1721 |
public boolean isLoggable(Level level) { |
|
1722 |
if (level.intValue() < levelValue || levelValue == offValue) { |
|
1723 |
return false; |
|
1724 |
} |
|
1725 |
return true; |
|
1726 |
} |
|
1727 |
||
1728 |
/** |
|
1729 |
* Get the name for this logger. |
|
1730 |
* @return logger name. Will be null for anonymous Loggers. |
|
1731 |
*/ |
|
1732 |
public String getName() { |
|
1733 |
return name; |
|
1734 |
} |
|
1735 |
||
1736 |
/** |
|
1737 |
* Add a log Handler to receive logging messages. |
|
1738 |
* <p> |
|
1739 |
* By default, Loggers also send their output to their parent logger. |
|
1740 |
* Typically the root Logger is configured with a set of Handlers |
|
1741 |
* that essentially act as default handlers for all loggers. |
|
1742 |
* |
|
1743 |
* @param handler a logging Handler |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1744 |
* @throws SecurityException if a security manager exists, |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1745 |
* this logger is not anonymous, and the caller |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1746 |
* does not have LoggingPermission("control"). |
2 | 1747 |
*/ |
1933 | 1748 |
public void addHandler(Handler handler) throws SecurityException { |
2 | 1749 |
// Check for null handler |
1750 |
handler.getClass(); |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
10046
diff
changeset
|
1751 |
checkPermission(); |
2 | 1752 |
handlers.add(handler); |
1753 |
} |
|
1754 |
||
1755 |
/** |
|
1756 |
* Remove a log Handler. |
|
1757 |
* <P> |
|
1758 |
* Returns silently if the given Handler is not found or is null |
|
1759 |
* |
|
1760 |
* @param handler a logging Handler |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1761 |
* @throws SecurityException if a security manager exists, |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1762 |
* this logger is not anonymous, and the caller |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1763 |
* does not have LoggingPermission("control"). |
2 | 1764 |
*/ |
1933 | 1765 |
public void removeHandler(Handler handler) throws SecurityException { |
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
10046
diff
changeset
|
1766 |
checkPermission(); |
2 | 1767 |
if (handler == null) { |
1768 |
return; |
|
1769 |
} |
|
1770 |
handlers.remove(handler); |
|
1771 |
} |
|
1772 |
||
1773 |
/** |
|
1774 |
* Get the Handlers associated with this logger. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1775 |
* |
2 | 1776 |
* @return an array of all registered Handlers |
1777 |
*/ |
|
1933 | 1778 |
public Handler[] getHandlers() { |
23899 | 1779 |
return accessCheckedHandlers(); |
1780 |
} |
|
1781 |
||
1782 |
// This method should ideally be marked final - but unfortunately |
|
1783 |
// it needs to be overridden by LogManager.RootLogger |
|
1784 |
Handler[] accessCheckedHandlers() { |
|
1933 | 1785 |
return handlers.toArray(emptyHandlers); |
2 | 1786 |
} |
1787 |
||
1788 |
/** |
|
1789 |
* Specify whether or not this logger should send its output |
|
3853 | 1790 |
* to its parent Logger. This means that any LogRecords will |
2 | 1791 |
* also be written to the parent's Handlers, and potentially |
1792 |
* to its parent, recursively up the namespace. |
|
1793 |
* |
|
1794 |
* @param useParentHandlers true if output is to be sent to the |
|
1795 |
* logger's parent. |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1796 |
* @throws SecurityException if a security manager exists, |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1797 |
* this logger is not anonymous, and the caller |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1798 |
* does not have LoggingPermission("control"). |
2 | 1799 |
*/ |
1933 | 1800 |
public void setUseParentHandlers(boolean useParentHandlers) { |
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
10046
diff
changeset
|
1801 |
checkPermission(); |
2 | 1802 |
this.useParentHandlers = useParentHandlers; |
1803 |
} |
|
1804 |
||
1805 |
/** |
|
1806 |
* Discover whether or not this logger is sending its output |
|
1807 |
* to its parent logger. |
|
1808 |
* |
|
1809 |
* @return true if output is to be sent to the logger's parent |
|
1810 |
*/ |
|
1933 | 1811 |
public boolean getUseParentHandlers() { |
2 | 1812 |
return useParentHandlers; |
1813 |
} |
|
1814 |
||
16098 | 1815 |
private static ResourceBundle findSystemResourceBundle(final Locale locale) { |
1816 |
// the resource bundle is in a restricted package |
|
1817 |
return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() { |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1818 |
@Override |
16098 | 1819 |
public ResourceBundle run() { |
1820 |
try { |
|
1821 |
return ResourceBundle.getBundle(SYSTEM_LOGGER_RB_NAME, |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1822 |
locale, |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1823 |
ClassLoader.getSystemClassLoader()); |
16098 | 1824 |
} catch (MissingResourceException e) { |
1825 |
throw new InternalError(e.toString()); |
|
1826 |
} |
|
1827 |
} |
|
1828 |
}); |
|
1829 |
} |
|
1830 |
||
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1831 |
/** |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1832 |
* Private utility method to map a resource bundle name to an |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1833 |
* actual resource bundle, using a simple one-entry cache. |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1834 |
* Returns null for a null name. |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1835 |
* May also return null if we can't find the resource bundle and |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1836 |
* there is no suitable previous cached value. |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1837 |
* |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1838 |
* @param name the ResourceBundle to locate |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1839 |
* @param userCallersClassLoader if true search using the caller's ClassLoader |
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1840 |
* @return ResourceBundle specified by name or null if not found |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1841 |
*/ |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1842 |
private synchronized ResourceBundle findResourceBundle(String name, |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1843 |
boolean useCallersClassLoader) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1844 |
// For all lookups, we first check the thread context class loader |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1845 |
// if it is set. If not, we use the system classloader. If we |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1846 |
// still haven't found it we use the callersClassLoaderRef if it |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1847 |
// is set and useCallersClassLoader is true. We set |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1848 |
// callersClassLoaderRef initially upon creating the logger with a |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1849 |
// non-null resource bundle name. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1850 |
|
2 | 1851 |
// Return a null bundle for a null name. |
1852 |
if (name == null) { |
|
1853 |
return null; |
|
1854 |
} |
|
1855 |
||
1856 |
Locale currentLocale = Locale.getDefault(); |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1857 |
final LoggerBundle lb = loggerBundle; |
2 | 1858 |
|
1859 |
// Normally we should hit on our simple one entry cache. |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1860 |
if (lb.userBundle != null && |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1861 |
name.equals(lb.resourceBundleName)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1862 |
return lb.userBundle; |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1863 |
} else if (catalog != null && currentLocale.equals(catalogLocale) |
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1864 |
&& name.equals(catalogName)) { |
2 | 1865 |
return catalog; |
1866 |
} |
|
1867 |
||
16098 | 1868 |
if (name.equals(SYSTEM_LOGGER_RB_NAME)) { |
1869 |
catalog = findSystemResourceBundle(currentLocale); |
|
1870 |
catalogName = name; |
|
1871 |
catalogLocale = currentLocale; |
|
1872 |
return catalog; |
|
1873 |
} |
|
1874 |
||
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1875 |
// Use the thread's context ClassLoader. If there isn't one, use the |
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1876 |
// {@linkplain java.lang.ClassLoader#getSystemClassLoader() system ClassLoader}. |
2 | 1877 |
ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
1878 |
if (cl == null) { |
|
1879 |
cl = ClassLoader.getSystemClassLoader(); |
|
1880 |
} |
|
1881 |
try { |
|
1882 |
catalog = ResourceBundle.getBundle(name, currentLocale, cl); |
|
1883 |
catalogName = name; |
|
1884 |
catalogLocale = currentLocale; |
|
1885 |
return catalog; |
|
1886 |
} catch (MissingResourceException ex) { |
|
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1887 |
// We can't find the ResourceBundle in the default |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1888 |
// ClassLoader. Drop through. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1889 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1890 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1891 |
if (useCallersClassLoader) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1892 |
// Try with the caller's ClassLoader |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1893 |
ClassLoader callersClassLoader = getCallersClassLoader(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1894 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1895 |
if (callersClassLoader == null || callersClassLoader == cl) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1896 |
return null; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1897 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1898 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1899 |
try { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1900 |
catalog = ResourceBundle.getBundle(name, currentLocale, |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1901 |
callersClassLoader); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1902 |
catalogName = name; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1903 |
catalogLocale = currentLocale; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1904 |
return catalog; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1905 |
} catch (MissingResourceException ex) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1906 |
return null; // no luck |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1907 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1908 |
} else { |
16475
6b45edea3370
8002070: Remove the stack search for a resource bundle for Logger to use
jgish
parents:
15310
diff
changeset
|
1909 |
return null; |
2 | 1910 |
} |
1911 |
} |
|
1912 |
||
1913 |
// Private utility method to initialize our one entry |
|
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1914 |
// resource bundle name cache and the callers ClassLoader |
2 | 1915 |
// Note: for consistency reasons, we are careful to check |
1916 |
// that a suitable ResourceBundle exists before setting the |
|
10046
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1917 |
// resourceBundleName field. |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1918 |
// Synchronized to prevent races in setting the fields. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1919 |
private synchronized void setupResourceInfo(String name, |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1920 |
Class<?> callersClass) { |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1921 |
final LoggerBundle lb = loggerBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1922 |
if (lb.resourceBundleName != null) { |
10046
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1923 |
// this Logger already has a ResourceBundle |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1924 |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1925 |
if (lb.resourceBundleName.equals(name)) { |
10046
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1926 |
// the names match so there is nothing more to do |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1927 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1928 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1929 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1930 |
// cannot change ResourceBundles once they are set |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1931 |
throw new IllegalArgumentException( |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1932 |
lb.resourceBundleName + " != " + name); |
10046
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1933 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
9699
diff
changeset
|
1934 |
|
19584
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
1935 |
if (name == null) { |
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
1936 |
return; |
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
1937 |
} |
6ddcdf868ab5
8005899: Logger.getLogger(name, null) should not allow to reset a non-null resource bundle
dfuchs
parents:
18595
diff
changeset
|
1938 |
|
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1939 |
setCallersClassLoaderRef(callersClass); |
27074 | 1940 |
if (isSystemLogger && getCallersClassLoader() != null) { |
1941 |
checkPermission(); |
|
1942 |
} |
|
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1943 |
if (findResourceBundle(name, true) == null) { |
2 | 1944 |
// We've failed to find an expected ResourceBundle. |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1945 |
// unset the caller's ClassLoader since we were unable to find the |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1946 |
// the bundle using it |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1947 |
this.callersClassLoaderRef = null; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1948 |
throw new MissingResourceException("Can't find " + name + " bundle", |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
16906
diff
changeset
|
1949 |
name, ""); |
2 | 1950 |
} |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1951 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1952 |
// if lb.userBundle is not null we won't reach this line. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1953 |
assert lb.userBundle == null; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1954 |
loggerBundle = LoggerBundle.get(name, null); |
2 | 1955 |
} |
1956 |
||
1957 |
/** |
|
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1958 |
* Sets a resource bundle on this logger. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1959 |
* All messages will be logged using the given resource bundle for its |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1960 |
* specific {@linkplain ResourceBundle#getLocale locale}. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1961 |
* @param bundle The resource bundle that this logger shall use. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1962 |
* @throws NullPointerException if the given bundle is {@code null}. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1963 |
* @throws IllegalArgumentException if the given bundle doesn't have a |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1964 |
* {@linkplain ResourceBundle#getBaseBundleName base name}, |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1965 |
* or if this logger already has a resource bundle set but |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1966 |
* the given bundle has a different base name. |
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1967 |
* @throws SecurityException if a security manager exists, |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1968 |
* this logger is not anonymous, and the caller |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
1969 |
* does not have LoggingPermission("control"). |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1970 |
* @since 1.8 |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1971 |
*/ |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1972 |
public void setResourceBundle(ResourceBundle bundle) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1973 |
checkPermission(); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1974 |
|
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1975 |
// Will throw NPE if bundle is null. |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1976 |
final String baseName = bundle.getBaseBundleName(); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1977 |
|
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1978 |
// bundle must have a name |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1979 |
if (baseName == null || baseName.isEmpty()) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1980 |
throw new IllegalArgumentException("resource bundle must have a name"); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1981 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1982 |
|
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1983 |
synchronized (this) { |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1984 |
LoggerBundle lb = loggerBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1985 |
final boolean canReplaceResourceBundle = lb.resourceBundleName == null |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1986 |
|| lb.resourceBundleName.equals(baseName); |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1987 |
|
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1988 |
if (!canReplaceResourceBundle) { |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1989 |
throw new IllegalArgumentException("can't replace resource bundle"); |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1990 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1991 |
|
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1992 |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
1993 |
loggerBundle = LoggerBundle.get(baseName, bundle); |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1994 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1995 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1996 |
|
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
1997 |
/** |
2 | 1998 |
* Return the parent for this Logger. |
1999 |
* <p> |
|
2000 |
* This method returns the nearest extant parent in the namespace. |
|
2001 |
* Thus if a Logger is called "a.b.c.d", and a Logger called "a.b" |
|
2002 |
* has been created but no logger "a.b.c" exists, then a call of |
|
2003 |
* getParent on the Logger "a.b.c.d" will return the Logger "a.b". |
|
2004 |
* <p> |
|
2005 |
* The result will be null if it is called on the root Logger |
|
2006 |
* in the namespace. |
|
2007 |
* |
|
2008 |
* @return nearest existing parent Logger |
|
2009 |
*/ |
|
2010 |
public Logger getParent() { |
|
1933 | 2011 |
// Note: this used to be synchronized on treeLock. However, this only |
2012 |
// provided memory semantics, as there was no guarantee that the caller |
|
2013 |
// would synchronize on treeLock (in fact, there is no way for external |
|
2014 |
// callers to so synchronize). Therefore, we have made parent volatile |
|
2015 |
// instead. |
|
2016 |
return parent; |
|
2 | 2017 |
} |
2018 |
||
2019 |
/** |
|
2020 |
* Set the parent for this Logger. This method is used by |
|
2021 |
* the LogManager to update a Logger when the namespace changes. |
|
2022 |
* <p> |
|
2023 |
* It should not be called from application code. |
|
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
2024 |
* |
2 | 2025 |
* @param parent the new parent logger |
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2026 |
* @throws SecurityException if a security manager exists and if |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2027 |
* the caller does not have LoggingPermission("control"). |
2 | 2028 |
*/ |
2029 |
public void setParent(Logger parent) { |
|
2030 |
if (parent == null) { |
|
2031 |
throw new NullPointerException(); |
|
2032 |
} |
|
21369
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2033 |
|
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2034 |
// check permission for all loggers, including anonymous loggers |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2035 |
if (manager == null) { |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2036 |
manager = LogManager.getLogManager(); |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2037 |
} |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2038 |
manager.checkPermission(); |
45d88a0a11d5
8026863: regression in anonymous Logger.setParent method
dfuchs
parents:
21334
diff
changeset
|
2039 |
|
2 | 2040 |
doSetParent(parent); |
2041 |
} |
|
2042 |
||
2043 |
// Private method to do the work for parenting a child |
|
2044 |
// Logger onto a parent logger. |
|
2045 |
private void doSetParent(Logger newParent) { |
|
2046 |
||
2047 |
// System.err.println("doSetParent \"" + getName() + "\" \"" |
|
2048 |
// + newParent.getName() + "\""); |
|
2049 |
||
2050 |
synchronized (treeLock) { |
|
2051 |
||
2052 |
// Remove ourself from any previous parent. |
|
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2053 |
LogManager.LoggerWeakRef ref = null; |
2 | 2054 |
if (parent != null) { |
2055 |
// assert parent.kids != null; |
|
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2056 |
for (Iterator<LogManager.LoggerWeakRef> iter = parent.kids.iterator(); iter.hasNext(); ) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2057 |
ref = iter.next(); |
2 | 2058 |
Logger kid = ref.get(); |
2059 |
if (kid == this) { |
|
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2060 |
// ref is used down below to complete the reparenting |
2 | 2061 |
iter.remove(); |
2062 |
break; |
|
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2063 |
} else { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2064 |
ref = null; |
2 | 2065 |
} |
2066 |
} |
|
2067 |
// We have now removed ourself from our parents' kids. |
|
2068 |
} |
|
2069 |
||
2070 |
// Set our new parent. |
|
2071 |
parent = newParent; |
|
2072 |
if (parent.kids == null) { |
|
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
6675
diff
changeset
|
2073 |
parent.kids = new ArrayList<>(2); |
2 | 2074 |
} |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2075 |
if (ref == null) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2076 |
// we didn't have a previous parent |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2077 |
ref = manager.new LoggerWeakRef(this); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2078 |
} |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
2079 |
ref.setParentRef(new WeakReference<>(parent)); |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2080 |
parent.kids.add(ref); |
2 | 2081 |
|
2082 |
// As a result of the reparenting, the effective level |
|
2083 |
// may have changed for us and our children. |
|
2084 |
updateEffectiveLevel(); |
|
2085 |
||
2086 |
} |
|
2087 |
} |
|
2088 |
||
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2089 |
// Package-level method. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2090 |
// Remove the weak reference for the specified child Logger from the |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2091 |
// kid list. We should only be called from LoggerWeakRef.dispose(). |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2092 |
final void removeChildLogger(LogManager.LoggerWeakRef child) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2093 |
synchronized (treeLock) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2094 |
for (Iterator<LogManager.LoggerWeakRef> iter = kids.iterator(); iter.hasNext(); ) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2095 |
LogManager.LoggerWeakRef ref = iter.next(); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2096 |
if (ref == child) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2097 |
iter.remove(); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2098 |
return; |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2099 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2100 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2101 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2102 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
2103 |
|
2 | 2104 |
// Recalculate the effective level for this node and |
2105 |
// recursively for our children. |
|
2106 |
||
2107 |
private void updateEffectiveLevel() { |
|
2108 |
// assert Thread.holdsLock(treeLock); |
|
2109 |
||
2110 |
// Figure out our current effective level. |
|
2111 |
int newLevelValue; |
|
2112 |
if (levelObject != null) { |
|
2113 |
newLevelValue = levelObject.intValue(); |
|
2114 |
} else { |
|
2115 |
if (parent != null) { |
|
2116 |
newLevelValue = parent.levelValue; |
|
2117 |
} else { |
|
2118 |
// This may happen during initialization. |
|
2119 |
newLevelValue = Level.INFO.intValue(); |
|
2120 |
} |
|
2121 |
} |
|
2122 |
||
2123 |
// If our effective value hasn't changed, we're done. |
|
2124 |
if (levelValue == newLevelValue) { |
|
2125 |
return; |
|
2126 |
} |
|
2127 |
||
2128 |
levelValue = newLevelValue; |
|
2129 |
||
2130 |
// System.err.println("effective level: \"" + getName() + "\" := " + level); |
|
2131 |
||
2132 |
// Recursively update the level on each of our kids. |
|
2133 |
if (kids != null) { |
|
22078
bdec5d53e98c
8030851: Update code in java.util to use newer language features
psandoz
parents:
21960
diff
changeset
|
2134 |
for (LogManager.LoggerWeakRef ref : kids) { |
bdec5d53e98c
8030851: Update code in java.util to use newer language features
psandoz
parents:
21960
diff
changeset
|
2135 |
Logger kid = ref.get(); |
2 | 2136 |
if (kid != null) { |
2137 |
kid.updateEffectiveLevel(); |
|
2138 |
} |
|
2139 |
} |
|
2140 |
} |
|
2141 |
} |
|
2142 |
||
2143 |
||
2144 |
// Private method to get the potentially inherited |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2145 |
// resource bundle and resource bundle name for this Logger. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2146 |
// This method never returns null. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2147 |
private LoggerBundle getEffectiveLoggerBundle() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2148 |
final LoggerBundle lb = loggerBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2149 |
if (lb.isSystemBundle()) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2150 |
return SYSTEM_BUNDLE; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2151 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2152 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2153 |
// first take care of this logger |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2154 |
final ResourceBundle b = getResourceBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2155 |
if (b != null && b == lb.userBundle) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2156 |
return lb; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2157 |
} else if (b != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2158 |
// either lb.userBundle is null or getResourceBundle() is |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2159 |
// overriden |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2160 |
final String rbName = getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2161 |
return LoggerBundle.get(rbName, b); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2162 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2163 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2164 |
// no resource bundle was specified on this logger, look up the |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2165 |
// parent stack. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2166 |
Logger target = this.parent; |
2 | 2167 |
while (target != null) { |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2168 |
final LoggerBundle trb = target.loggerBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2169 |
if (trb.isSystemBundle()) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2170 |
return SYSTEM_BUNDLE; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2171 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2172 |
if (trb.userBundle != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2173 |
return trb; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2174 |
} |
23899 | 2175 |
final String rbName = isSystemLogger |
27074 | 2176 |
// ancestor of a system logger is expected to be a system logger. |
2177 |
// ignore resource bundle name if it's not. |
|
2178 |
? (target.isSystemLogger ? trb.resourceBundleName : null) |
|
23899 | 2179 |
: target.getResourceBundleName(); |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2180 |
if (rbName != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2181 |
return LoggerBundle.get(rbName, |
27074 | 2182 |
findResourceBundle(rbName, true)); |
2 | 2183 |
} |
23899 | 2184 |
target = isSystemLogger ? target.parent : target.getParent(); |
2 | 2185 |
} |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21655
diff
changeset
|
2186 |
return NO_RESOURCE_BUNDLE; |
20865
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
2187 |
} |
164ba3f3484b
8013839: Enhance Logger API for handling of resource bundles
dfuchs
parents:
19847
diff
changeset
|
2188 |
|
2 | 2189 |
} |