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