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