author | plevart |
Sun, 17 May 2015 10:38:36 +0200 | |
changeset 30643 | 1fcf87dbdc3c |
parent 29919 | be906afc335b |
child 31150 | 2aa1d300cd75 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29739
3966f5f6a6fd
8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
27932
diff
changeset
|
2 |
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
||
27 |
package java.util.logging; |
|
28 |
||
29 |
import java.io.*; |
|
30 |
import java.util.*; |
|
31 |
import java.security.*; |
|
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
32 |
import java.lang.ref.ReferenceQueue; |
2 | 33 |
import java.lang.ref.WeakReference; |
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
34 |
import java.util.concurrent.ConcurrentHashMap; |
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
35 |
import java.util.concurrent.CopyOnWriteArrayList; |
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
36 |
import java.util.concurrent.locks.ReentrantLock; |
16098 | 37 |
import sun.misc.JavaAWTAccess; |
29919
be906afc335b
8047149: Enhance thread contexts in core libraries
chegar
parents:
29740
diff
changeset
|
38 |
import sun.misc.ManagedLocalsThread; |
16098 | 39 |
import sun.misc.SharedSecrets; |
2 | 40 |
|
41 |
/** |
|
42 |
* There is a single global LogManager object that is used to |
|
43 |
* maintain a set of shared state about Loggers and log services. |
|
44 |
* <p> |
|
45 |
* This LogManager object: |
|
46 |
* <ul> |
|
47 |
* <li> Manages a hierarchical namespace of Logger objects. All |
|
48 |
* named Loggers are stored in this namespace. |
|
49 |
* <li> Manages a set of logging control properties. These are |
|
50 |
* simple key-value pairs that can be used by Handlers and |
|
51 |
* other logging objects to configure themselves. |
|
52 |
* </ul> |
|
53 |
* <p> |
|
54 |
* The global LogManager object can be retrieved using LogManager.getLogManager(). |
|
55 |
* The LogManager object is created during class initialization and |
|
56 |
* cannot subsequently be changed. |
|
57 |
* <p> |
|
58 |
* At startup the LogManager class is located using the |
|
59 |
* java.util.logging.manager system property. |
|
60 |
* <p> |
|
14691
22056e110b04
8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents:
14342
diff
changeset
|
61 |
* The LogManager defines two optional system properties that allow control over |
22056e110b04
8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents:
14342
diff
changeset
|
62 |
* the initial configuration: |
2 | 63 |
* <ul> |
64 |
* <li>"java.util.logging.config.class" |
|
65 |
* <li>"java.util.logging.config.file" |
|
66 |
* </ul> |
|
14691
22056e110b04
8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents:
14342
diff
changeset
|
67 |
* These two properties may be specified on the command line to the "java" |
22056e110b04
8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents:
14342
diff
changeset
|
68 |
* command, or as system property definitions passed to JNI_CreateJavaVM. |
2 | 69 |
* <p> |
70 |
* If the "java.util.logging.config.class" property is set, then the |
|
71 |
* property value is treated as a class name. The given class will be |
|
72 |
* loaded, an object will be instantiated, and that object's constructor |
|
73 |
* is responsible for reading in the initial configuration. (That object |
|
74 |
* may use other system properties to control its configuration.) The |
|
75 |
* alternate configuration class can use <tt>readConfiguration(InputStream)</tt> |
|
76 |
* to define properties in the LogManager. |
|
77 |
* <p> |
|
78 |
* If "java.util.logging.config.class" property is <b>not</b> set, |
|
79 |
* then the "java.util.logging.config.file" system property can be used |
|
80 |
* to specify a properties file (in java.util.Properties format). The |
|
81 |
* initial logging configuration will be read from this file. |
|
82 |
* <p> |
|
14691
22056e110b04
8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents:
14342
diff
changeset
|
83 |
* If neither of these properties is defined then the LogManager uses its |
22056e110b04
8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents:
14342
diff
changeset
|
84 |
* default configuration. The default configuration is typically loaded from the |
27565 | 85 |
* properties file "{@code conf/logging.properties}" in the Java installation |
14691
22056e110b04
8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents:
14342
diff
changeset
|
86 |
* directory. |
2 | 87 |
* <p> |
88 |
* The properties for loggers and Handlers will have names starting |
|
89 |
* with the dot-separated name for the handler or logger. |
|
90 |
* <p> |
|
91 |
* The global logging properties may include: |
|
92 |
* <ul> |
|
93 |
* <li>A property "handlers". This defines a whitespace or comma separated |
|
94 |
* list of class names for handler classes to load and register as |
|
95 |
* handlers on the root Logger (the Logger named ""). Each class |
|
96 |
* name must be for a Handler class which has a default constructor. |
|
97 |
* Note that these Handlers may be created lazily, when they are |
|
98 |
* first used. |
|
99 |
* |
|
100 |
* <li>A property "<logger>.handlers". This defines a whitespace or |
|
101 |
* comma separated list of class names for handlers classes to |
|
102 |
* load and register as handlers to the specified logger. Each class |
|
103 |
* name must be for a Handler class which has a default constructor. |
|
104 |
* Note that these Handlers may be created lazily, when they are |
|
105 |
* first used. |
|
106 |
* |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
107 |
* <li>A property "<logger>.handlers.ensureCloseOnReset". This defines a |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
108 |
* a boolean value. If "<logger>.handlers" is not defined or is empty, |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
109 |
* this property is ignored. Otherwise it defaults to {@code true}. When the |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
110 |
* value is {@code true}, the handlers associated with the logger are guaranteed |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
111 |
* to be closed on {@linkplain #reset} and shutdown. This can be turned off |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
112 |
* by explicitly setting "<logger>.handlers.ensureCloseOnReset=false" in |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
113 |
* the configuration. Note that turning this property off causes the risk of |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
114 |
* introducing a resource leak, as the logger may get garbage collected before |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
115 |
* {@code reset()} is called, thus preventing its handlers from being closed |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
116 |
* on {@code reset()}. In that case it is the responsibility of the application |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
117 |
* to ensure that the handlers are closed before the logger is garbage |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
118 |
* collected. |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
119 |
* |
2 | 120 |
* <li>A property "<logger>.useParentHandlers". This defines a boolean |
121 |
* value. By default every logger calls its parent in addition to |
|
122 |
* handling the logging message itself, this often result in messages |
|
123 |
* being handled by the root logger as well. When setting this property |
|
124 |
* to false a Handler needs to be configured for this logger otherwise |
|
125 |
* no logging messages are delivered. |
|
126 |
* |
|
127 |
* <li>A property "config". This property is intended to allow |
|
128 |
* arbitrary configuration code to be run. The property defines a |
|
129 |
* whitespace or comma separated list of class names. A new instance will be |
|
130 |
* created for each named class. The default constructor of each class |
|
131 |
* may execute arbitrary code to update the logging configuration, such as |
|
132 |
* setting logger levels, adding handlers, adding filters, etc. |
|
133 |
* </ul> |
|
134 |
* <p> |
|
135 |
* Note that all classes loaded during LogManager configuration are |
|
136 |
* first searched on the system class path before any user class path. |
|
137 |
* That includes the LogManager class, any config classes, and any |
|
138 |
* handler classes. |
|
139 |
* <p> |
|
140 |
* Loggers are organized into a naming hierarchy based on their |
|
141 |
* dot separated names. Thus "a.b.c" is a child of "a.b", but |
|
142 |
* "a.b1" and a.b2" are peers. |
|
143 |
* <p> |
|
144 |
* All properties whose names end with ".level" are assumed to define |
|
145 |
* log levels for Loggers. Thus "foo.level" defines a log level for |
|
146 |
* the logger called "foo" and (recursively) for any of its children |
|
147 |
* in the naming hierarchy. Log Levels are applied in the order they |
|
148 |
* are defined in the properties file. Thus level settings for child |
|
149 |
* nodes in the tree should come after settings for their parents. |
|
150 |
* The property name ".level" can be used to set the level for the |
|
151 |
* root of the tree. |
|
152 |
* <p> |
|
153 |
* All methods on the LogManager object are multi-thread safe. |
|
154 |
* |
|
155 |
* @since 1.4 |
|
156 |
*/ |
|
157 |
||
158 |
public class LogManager { |
|
159 |
// The global LogManager object |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
160 |
private static final LogManager manager; |
2 | 161 |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
162 |
// 'props' is assigned within a lock but accessed without it. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
163 |
// Declaring it volatile makes sure that another thread will not |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
164 |
// be able to see a partially constructed 'props' object. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
165 |
// (seeing a partially constructed 'props' object can result in |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
166 |
// NPE being thrown in Hashtable.get(), because it leaves the door |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
167 |
// open for props.getProperties() to be called before the construcor |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
168 |
// of Hashtable is actually completed). |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
169 |
private volatile Properties props = new Properties(); |
2 | 170 |
private final static Level defaultLevel = Level.INFO; |
171 |
||
16098 | 172 |
// LoggerContext for system loggers and user loggers |
173 |
private final LoggerContext systemContext = new SystemLoggerContext(); |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
174 |
private final LoggerContext userContext = new LoggerContext(); |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
175 |
// non final field - make it volatile to make sure that other threads |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
176 |
// will see the new value once ensureLogManagerInitialized() has finished |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
177 |
// executing. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
178 |
private volatile Logger rootLogger; |
2 | 179 |
// Have we done the primordial reading of the configuration file? |
180 |
// (Must be done after a suitable amount of java.lang.System |
|
181 |
// initialization has been done) |
|
182 |
private volatile boolean readPrimordialConfiguration; |
|
183 |
// Have we initialized global (root) handlers yet? |
|
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
184 |
// This gets set to STATE_UNINITIALIZED in readConfiguration |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
185 |
private static final int |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
186 |
STATE_INITIALIZED = 0, // initial state |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
187 |
STATE_INITIALIZING = 1, |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
188 |
STATE_READING_CONFIG = 2, |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
189 |
STATE_UNINITIALIZED = 3, |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
190 |
STATE_SHUTDOWN = 4; // terminal state |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
191 |
private volatile int globalHandlersState; // = STATE_INITIALIZED; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
192 |
// A concurrency lock for reset(), readConfiguration() and Cleaner. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
193 |
private final ReentrantLock configurationLock = new ReentrantLock(); |
2 | 194 |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
195 |
// This list contains the loggers for which some handlers have been |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
196 |
// explicitly configured in the configuration file. |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
197 |
// It prevents these loggers from being arbitrarily garbage collected. |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
198 |
private static final class CloseOnReset { |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
199 |
private final Logger logger; |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
200 |
private CloseOnReset(Logger ref) { |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
201 |
this.logger = Objects.requireNonNull(ref); |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
202 |
} |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
203 |
@Override |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
204 |
public boolean equals(Object other) { |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
205 |
return (other instanceof CloseOnReset) && ((CloseOnReset)other).logger == logger; |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
206 |
} |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
207 |
@Override |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
208 |
public int hashCode() { |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
209 |
return System.identityHashCode(logger); |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
210 |
} |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
211 |
public Logger get() { |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
212 |
return logger; |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
213 |
} |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
214 |
public static CloseOnReset create(Logger logger) { |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
215 |
return new CloseOnReset(logger); |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
216 |
} |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
217 |
} |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
218 |
private final CopyOnWriteArrayList<CloseOnReset> closeOnResetLoggers = |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
219 |
new CopyOnWriteArrayList<>(); |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
220 |
|
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
221 |
|
26859
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
222 |
private final Map<Object, Runnable> listeners = |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
223 |
Collections.synchronizedMap(new IdentityHashMap<>()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
224 |
|
2 | 225 |
static { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
226 |
manager = AccessController.doPrivileged(new PrivilegedAction<LogManager>() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
227 |
@Override |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
228 |
public LogManager run() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
229 |
LogManager mgr = null; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
230 |
String cname = null; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
231 |
try { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
232 |
cname = System.getProperty("java.util.logging.manager"); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
233 |
if (cname != null) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
234 |
try { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
235 |
Class<?> clz = ClassLoader.getSystemClassLoader() |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
236 |
.loadClass(cname); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
237 |
mgr = (LogManager) clz.newInstance(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
238 |
} catch (ClassNotFoundException ex) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
239 |
Class<?> clz = Thread.currentThread() |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
240 |
.getContextClassLoader().loadClass(cname); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
241 |
mgr = (LogManager) clz.newInstance(); |
2 | 242 |
} |
243 |
} |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
244 |
} catch (Exception ex) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
245 |
System.err.println("Could not load Logmanager \"" + cname + "\""); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
246 |
ex.printStackTrace(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
247 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
248 |
if (mgr == null) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
249 |
mgr = new LogManager(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
250 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
251 |
return mgr; |
2 | 252 |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
253 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
254 |
}); |
2 | 255 |
} |
256 |
||
257 |
// This private class is used as a shutdown hook. |
|
258 |
// It does a "reset" to close all open handlers. |
|
29919
be906afc335b
8047149: Enhance thread contexts in core libraries
chegar
parents:
29740
diff
changeset
|
259 |
private class Cleaner extends ManagedLocalsThread { |
2384
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
260 |
|
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
261 |
private Cleaner() { |
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
262 |
/* Set context class loader to null in order to avoid |
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
263 |
* keeping a strong reference to an application classloader. |
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
264 |
*/ |
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
265 |
this.setContextClassLoader(null); |
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
266 |
} |
b3ba5fb77f89
6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
2
diff
changeset
|
267 |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
268 |
@Override |
2 | 269 |
public void run() { |
270 |
// This is to ensure the LogManager.<clinit> is completed |
|
271 |
// before synchronized block. Otherwise deadlocks are possible. |
|
272 |
LogManager mgr = manager; |
|
273 |
||
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
274 |
// set globalHandlersState to STATE_SHUTDOWN atomically so that |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
275 |
// no attempts are made to (re)initialize the handlers or (re)read |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
276 |
// the configuration again. This is terminal state. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
277 |
configurationLock.lock(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
278 |
globalHandlersState = STATE_SHUTDOWN; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
279 |
configurationLock.unlock(); |
2 | 280 |
|
281 |
// Do a reset to close all active handlers. |
|
282 |
reset(); |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
||
287 |
/** |
|
288 |
* Protected constructor. This is protected so that container applications |
|
289 |
* (such as J2EE containers) can subclass the object. It is non-public as |
|
290 |
* it is intended that there only be one LogManager object, whose value is |
|
14767
b64db1d425e5
4819681: Typo in http://java.sun.com/j2se/1.4.1/docs/api/java/util/logging/LogManager.html
mchung
parents:
14691
diff
changeset
|
291 |
* retrieved by calling LogManager.getLogManager. |
2 | 292 |
*/ |
293 |
protected LogManager() { |
|
22321 | 294 |
this(checkSubclassPermissions()); |
295 |
} |
|
296 |
||
297 |
private LogManager(Void checked) { |
|
298 |
||
2 | 299 |
// Add a shutdown hook to close the global handlers. |
300 |
try { |
|
301 |
Runtime.getRuntime().addShutdownHook(new Cleaner()); |
|
302 |
} catch (IllegalStateException e) { |
|
303 |
// If the VM is already shutting down, |
|
304 |
// We do not need to register shutdownHook. |
|
305 |
} |
|
306 |
} |
|
307 |
||
22321 | 308 |
private static Void checkSubclassPermissions() { |
309 |
final SecurityManager sm = System.getSecurityManager(); |
|
310 |
if (sm != null) { |
|
311 |
// These permission will be checked in the LogManager constructor, |
|
312 |
// in order to register the Cleaner() thread as a shutdown hook. |
|
313 |
// Check them here to avoid the penalty of constructing the object |
|
314 |
// etc... |
|
315 |
sm.checkPermission(new RuntimePermission("shutdownHooks")); |
|
316 |
sm.checkPermission(new RuntimePermission("setContextClassLoader")); |
|
317 |
} |
|
318 |
return null; |
|
319 |
} |
|
320 |
||
2 | 321 |
/** |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
322 |
* Lazy initialization: if this instance of manager is the global |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
323 |
* manager then this method will read the initial configuration and |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
324 |
* add the root logger and global logger by calling addLogger(). |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
325 |
* |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
326 |
* Note that it is subtly different from what we do in LoggerContext. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
327 |
* In LoggerContext we're patching up the logger context tree in order to add |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
328 |
* the root and global logger *to the context tree*. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
329 |
* |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
330 |
* For this to work, addLogger() must have already have been called |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
331 |
* once on the LogManager instance for the default logger being |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
332 |
* added. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
333 |
* |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
334 |
* This is why ensureLogManagerInitialized() needs to be called before |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
335 |
* any logger is added to any logger context. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
336 |
* |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
337 |
*/ |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
338 |
private boolean initializedCalled = false; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
339 |
private volatile boolean initializationDone = false; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
340 |
final void ensureLogManagerInitialized() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
341 |
final LogManager owner = this; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
342 |
if (initializationDone || owner != manager) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
343 |
// we don't want to do this twice, and we don't want to do |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
344 |
// this on private manager instances. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
345 |
return; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
346 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
347 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
348 |
// Maybe another thread has called ensureLogManagerInitialized() |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
349 |
// before us and is still executing it. If so we will block until |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
350 |
// the log manager has finished initialized, then acquire the monitor, |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
351 |
// notice that initializationDone is now true and return. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
352 |
// Otherwise - we have come here first! We will acquire the monitor, |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
353 |
// see that initializationDone is still false, and perform the |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
354 |
// initialization. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
355 |
// |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
356 |
synchronized(this) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
357 |
// If initializedCalled is true it means that we're already in |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
358 |
// the process of initializing the LogManager in this thread. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
359 |
// There has been a recursive call to ensureLogManagerInitialized(). |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
360 |
final boolean isRecursiveInitialization = (initializedCalled == true); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
361 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
362 |
assert initializedCalled || !initializationDone |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
363 |
: "Initialization can't be done if initialized has not been called!"; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
364 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
365 |
if (isRecursiveInitialization || initializationDone) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
366 |
// If isRecursiveInitialization is true it means that we're |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
367 |
// already in the process of initializing the LogManager in |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
368 |
// this thread. There has been a recursive call to |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
369 |
// ensureLogManagerInitialized(). We should not proceed as |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
370 |
// it would lead to infinite recursion. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
371 |
// |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
372 |
// If initializationDone is true then it means the manager |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
373 |
// has finished initializing; just return: we're done. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
374 |
return; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
375 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
376 |
// Calling addLogger below will in turn call requiresDefaultLogger() |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
377 |
// which will call ensureLogManagerInitialized(). |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
378 |
// We use initializedCalled to break the recursion. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
379 |
initializedCalled = true; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
380 |
try { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
381 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
382 |
@Override |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
383 |
public Object run() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
384 |
assert rootLogger == null; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
385 |
assert initializedCalled && !initializationDone; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
386 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
387 |
// Read configuration. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
388 |
owner.readPrimordialConfiguration(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
389 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
390 |
// Create and retain Logger for the root of the namespace. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
391 |
owner.rootLogger = owner.new RootLogger(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
392 |
owner.addLogger(owner.rootLogger); |
22086
866b0a7d0127
8030850: Setting .level=FINEST in logging configuration file doesn't work
dfuchs
parents:
22078
diff
changeset
|
393 |
if (!owner.rootLogger.isLevelInitialized()) { |
866b0a7d0127
8030850: Setting .level=FINEST in logging configuration file doesn't work
dfuchs
parents:
22078
diff
changeset
|
394 |
owner.rootLogger.setLevel(defaultLevel); |
866b0a7d0127
8030850: Setting .level=FINEST in logging configuration file doesn't work
dfuchs
parents:
22078
diff
changeset
|
395 |
} |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
396 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
397 |
// Adding the global Logger. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
398 |
// Do not call Logger.getGlobal() here as this might trigger |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
399 |
// subtle inter-dependency issues. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
400 |
@SuppressWarnings("deprecation") |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
401 |
final Logger global = Logger.global; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
402 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
403 |
// Make sure the global logger will be registered in the |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
404 |
// global manager |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
405 |
owner.addLogger(global); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
406 |
return null; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
407 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
408 |
}); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
409 |
} finally { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
410 |
initializationDone = true; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
411 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
412 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
413 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
414 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
415 |
/** |
18565 | 416 |
* Returns the global LogManager object. |
417 |
* @return the global LogManager object |
|
2 | 418 |
*/ |
419 |
public static LogManager getLogManager() { |
|
420 |
if (manager != null) { |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
421 |
manager.ensureLogManagerInitialized(); |
2 | 422 |
} |
423 |
return manager; |
|
424 |
} |
|
425 |
||
426 |
private void readPrimordialConfiguration() { |
|
427 |
if (!readPrimordialConfiguration) { |
|
428 |
synchronized (this) { |
|
429 |
if (!readPrimordialConfiguration) { |
|
430 |
// If System.in/out/err are null, it's a good |
|
431 |
// indication that we're still in the |
|
432 |
// bootstrapping phase |
|
433 |
if (System.out == null) { |
|
434 |
return; |
|
435 |
} |
|
436 |
readPrimordialConfiguration = true; |
|
16098 | 437 |
|
2 | 438 |
try { |
16098 | 439 |
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
440 |
@Override |
16098 | 441 |
public Void run() throws Exception { |
2 | 442 |
readConfiguration(); |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
3319
diff
changeset
|
443 |
|
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
3319
diff
changeset
|
444 |
// Platform loggers begin to delegate to java.util.logging.Logger |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
3319
diff
changeset
|
445 |
sun.util.logging.PlatformLogger.redirectPlatformLoggers(); |
2 | 446 |
return null; |
447 |
} |
|
448 |
}); |
|
449 |
} catch (Exception ex) { |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
450 |
assert false : "Exception raised while reading logging configuration: " + ex; |
2 | 451 |
} |
452 |
} |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
||
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
457 |
// LoggerContext maps from AppContext |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
458 |
private WeakHashMap<Object, LoggerContext> contextsMap = null; |
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
459 |
|
16098 | 460 |
// Returns the LoggerContext for the user code (i.e. application or AppContext). |
461 |
// Loggers are isolated from each AppContext. |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
462 |
private LoggerContext getUserContext() { |
16098 | 463 |
LoggerContext context = null; |
9700
fdbacf68f185
7016208: 4/3 null sometimes returned by java.util.logging.Logger.getLogger(String name) in -server -Xcomp
dcubed
parents:
9013
diff
changeset
|
464 |
|
16098 | 465 |
SecurityManager sm = System.getSecurityManager(); |
466 |
JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess(); |
|
467 |
if (sm != null && javaAwtAccess != null) { |
|
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
468 |
// for each applet, it has its own LoggerContext isolated from others |
27932
654c0f23c1c0
8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents:
27799
diff
changeset
|
469 |
final Object ecx = javaAwtAccess.getAppletContext(); |
654c0f23c1c0
8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents:
27799
diff
changeset
|
470 |
if (ecx != null) { |
654c0f23c1c0
8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents:
27799
diff
changeset
|
471 |
synchronized (javaAwtAccess) { |
654c0f23c1c0
8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents:
27799
diff
changeset
|
472 |
// find the AppContext of the applet code |
654c0f23c1c0
8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents:
27799
diff
changeset
|
473 |
// will be null if we are in the main app context. |
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
474 |
if (contextsMap == null) { |
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
475 |
contextsMap = new WeakHashMap<>(); |
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
476 |
} |
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
477 |
context = contextsMap.get(ecx); |
18202 | 478 |
if (context == null) { |
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
479 |
// Create a new LoggerContext for the applet. |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
480 |
context = new LoggerContext(); |
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
481 |
contextsMap.put(ecx, context); |
16098 | 482 |
} |
483 |
} |
|
484 |
} |
|
485 |
} |
|
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18595
diff
changeset
|
486 |
// for standalone app, return userContext |
18202 | 487 |
return context != null ? context : userContext; |
16098 | 488 |
} |
9700
fdbacf68f185
7016208: 4/3 null sometimes returned by java.util.logging.Logger.getLogger(String name) in -server -Xcomp
dcubed
parents:
9013
diff
changeset
|
489 |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
490 |
// The system context. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
491 |
final LoggerContext getSystemContext() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
492 |
return systemContext; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
493 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
494 |
|
16098 | 495 |
private List<LoggerContext> contexts() { |
496 |
List<LoggerContext> cxs = new ArrayList<>(); |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
497 |
cxs.add(getSystemContext()); |
16098 | 498 |
cxs.add(getUserContext()); |
499 |
return cxs; |
|
2 | 500 |
} |
501 |
||
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
502 |
// Find or create a specified logger instance. If a logger has |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
503 |
// already been created with the given name it is returned. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
504 |
// Otherwise a new logger instance is created and registered |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
505 |
// in the LogManager global namespace. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
506 |
// This method will always return a non-null Logger object. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
507 |
// Synchronization is not required here. All synchronization for |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
508 |
// adding a new Logger object is handled by addLogger(). |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
509 |
// |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
510 |
// This method must delegate to the LogManager implementation to |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
511 |
// add a new Logger or return the one that has been added previously |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
512 |
// as a LogManager subclass may override the addLogger, getLogger, |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
513 |
// readConfiguration, and other methods. |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
17164
diff
changeset
|
514 |
Logger demandLogger(String name, String resourceBundleName, Class<?> caller) { |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
515 |
Logger result = getLogger(name); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
516 |
if (result == null) { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
517 |
// only allocate the new logger once |
23899 | 518 |
Logger newLogger = new Logger(name, resourceBundleName, caller, this, false); |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
519 |
do { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
520 |
if (addLogger(newLogger)) { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
521 |
// We successfully added the new Logger that we |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
522 |
// created above so return it without refetching. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
523 |
return newLogger; |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
524 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
525 |
|
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
526 |
// We didn't add the new Logger that we created above |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
527 |
// because another thread added a Logger with the same |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
528 |
// name after our null check above and before our call |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
529 |
// to addLogger(). We have to refetch the Logger because |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
530 |
// addLogger() returns a boolean instead of the Logger |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
531 |
// reference itself. However, if the thread that created |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
532 |
// the other Logger is not holding a strong reference to |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
533 |
// the other Logger, then it is possible for the other |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
534 |
// Logger to be GC'ed after we saw it in addLogger() and |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
535 |
// before we can refetch it. If it has been GC'ed then |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
536 |
// we'll just loop around and try again. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
537 |
result = getLogger(name); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
538 |
} while (result == null); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
539 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
540 |
return result; |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
541 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
542 |
|
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
543 |
Logger demandSystemLogger(String name, String resourceBundleName) { |
16111
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
544 |
// Add a system logger in the system context's namespace |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
545 |
final Logger sysLogger = getSystemContext().demandLogger(name, resourceBundleName); |
16111
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
546 |
|
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
547 |
// Add the system logger to the LogManager's namespace if not exist |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
548 |
// so that there is only one single logger of the given name. |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
549 |
// System loggers are visible to applications unless a logger of |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
550 |
// the same name has been added. |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
551 |
Logger logger; |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
552 |
do { |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
553 |
// First attempt to call addLogger instead of getLogger |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
554 |
// This would avoid potential bug in custom LogManager.getLogger |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
555 |
// implementation that adds a logger if does not exist |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
556 |
if (addLogger(sysLogger)) { |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
557 |
// successfully added the new system logger |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
558 |
logger = sysLogger; |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
559 |
} else { |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
560 |
logger = getLogger(name); |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
561 |
} |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
562 |
} while (logger == null); |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
563 |
|
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
564 |
// LogManager will set the sysLogger's handlers via LogManager.addLogger method. |
23899 | 565 |
if (logger != sysLogger && sysLogger.accessCheckedHandlers().length == 0) { |
16111
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
566 |
// if logger already exists but handlers not set |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
567 |
final Logger l = logger; |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
568 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
569 |
@Override |
16111
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
570 |
public Void run() { |
23899 | 571 |
for (Handler hdl : l.accessCheckedHandlers()) { |
16111
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
572 |
sysLogger.addHandler(hdl); |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
573 |
} |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
574 |
return null; |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
575 |
} |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
576 |
}); |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
577 |
} |
5c5fc1d5bb38
8007393: Possible race condition after JDK-6664509
mchung
parents:
16105
diff
changeset
|
578 |
return sysLogger; |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
579 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
580 |
|
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
581 |
// LoggerContext maintains the logger namespace per context. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
582 |
// The default LogManager implementation has one system context and user |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
583 |
// context. The system context is used to maintain the namespace for |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
584 |
// all system loggers and is queried by the system code. If a system logger |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
585 |
// doesn't exist in the user context, it'll also be added to the user context. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
586 |
// The user context is queried by the user code and all other loggers are |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
587 |
// added in the user context. |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
588 |
class LoggerContext { |
16098 | 589 |
// Table of named Loggers that maps names to Loggers. |
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
590 |
private final ConcurrentHashMap<String,LoggerWeakRef> namedLoggers = |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
591 |
new ConcurrentHashMap<>(); |
16098 | 592 |
// Tree of named Loggers |
593 |
private final LogNode root; |
|
594 |
private LoggerContext() { |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
595 |
this.root = new LogNode(null, this); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
596 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
597 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
598 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
599 |
// Tells whether default loggers are required in this context. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
600 |
// If true, the default loggers will be lazily added. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
601 |
final boolean requiresDefaultLoggers() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
602 |
final boolean requiresDefaultLoggers = (getOwner() == manager); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
603 |
if (requiresDefaultLoggers) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
604 |
getOwner().ensureLogManagerInitialized(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
605 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
606 |
return requiresDefaultLoggers; |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
607 |
} |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
608 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
609 |
// This context's LogManager. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
610 |
final LogManager getOwner() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
611 |
return LogManager.this; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
612 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
613 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
614 |
// This context owner's root logger, which if not null, and if |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
615 |
// the context requires default loggers, will be added to the context |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
616 |
// logger's tree. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
617 |
final Logger getRootLogger() { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
618 |
return getOwner().rootLogger; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
619 |
} |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
620 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
621 |
// The global logger, which if not null, and if |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
622 |
// the context requires default loggers, will be added to the context |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
623 |
// logger's tree. |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
624 |
final Logger getGlobalLogger() { |
23342 | 625 |
@SuppressWarnings("deprecation") // avoids initialization cycles. |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
626 |
final Logger global = Logger.global; |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
627 |
return global; |
16098 | 628 |
} |
629 |
||
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
630 |
Logger demandLogger(String name, String resourceBundleName) { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
631 |
// a LogManager subclass may have its own implementation to add and |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
632 |
// get a Logger. So delegate to the LogManager to do the work. |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
633 |
final LogManager owner = getOwner(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
634 |
return owner.demandLogger(name, resourceBundleName, null); |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
635 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
636 |
|
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
637 |
|
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
638 |
// Due to subtle deadlock issues getUserContext() no longer |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
639 |
// calls addLocalLogger(rootLogger); |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
640 |
// Therefore - we need to add the default loggers later on. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
641 |
// Checks that the context is properly initialized |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
642 |
// This is necessary before calling e.g. find(name) |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
643 |
// or getLoggerNames() |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
644 |
// |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
645 |
private void ensureInitialized() { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
646 |
if (requiresDefaultLoggers()) { |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
647 |
// Ensure that the root and global loggers are set. |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
648 |
ensureDefaultLogger(getRootLogger()); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
649 |
ensureDefaultLogger(getGlobalLogger()); |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
650 |
} |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
651 |
} |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
652 |
|
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
653 |
|
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
654 |
Logger findLogger(String name) { |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
655 |
// Attempt to find logger without locking. |
16098 | 656 |
LoggerWeakRef ref = namedLoggers.get(name); |
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
657 |
Logger logger = ref == null ? null : ref.get(); |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
658 |
|
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
659 |
// if logger is not null, then we can return it right away. |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
660 |
// if name is "" or "global" and logger is null |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
661 |
// we need to fall through and check that this context is |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
662 |
// initialized. |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
663 |
// if ref is not null and logger is null we also need to |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
664 |
// fall through. |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
665 |
if (logger != null || (ref == null && !name.isEmpty() |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
666 |
&& !name.equals(Logger.GLOBAL_LOGGER_NAME))) { |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
667 |
return logger; |
16098 | 668 |
} |
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
669 |
|
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
670 |
// We either found a stale reference, or we were looking for |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
671 |
// "" or "global" and didn't find them. |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
672 |
// Make sure context is initialized (has the default loggers), |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
673 |
// and look up again, cleaning the stale reference if it hasn't |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
674 |
// been cleaned up in between. All this needs to be done inside |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
675 |
// a synchronized block. |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
676 |
synchronized(this) { |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
677 |
// ensure that this context is properly initialized before |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
678 |
// looking for loggers. |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
679 |
ensureInitialized(); |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
680 |
ref = namedLoggers.get(name); |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
681 |
if (ref == null) { |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
682 |
return null; |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
683 |
} |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
684 |
logger = ref.get(); |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
685 |
if (logger == null) { |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
686 |
// The namedLoggers map holds stale weak reference |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
687 |
// to a logger which has been GC-ed. |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
688 |
ref.dispose(); |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
689 |
} |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
690 |
return logger; |
16098 | 691 |
} |
692 |
} |
|
693 |
||
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
694 |
// This method is called before adding a logger to the |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
695 |
// context. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
696 |
// 'logger' is the context that will be added. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
697 |
// This method will ensure that the defaults loggers are added |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
698 |
// before adding 'logger'. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
699 |
// |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
700 |
private void ensureAllDefaultLoggers(Logger logger) { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
701 |
if (requiresDefaultLoggers()) { |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
702 |
final String name = logger.getName(); |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
703 |
if (!name.isEmpty()) { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
704 |
ensureDefaultLogger(getRootLogger()); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
705 |
if (!Logger.GLOBAL_LOGGER_NAME.equals(name)) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
706 |
ensureDefaultLogger(getGlobalLogger()); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
707 |
} |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
708 |
} |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
709 |
} |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
710 |
} |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
711 |
|
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
712 |
private void ensureDefaultLogger(Logger logger) { |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
713 |
// Used for lazy addition of root logger and global logger |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
714 |
// to a LoggerContext. |
18202 | 715 |
|
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
716 |
// This check is simple sanity: we do not want that this |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
717 |
// method be called for anything else than Logger.global |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
718 |
// or owner.rootLogger. |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
719 |
if (!requiresDefaultLoggers() || logger == null |
23342 | 720 |
|| logger != getGlobalLogger() && logger != LogManager.this.rootLogger ) { |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
721 |
|
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
722 |
// the case where we have a non null logger which is neither |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
723 |
// Logger.global nor manager.rootLogger indicates a serious |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
724 |
// issue - as ensureDefaultLogger should never be called |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
725 |
// with any other loggers than one of these two (or null - if |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
726 |
// e.g manager.rootLogger is not yet initialized)... |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
727 |
assert logger == null; |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
728 |
|
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
729 |
return; |
18202 | 730 |
} |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
731 |
|
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
732 |
// Adds the logger if it's not already there. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
733 |
if (!namedLoggers.containsKey(logger.getName())) { |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
734 |
// It is important to prevent addLocalLogger to |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
735 |
// call ensureAllDefaultLoggers when we're in the process |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
736 |
// off adding one of those default loggers - as this would |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
737 |
// immediately cause a stack overflow. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
738 |
// Therefore we must pass addDefaultLoggersIfNeeded=false, |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
739 |
// even if requiresDefaultLoggers is true. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
740 |
addLocalLogger(logger, false); |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
741 |
} |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
742 |
} |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
743 |
|
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
744 |
boolean addLocalLogger(Logger logger) { |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
745 |
// no need to add default loggers if it's not required |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
746 |
return addLocalLogger(logger, requiresDefaultLoggers()); |
18202 | 747 |
} |
748 |
||
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
749 |
// Add a logger to this context. This method will only set its level |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
750 |
// and process parent loggers. It doesn't set its handlers. |
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
751 |
synchronized boolean addLocalLogger(Logger logger, boolean addDefaultLoggersIfNeeded) { |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
752 |
// addDefaultLoggersIfNeeded serves to break recursion when adding |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
753 |
// default loggers. If we're adding one of the default loggers |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
754 |
// (we're being called from ensureDefaultLogger()) then |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
755 |
// addDefaultLoggersIfNeeded will be false: we don't want to |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
756 |
// call ensureAllDefaultLoggers again. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
757 |
// |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
758 |
// Note: addDefaultLoggersIfNeeded can also be false when |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
759 |
// requiresDefaultLoggers is false - since calling |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
760 |
// ensureAllDefaultLoggers would have no effect in this case. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
761 |
if (addDefaultLoggersIfNeeded) { |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
762 |
ensureAllDefaultLoggers(logger); |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
763 |
} |
18202 | 764 |
|
16098 | 765 |
final String name = logger.getName(); |
766 |
if (name == null) { |
|
767 |
throw new NullPointerException(); |
|
768 |
} |
|
769 |
LoggerWeakRef ref = namedLoggers.get(name); |
|
770 |
if (ref != null) { |
|
771 |
if (ref.get() == null) { |
|
17164 | 772 |
// It's possible that the Logger was GC'ed after a |
16098 | 773 |
// drainLoggerRefQueueBounded() call above so allow |
774 |
// a new one to be registered. |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
775 |
ref.dispose(); |
16098 | 776 |
} else { |
777 |
// We already have a registered logger with the given name. |
|
778 |
return false; |
|
779 |
} |
|
780 |
} |
|
781 |
||
782 |
// We're adding a new logger. |
|
783 |
// Note that we are creating a weak reference here. |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
784 |
final LogManager owner = getOwner(); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
785 |
logger.setLogManager(owner); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
786 |
ref = owner.new LoggerWeakRef(logger); |
16098 | 787 |
|
21304
7971ecf0fbed
8026499: Root Logger level can be reset unexpectedly
dfuchs
parents:
19825
diff
changeset
|
788 |
// Apply any initial level defined for the new logger, unless |
7971ecf0fbed
8026499: Root Logger level can be reset unexpectedly
dfuchs
parents:
19825
diff
changeset
|
789 |
// the logger's level is already initialized |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
790 |
Level level = owner.getLevelProperty(name + ".level", null); |
21304
7971ecf0fbed
8026499: Root Logger level can be reset unexpectedly
dfuchs
parents:
19825
diff
changeset
|
791 |
if (level != null && !logger.isLevelInitialized()) { |
16098 | 792 |
doSetLevel(logger, level); |
793 |
} |
|
794 |
||
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
795 |
// instantiation of the handler is done in the LogManager.addLogger |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
796 |
// implementation as a handler class may be only visible to LogManager |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
797 |
// subclass for the custom log manager case |
16098 | 798 |
processParentHandlers(logger, name); |
799 |
||
800 |
// Find the new node and its parent. |
|
801 |
LogNode node = getNode(name); |
|
802 |
node.loggerRef = ref; |
|
803 |
Logger parent = null; |
|
804 |
LogNode nodep = node.parent; |
|
805 |
while (nodep != null) { |
|
806 |
LoggerWeakRef nodeRef = nodep.loggerRef; |
|
807 |
if (nodeRef != null) { |
|
808 |
parent = nodeRef.get(); |
|
809 |
if (parent != null) { |
|
810 |
break; |
|
811 |
} |
|
812 |
} |
|
813 |
nodep = nodep.parent; |
|
814 |
} |
|
815 |
||
816 |
if (parent != null) { |
|
817 |
doSetParent(logger, parent); |
|
2 | 818 |
} |
16098 | 819 |
// Walk over the children and tell them we are their new parent. |
820 |
node.walkAndSetParent(logger); |
|
821 |
// new LogNode is ready so tell the LoggerWeakRef about it |
|
822 |
ref.setNode(node); |
|
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
823 |
|
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
824 |
// Do not publish 'ref' in namedLoggers before the logger tree |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
825 |
// is fully updated - because the named logger will be visible as |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
826 |
// soon as it is published in namedLoggers (findLogger takes |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
827 |
// benefit of the ConcurrentHashMap implementation of namedLoggers |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
828 |
// to avoid synchronizing on retrieval when that is possible). |
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
829 |
namedLoggers.put(name, ref); |
16098 | 830 |
return true; |
831 |
} |
|
832 |
||
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
833 |
void removeLoggerRef(String name, LoggerWeakRef ref) { |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
834 |
namedLoggers.remove(name, ref); |
16098 | 835 |
} |
836 |
||
837 |
synchronized Enumeration<String> getLoggerNames() { |
|
18593
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
838 |
// ensure that this context is properly initialized before |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
839 |
// returning logger names. |
40715ebb6681
8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents:
18565
diff
changeset
|
840 |
ensureInitialized(); |
29740
d9f64fdd3c97
7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents:
29739
diff
changeset
|
841 |
return Collections.enumeration(namedLoggers.keySet()); |
16098 | 842 |
} |
843 |
||
844 |
// If logger.getUseParentHandlers() returns 'true' and any of the logger's |
|
845 |
// parents have levels or handlers defined, make sure they are instantiated. |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
846 |
private void processParentHandlers(final Logger logger, final String name) { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
847 |
final LogManager owner = getOwner(); |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
848 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
849 |
@Override |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
850 |
public Void run() { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
851 |
if (logger != owner.rootLogger) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
852 |
boolean useParent = owner.getBooleanProperty(name + ".useParentHandlers", true); |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
853 |
if (!useParent) { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
854 |
logger.setUseParentHandlers(false); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
855 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
856 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
857 |
return null; |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
858 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
859 |
}); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
860 |
|
16098 | 861 |
int ix = 1; |
862 |
for (;;) { |
|
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
24196
diff
changeset
|
863 |
int ix2 = name.indexOf('.', ix); |
16098 | 864 |
if (ix2 < 0) { |
865 |
break; |
|
866 |
} |
|
867 |
String pname = name.substring(0, ix2); |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
868 |
if (owner.getProperty(pname + ".level") != null || |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
869 |
owner.getProperty(pname + ".handlers") != null) { |
16098 | 870 |
// This pname has a level/handlers definition. |
871 |
// Make sure it exists. |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
872 |
demandLogger(pname, null); |
16098 | 873 |
} |
874 |
ix = ix2+1; |
|
875 |
} |
|
876 |
} |
|
2 | 877 |
|
16098 | 878 |
// Gets a node in our tree of logger nodes. |
879 |
// If necessary, create it. |
|
880 |
LogNode getNode(String name) { |
|
881 |
if (name == null || name.equals("")) { |
|
882 |
return root; |
|
883 |
} |
|
884 |
LogNode node = root; |
|
885 |
while (name.length() > 0) { |
|
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
24196
diff
changeset
|
886 |
int ix = name.indexOf('.'); |
16098 | 887 |
String head; |
888 |
if (ix > 0) { |
|
889 |
head = name.substring(0, ix); |
|
890 |
name = name.substring(ix + 1); |
|
891 |
} else { |
|
892 |
head = name; |
|
893 |
name = ""; |
|
894 |
} |
|
895 |
if (node.children == null) { |
|
896 |
node.children = new HashMap<>(); |
|
897 |
} |
|
898 |
LogNode child = node.children.get(head); |
|
899 |
if (child == null) { |
|
900 |
child = new LogNode(node, this); |
|
901 |
node.children.put(head, child); |
|
902 |
} |
|
903 |
node = child; |
|
2 | 904 |
} |
16098 | 905 |
return node; |
906 |
} |
|
907 |
} |
|
908 |
||
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
909 |
final class SystemLoggerContext extends LoggerContext { |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
910 |
// Add a system logger in the system context's namespace as well as |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
911 |
// in the LogManager's namespace if not exist so that there is only |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
912 |
// one single logger of the given name. System loggers are visible |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
913 |
// to applications unless a logger of the same name has been added. |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
914 |
@Override |
16098 | 915 |
Logger demandLogger(String name, String resourceBundleName) { |
916 |
Logger result = findLogger(name); |
|
917 |
if (result == null) { |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
918 |
// only allocate the new system logger once |
23899 | 919 |
Logger newLogger = new Logger(name, resourceBundleName, null, getOwner(), true); |
16098 | 920 |
do { |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
921 |
if (addLocalLogger(newLogger)) { |
16098 | 922 |
// We successfully added the new Logger that we |
923 |
// created above so return it without refetching. |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
924 |
result = newLogger; |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
925 |
} else { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
926 |
// We didn't add the new Logger that we created above |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
927 |
// because another thread added a Logger with the same |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
928 |
// name after our null check above and before our call |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
929 |
// to addLogger(). We have to refetch the Logger because |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
930 |
// addLogger() returns a boolean instead of the Logger |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
931 |
// reference itself. However, if the thread that created |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
932 |
// the other Logger is not holding a strong reference to |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
933 |
// the other Logger, then it is possible for the other |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
934 |
// Logger to be GC'ed after we saw it in addLogger() and |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
935 |
// before we can refetch it. If it has been GC'ed then |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
936 |
// we'll just loop around and try again. |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
937 |
result = findLogger(name); |
16098 | 938 |
} |
939 |
} while (result == null); |
|
940 |
} |
|
941 |
return result; |
|
2 | 942 |
} |
943 |
} |
|
944 |
||
945 |
// Add new per logger handlers. |
|
946 |
// We need to raise privilege here. All our decisions will |
|
947 |
// be made based on the logging configuration, which can |
|
948 |
// only be modified by trusted code. |
|
949 |
private void loadLoggerHandlers(final Logger logger, final String name, |
|
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
950 |
final String handlersPropertyName) |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
951 |
{ |
2 | 952 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
953 |
@Override |
2 | 954 |
public Object run() { |
955 |
String names[] = parseClassNames(handlersPropertyName); |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
956 |
final boolean ensureCloseOnReset = names.length > 0 |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
957 |
&& getBooleanProperty(handlersPropertyName + ".ensureCloseOnReset",true); |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
958 |
|
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
959 |
int count = 0; |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
960 |
for (String type : names) { |
2 | 961 |
try { |
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
962 |
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(type); |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
963 |
Handler hdl = (Handler) clz.newInstance(); |
16098 | 964 |
// Check if there is a property defining the |
965 |
// this handler's level. |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
966 |
String levs = getProperty(type + ".level"); |
16098 | 967 |
if (levs != null) { |
968 |
Level l = Level.findLevel(levs); |
|
969 |
if (l != null) { |
|
970 |
hdl.setLevel(l); |
|
971 |
} else { |
|
972 |
// Probably a bad level. Drop through. |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
973 |
System.err.println("Can't set level for " + type); |
2 | 974 |
} |
975 |
} |
|
976 |
// Add this Handler to the logger |
|
977 |
logger.addHandler(hdl); |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
978 |
if (++count == 1 && ensureCloseOnReset) { |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
979 |
// add this logger to the closeOnResetLoggers list. |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
980 |
closeOnResetLoggers.addIfAbsent(CloseOnReset.create(logger)); |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
981 |
} |
2 | 982 |
} catch (Exception ex) { |
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
983 |
System.err.println("Can't load log handler \"" + type + "\""); |
2 | 984 |
System.err.println("" + ex); |
985 |
ex.printStackTrace(); |
|
986 |
} |
|
987 |
} |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
988 |
|
2 | 989 |
return null; |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
990 |
} |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
991 |
}); |
2 | 992 |
} |
993 |
||
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
994 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
995 |
// loggerRefQueue holds LoggerWeakRef objects for Logger objects |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
996 |
// that have been GC'ed. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
997 |
private final ReferenceQueue<Logger> loggerRefQueue |
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
6675
diff
changeset
|
998 |
= new ReferenceQueue<>(); |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
999 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1000 |
// Package-level inner class. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1001 |
// Helper class for managing WeakReferences to Logger objects. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1002 |
// |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1003 |
// LogManager.namedLoggers |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1004 |
// - has weak references to all named Loggers |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1005 |
// - namedLoggers keeps the LoggerWeakRef objects for the named |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1006 |
// Loggers around until we can deal with the book keeping for |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1007 |
// the named Logger that is being GC'ed. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1008 |
// LogManager.LogNode.loggerRef |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1009 |
// - has a weak reference to a named Logger |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1010 |
// - the LogNode will also keep the LoggerWeakRef objects for |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1011 |
// the named Loggers around; currently LogNodes never go away. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1012 |
// Logger.kids |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1013 |
// - has a weak reference to each direct child Logger; this |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1014 |
// includes anonymous and named Loggers |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1015 |
// - anonymous Loggers are always children of the rootLogger |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1016 |
// which is a strong reference; rootLogger.kids keeps the |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1017 |
// LoggerWeakRef objects for the anonymous Loggers around |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1018 |
// until we can deal with the book keeping. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1019 |
// |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1020 |
final class LoggerWeakRef extends WeakReference<Logger> { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1021 |
private String name; // for namedLoggers cleanup |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1022 |
private LogNode node; // for loggerRef cleanup |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1023 |
private WeakReference<Logger> parentRef; // for kids cleanup |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1024 |
private boolean disposed = false; // avoid calling dispose twice |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1025 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1026 |
LoggerWeakRef(Logger logger) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1027 |
super(logger, loggerRefQueue); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1028 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1029 |
name = logger.getName(); // save for namedLoggers cleanup |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1030 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1031 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1032 |
// dispose of this LoggerWeakRef object |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1033 |
void dispose() { |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1034 |
// Avoid calling dispose twice. When a Logger is gc'ed, its |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1035 |
// LoggerWeakRef will be enqueued. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1036 |
// However, a new logger of the same name may be added (or looked |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1037 |
// up) before the queue is drained. When that happens, dispose() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1038 |
// will be called by addLocalLogger() or findLogger(). |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1039 |
// Later when the queue is drained, dispose() will be called again |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1040 |
// for the same LoggerWeakRef. Marking LoggerWeakRef as disposed |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1041 |
// avoids processing the data twice (even though the code should |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1042 |
// now be reentrant). |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1043 |
synchronized(this) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1044 |
// Note to maintainers: |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1045 |
// Be careful not to call any method that tries to acquire |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1046 |
// another lock from within this block - as this would surely |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1047 |
// lead to deadlocks, given that dispose() can be called by |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1048 |
// multiple threads, and from within different synchronized |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1049 |
// methods/blocks. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1050 |
if (disposed) return; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1051 |
disposed = true; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1052 |
} |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1053 |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1054 |
final LogNode n = node; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1055 |
if (n != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1056 |
// n.loggerRef can only be safely modified from within |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1057 |
// a lock on LoggerContext. removeLoggerRef is already |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1058 |
// synchronized on LoggerContext so calling |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1059 |
// n.context.removeLoggerRef from within this lock is safe. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1060 |
synchronized (n.context) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1061 |
// if we have a LogNode, then we were a named Logger |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1062 |
// so clear namedLoggers weak ref to us |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1063 |
n.context.removeLoggerRef(name, this); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1064 |
name = null; // clear our ref to the Logger's name |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1065 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1066 |
// LogNode may have been reused - so only clear |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1067 |
// LogNode.loggerRef if LogNode.loggerRef == this |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1068 |
if (n.loggerRef == this) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1069 |
n.loggerRef = null; // clear LogNode's weak ref to us |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1070 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1071 |
node = null; // clear our ref to LogNode |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1072 |
} |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1073 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1074 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1075 |
if (parentRef != null) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1076 |
// this LoggerWeakRef has or had a parent Logger |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1077 |
Logger parent = parentRef.get(); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1078 |
if (parent != null) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1079 |
// the parent Logger is still there so clear the |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1080 |
// parent Logger's weak ref to us |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1081 |
parent.removeChildLogger(this); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1082 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1083 |
parentRef = null; // clear our weak ref to the parent Logger |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1084 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1085 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1086 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1087 |
// set the node field to the specified value |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1088 |
void setNode(LogNode node) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1089 |
this.node = node; |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1090 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1091 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1092 |
// set the parentRef field to the specified value |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1093 |
void setParentRef(WeakReference<Logger> parentRef) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1094 |
this.parentRef = parentRef; |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1095 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1096 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1097 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1098 |
// Package-level method. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1099 |
// Drain some Logger objects that have been GC'ed. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1100 |
// |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1101 |
// drainLoggerRefQueueBounded() is called by addLogger() below |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1102 |
// and by Logger.getAnonymousLogger(String) so we'll drain up to |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1103 |
// MAX_ITERATIONS GC'ed Loggers for every Logger we add. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1104 |
// |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1105 |
// On a WinXP VMware client, a MAX_ITERATIONS value of 400 gives |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1106 |
// us about a 50/50 mix in increased weak ref counts versus |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1107 |
// decreased weak ref counts in the AnonLoggerWeakRefLeak test. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1108 |
// Here are stats for cleaning up sets of 400 anonymous Loggers: |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1109 |
// - test duration 1 minute |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1110 |
// - sample size of 125 sets of 400 |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1111 |
// - average: 1.99 ms |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1112 |
// - minimum: 0.57 ms |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1113 |
// - maximum: 25.3 ms |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1114 |
// |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1115 |
// The same config gives us a better decreased weak ref count |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1116 |
// than increased weak ref count in the LoggerWeakRefLeak test. |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1117 |
// Here are stats for cleaning up sets of 400 named Loggers: |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1118 |
// - test duration 2 minutes |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1119 |
// - sample size of 506 sets of 400 |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1120 |
// - average: 0.57 ms |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1121 |
// - minimum: 0.02 ms |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1122 |
// - maximum: 10.9 ms |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1123 |
// |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1124 |
private final static int MAX_ITERATIONS = 400; |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
21304
diff
changeset
|
1125 |
final void drainLoggerRefQueueBounded() { |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1126 |
for (int i = 0; i < MAX_ITERATIONS; i++) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1127 |
if (loggerRefQueue == null) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1128 |
// haven't finished loading LogManager yet |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1129 |
break; |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1130 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1131 |
|
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1132 |
LoggerWeakRef ref = (LoggerWeakRef) loggerRefQueue.poll(); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1133 |
if (ref == null) { |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1134 |
break; |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1135 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1136 |
// a Logger object has been GC'ed so clean it up |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1137 |
ref.dispose(); |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1138 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1139 |
} |
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1140 |
|
2 | 1141 |
/** |
1142 |
* Add a named logger. This does nothing and returns false if a logger |
|
1143 |
* with the same name is already registered. |
|
1144 |
* <p> |
|
1145 |
* The Logger factory methods call this method to register each |
|
1146 |
* newly created Logger. |
|
1147 |
* <p> |
|
1148 |
* The application should retain its own reference to the Logger |
|
1149 |
* object to avoid it being garbage collected. The LogManager |
|
1150 |
* may only retain a weak reference. |
|
1151 |
* |
|
1152 |
* @param logger the new logger. |
|
1153 |
* @return true if the argument logger was registered successfully, |
|
1154 |
* false if a logger of that name already exists. |
|
1155 |
* @exception NullPointerException if the logger name is null. |
|
1156 |
*/ |
|
16098 | 1157 |
public boolean addLogger(Logger logger) { |
2 | 1158 |
final String name = logger.getName(); |
1159 |
if (name == null) { |
|
1160 |
throw new NullPointerException(); |
|
1161 |
} |
|
17164 | 1162 |
drainLoggerRefQueueBounded(); |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1163 |
LoggerContext cx = getUserContext(); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1164 |
if (cx.addLocalLogger(logger)) { |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1165 |
// Do we have a per logger handler too? |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1166 |
// Note: this will add a 200ms penalty |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1167 |
loadLoggerHandlers(logger, name, name + ".handlers"); |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1168 |
return true; |
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1169 |
} else { |
16098 | 1170 |
return false; |
2 | 1171 |
} |
1172 |
} |
|
1173 |
||
1174 |
// Private method to set a level on a logger. |
|
1175 |
// If necessary, we raise privilege before doing the call. |
|
1176 |
private static void doSetLevel(final Logger logger, final Level level) { |
|
1177 |
SecurityManager sm = System.getSecurityManager(); |
|
1178 |
if (sm == null) { |
|
1179 |
// There is no security manager, so things are easy. |
|
1180 |
logger.setLevel(level); |
|
1181 |
return; |
|
1182 |
} |
|
1183 |
// There is a security manager. Raise privilege before |
|
1184 |
// calling setLevel. |
|
1185 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1186 |
@Override |
2 | 1187 |
public Object run() { |
1188 |
logger.setLevel(level); |
|
1189 |
return null; |
|
1190 |
}}); |
|
1191 |
} |
|
1192 |
||
1193 |
// Private method to set a parent on a logger. |
|
1194 |
// If necessary, we raise privilege before doing the setParent call. |
|
1195 |
private static void doSetParent(final Logger logger, final Logger parent) { |
|
1196 |
SecurityManager sm = System.getSecurityManager(); |
|
1197 |
if (sm == null) { |
|
1198 |
// There is no security manager, so things are easy. |
|
1199 |
logger.setParent(parent); |
|
1200 |
return; |
|
1201 |
} |
|
1202 |
// There is a security manager. Raise privilege before |
|
1203 |
// calling setParent. |
|
1204 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1205 |
@Override |
2 | 1206 |
public Object run() { |
1207 |
logger.setParent(parent); |
|
1208 |
return null; |
|
1209 |
}}); |
|
1210 |
} |
|
1211 |
||
1212 |
/** |
|
1213 |
* Method to find a named logger. |
|
1214 |
* <p> |
|
1215 |
* Note that since untrusted code may create loggers with |
|
1216 |
* arbitrary names this method should not be relied on to |
|
1217 |
* find Loggers for security sensitive logging. |
|
6675
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1218 |
* It is also important to note that the Logger associated with the |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1219 |
* String {@code name} may be garbage collected at any time if there |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1220 |
* is no strong reference to the Logger. The caller of this method |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1221 |
* must check the return value for null in order to properly handle |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1222 |
* the case where the Logger has been garbage collected. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1223 |
* |
2 | 1224 |
* @param name name of the logger |
1225 |
* @return matching logger or null if none is found |
|
1226 |
*/ |
|
16098 | 1227 |
public Logger getLogger(String name) { |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1228 |
return getUserContext().findLogger(name); |
2 | 1229 |
} |
1230 |
||
1231 |
/** |
|
1232 |
* Get an enumeration of known logger names. |
|
1233 |
* <p> |
|
1234 |
* Note: Loggers may be added dynamically as new classes are loaded. |
|
1235 |
* This method only reports on the loggers that are currently registered. |
|
6675
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1236 |
* It is also important to note that this method only returns the name |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1237 |
* of a Logger, not a strong reference to the Logger itself. |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1238 |
* The returned String does nothing to prevent the Logger from being |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1239 |
* garbage collected. In particular, if the returned name is passed |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1240 |
* to {@code LogManager.getLogger()}, then the caller must check the |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1241 |
* return value from {@code LogManager.getLogger()} for null to properly |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1242 |
* handle the case where the Logger has been garbage collected in the |
c86763d8f1c7
6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents:
5964
diff
changeset
|
1243 |
* time since its name was returned by this method. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23899
diff
changeset
|
1244 |
* |
2 | 1245 |
* @return enumeration of logger name strings |
1246 |
*/ |
|
16098 | 1247 |
public Enumeration<String> getLoggerNames() { |
16105
fe7392acb767
8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents:
16100
diff
changeset
|
1248 |
return getUserContext().getLoggerNames(); |
2 | 1249 |
} |
1250 |
||
1251 |
/** |
|
1252 |
* Reinitialize the logging properties and reread the logging configuration. |
|
1253 |
* <p> |
|
1254 |
* The same rules are used for locating the configuration properties |
|
1255 |
* as are used at startup. So normally the logging properties will |
|
1256 |
* be re-read from the same file that was used at startup. |
|
1257 |
* <P> |
|
1258 |
* Any log level definitions in the new configuration file will be |
|
1259 |
* applied using Logger.setLevel(), if the target Logger exists. |
|
1260 |
* <p> |
|
26859
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1261 |
* Any {@linkplain #addConfigurationListener registered configuration |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1262 |
* listener} will be invoked after the properties are read. |
2 | 1263 |
* |
1264 |
* @exception SecurityException if a security manager exists and if |
|
1265 |
* the caller does not have LoggingPermission("control"). |
|
1266 |
* @exception IOException if there are IO problems reading the configuration. |
|
1267 |
*/ |
|
1268 |
public void readConfiguration() throws IOException, SecurityException { |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1269 |
checkPermission(); |
2 | 1270 |
|
1271 |
// if a configuration class is specified, load it and use it. |
|
1272 |
String cname = System.getProperty("java.util.logging.config.class"); |
|
1273 |
if (cname != null) { |
|
1274 |
try { |
|
1275 |
// Instantiate the named class. It is its constructor's |
|
1276 |
// responsibility to initialize the logging configuration, by |
|
1277 |
// calling readConfiguration(InputStream) with a suitable stream. |
|
1278 |
try { |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9700
diff
changeset
|
1279 |
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname); |
2 | 1280 |
clz.newInstance(); |
1281 |
return; |
|
1282 |
} catch (ClassNotFoundException ex) { |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9700
diff
changeset
|
1283 |
Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(cname); |
2 | 1284 |
clz.newInstance(); |
1285 |
return; |
|
1286 |
} |
|
1287 |
} catch (Exception ex) { |
|
1288 |
System.err.println("Logging configuration class \"" + cname + "\" failed"); |
|
1289 |
System.err.println("" + ex); |
|
1290 |
// keep going and useful config file. |
|
1291 |
} |
|
1292 |
} |
|
1293 |
||
1294 |
String fname = System.getProperty("java.util.logging.config.file"); |
|
1295 |
if (fname == null) { |
|
1296 |
fname = System.getProperty("java.home"); |
|
1297 |
if (fname == null) { |
|
1298 |
throw new Error("Can't find java.home ??"); |
|
1299 |
} |
|
27565 | 1300 |
File f = new File(fname, "conf"); |
2 | 1301 |
f = new File(f, "logging.properties"); |
1302 |
fname = f.getCanonicalPath(); |
|
1303 |
} |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1304 |
try (final InputStream in = new FileInputStream(fname)) { |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1305 |
final BufferedInputStream bin = new BufferedInputStream(in); |
2 | 1306 |
readConfiguration(bin); |
1307 |
} |
|
1308 |
} |
|
1309 |
||
1310 |
/** |
|
1311 |
* Reset the logging configuration. |
|
1312 |
* <p> |
|
1313 |
* For all named loggers, the reset operation removes and closes |
|
1314 |
* all Handlers and (except for the root logger) sets the level |
|
1315 |
* to null. The root logger's level is set to Level.INFO. |
|
1316 |
* |
|
1317 |
* @exception SecurityException if a security manager exists and if |
|
1318 |
* the caller does not have LoggingPermission("control"). |
|
1319 |
*/ |
|
1320 |
||
1321 |
public void reset() throws SecurityException { |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1322 |
checkPermission(); |
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1323 |
|
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
1324 |
List<CloseOnReset> persistent; |
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1325 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1326 |
// We don't want reset() and readConfiguration() |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1327 |
// to run in parallel |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1328 |
configurationLock.lock(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1329 |
try { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1330 |
// install new empty properties |
2 | 1331 |
props = new Properties(); |
27754
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
1332 |
// make sure we keep the loggers persistent until reset is done. |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
1333 |
// Those are the loggers for which we previously created a |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
1334 |
// handler from the configuration, and we need to prevent them |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
1335 |
// from being gc'ed until those handlers are closed. |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
1336 |
persistent = new ArrayList<>(closeOnResetLoggers); |
ee2f7768e1c9
8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents:
27191
diff
changeset
|
1337 |
closeOnResetLoggers.clear(); |
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1338 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1339 |
// if reset has been called from shutdown-hook (Cleaner), |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1340 |
// or if reset has been called from readConfiguration() which |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1341 |
// already holds the lock and will change the state itself, |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1342 |
// then do not change state here... |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1343 |
if (globalHandlersState != STATE_SHUTDOWN && |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1344 |
globalHandlersState != STATE_READING_CONFIG) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1345 |
// ...else user called reset()... |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1346 |
// Since we are doing a reset we no longer want to initialize |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1347 |
// the global handlers, if they haven't been initialized yet. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1348 |
globalHandlersState = STATE_INITIALIZED; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1349 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1350 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1351 |
for (LoggerContext cx : contexts()) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1352 |
resetLoggerContext(cx); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1353 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1354 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1355 |
persistent.clear(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1356 |
} finally { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1357 |
configurationLock.unlock(); |
2 | 1358 |
} |
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1359 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1360 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1361 |
private void resetLoggerContext(LoggerContext cx) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1362 |
Enumeration<String> enum_ = cx.getLoggerNames(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1363 |
while (enum_.hasMoreElements()) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1364 |
String name = enum_.nextElement(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1365 |
Logger logger = cx.findLogger(name); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1366 |
if (logger != null) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1367 |
resetLogger(logger); |
16098 | 1368 |
} |
2 | 1369 |
} |
1370 |
} |
|
1371 |
||
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1372 |
private void closeHandlers(Logger logger) { |
2 | 1373 |
Handler[] targets = logger.getHandlers(); |
22078
bdec5d53e98c
8030851: Update code in java.util to use newer language features
psandoz
parents:
22046
diff
changeset
|
1374 |
for (Handler h : targets) { |
2 | 1375 |
logger.removeHandler(h); |
1376 |
try { |
|
1377 |
h.close(); |
|
1378 |
} catch (Exception ex) { |
|
1379 |
// Problems closing a handler? Keep going... |
|
1380 |
} |
|
1381 |
} |
|
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1382 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1383 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1384 |
// Private method to reset an individual target logger. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1385 |
private void resetLogger(Logger logger) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1386 |
// Close all the Logger handlers. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1387 |
closeHandlers(logger); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1388 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1389 |
// Reset Logger level |
16098 | 1390 |
String name = logger.getName(); |
2 | 1391 |
if (name != null && name.equals("")) { |
1392 |
// This is the root logger. |
|
1393 |
logger.setLevel(defaultLevel); |
|
1394 |
} else { |
|
1395 |
logger.setLevel(null); |
|
1396 |
} |
|
1397 |
} |
|
1398 |
||
1399 |
// get a list of whitespace separated classnames from a property. |
|
1400 |
private String[] parseClassNames(String propertyName) { |
|
1401 |
String hands = getProperty(propertyName); |
|
1402 |
if (hands == null) { |
|
1403 |
return new String[0]; |
|
1404 |
} |
|
1405 |
hands = hands.trim(); |
|
1406 |
int ix = 0; |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1407 |
final List<String> result = new ArrayList<>(); |
2 | 1408 |
while (ix < hands.length()) { |
1409 |
int end = ix; |
|
1410 |
while (end < hands.length()) { |
|
1411 |
if (Character.isWhitespace(hands.charAt(end))) { |
|
1412 |
break; |
|
1413 |
} |
|
1414 |
if (hands.charAt(end) == ',') { |
|
1415 |
break; |
|
1416 |
} |
|
1417 |
end++; |
|
1418 |
} |
|
1419 |
String word = hands.substring(ix, end); |
|
1420 |
ix = end+1; |
|
1421 |
word = word.trim(); |
|
1422 |
if (word.length() == 0) { |
|
1423 |
continue; |
|
1424 |
} |
|
1425 |
result.add(word); |
|
1426 |
} |
|
1427 |
return result.toArray(new String[result.size()]); |
|
1428 |
} |
|
1429 |
||
1430 |
/** |
|
1431 |
* Reinitialize the logging properties and reread the logging configuration |
|
1432 |
* from the given stream, which should be in java.util.Properties format. |
|
26859
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1433 |
* Any {@linkplain #addConfigurationListener registered configuration |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1434 |
* listener} will be invoked after the properties are read. |
2 | 1435 |
* <p> |
1436 |
* Any log level definitions in the new configuration file will be |
|
1437 |
* applied using Logger.setLevel(), if the target Logger exists. |
|
1438 |
* |
|
1439 |
* @param ins stream to read properties from |
|
1440 |
* @exception SecurityException if a security manager exists and if |
|
1441 |
* the caller does not have LoggingPermission("control"). |
|
1442 |
* @exception IOException if there are problems reading from the stream. |
|
1443 |
*/ |
|
1444 |
public void readConfiguration(InputStream ins) throws IOException, SecurityException { |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1445 |
checkPermission(); |
2 | 1446 |
|
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1447 |
// We don't want reset() and readConfiguration() to run |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1448 |
// in parallel. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1449 |
configurationLock.lock(); |
29739
3966f5f6a6fd
8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
27932
diff
changeset
|
1450 |
try { |
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1451 |
if (globalHandlersState == STATE_SHUTDOWN) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1452 |
// already in terminal state: don't even bother |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1453 |
// to read the configuration |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1454 |
return; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1455 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1456 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1457 |
// change state to STATE_READING_CONFIG to signal reset() to not change it |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1458 |
globalHandlersState = STATE_READING_CONFIG; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1459 |
try { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1460 |
// reset configuration which leaves globalHandlersState at STATE_READING_CONFIG |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1461 |
// so that while reading configuration, any ongoing logging requests block and |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1462 |
// wait for the outcome (see the end of this try statement) |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1463 |
reset(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1464 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1465 |
try { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1466 |
// Load the properties |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1467 |
props.load(ins); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1468 |
} catch (IllegalArgumentException x) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1469 |
// props.load may throw an IllegalArgumentException if the stream |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1470 |
// contains malformed Unicode escape sequences. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1471 |
// We wrap that in an IOException as readConfiguration is |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1472 |
// specified to throw IOException if there are problems reading |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1473 |
// from the stream. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1474 |
// Note: new IOException(x.getMessage(), x) allow us to get a more |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1475 |
// concise error message than new IOException(x); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1476 |
throw new IOException(x.getMessage(), x); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1477 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1478 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1479 |
// Instantiate new configuration objects. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1480 |
String names[] = parseClassNames("config"); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1481 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1482 |
for (String word : names) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1483 |
try { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1484 |
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(word); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1485 |
clz.newInstance(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1486 |
} catch (Exception ex) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1487 |
System.err.println("Can't load config class \"" + word + "\""); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1488 |
System.err.println("" + ex); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1489 |
// ex.printStackTrace(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1490 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1491 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1492 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1493 |
// Set levels on any pre-existing loggers, based on the new properties. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1494 |
setLevelsOnExistingLoggers(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1495 |
|
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1496 |
// Note that we need to reinitialize global handles when |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1497 |
// they are first referenced. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1498 |
globalHandlersState = STATE_UNINITIALIZED; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1499 |
} catch (Throwable t) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1500 |
// If there were any trouble, then set state to STATE_INITIALIZED |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1501 |
// so that no global handlers reinitialization is performed on not fully |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1502 |
// initialized configuration. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1503 |
globalHandlersState = STATE_INITIALIZED; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1504 |
// re-throw |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1505 |
throw t; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1506 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1507 |
} finally { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1508 |
configurationLock.unlock(); |
29739
3966f5f6a6fd
8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
27932
diff
changeset
|
1509 |
} |
3966f5f6a6fd
8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
27932
diff
changeset
|
1510 |
|
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1511 |
// should be called out of lock to avoid dead-lock situations |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1512 |
// when user code is involved |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1513 |
invokeConfigurationListeners(); |
2 | 1514 |
} |
1515 |
||
1516 |
/** |
|
1517 |
* Get the value of a logging property. |
|
1518 |
* The method returns null if the property is not found. |
|
1519 |
* @param name property name |
|
1520 |
* @return property value |
|
1521 |
*/ |
|
1522 |
public String getProperty(String name) { |
|
1523 |
return props.getProperty(name); |
|
1524 |
} |
|
1525 |
||
1526 |
// Package private method to get a String property. |
|
1527 |
// If the property is not defined we return the given |
|
1528 |
// default value. |
|
1529 |
String getStringProperty(String name, String defaultValue) { |
|
1530 |
String val = getProperty(name); |
|
1531 |
if (val == null) { |
|
1532 |
return defaultValue; |
|
1533 |
} |
|
1534 |
return val.trim(); |
|
1535 |
} |
|
1536 |
||
1537 |
// Package private method to get an integer property. |
|
1538 |
// If the property is not defined or cannot be parsed |
|
1539 |
// we return the given default value. |
|
1540 |
int getIntProperty(String name, int defaultValue) { |
|
1541 |
String val = getProperty(name); |
|
1542 |
if (val == null) { |
|
1543 |
return defaultValue; |
|
1544 |
} |
|
1545 |
try { |
|
1546 |
return Integer.parseInt(val.trim()); |
|
1547 |
} catch (Exception ex) { |
|
1548 |
return defaultValue; |
|
1549 |
} |
|
1550 |
} |
|
1551 |
||
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1552 |
// Package private method to get a long property. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1553 |
// If the property is not defined or cannot be parsed |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1554 |
// we return the given default value. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1555 |
long getLongProperty(String name, long defaultValue) { |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1556 |
String val = getProperty(name); |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1557 |
if (val == null) { |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1558 |
return defaultValue; |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1559 |
} |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1560 |
try { |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1561 |
return Long.parseLong(val.trim()); |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1562 |
} catch (Exception ex) { |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1563 |
return defaultValue; |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1564 |
} |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1565 |
} |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26859
diff
changeset
|
1566 |
|
2 | 1567 |
// Package private method to get a boolean property. |
1568 |
// If the property is not defined or cannot be parsed |
|
1569 |
// we return the given default value. |
|
1570 |
boolean getBooleanProperty(String name, boolean defaultValue) { |
|
1571 |
String val = getProperty(name); |
|
1572 |
if (val == null) { |
|
1573 |
return defaultValue; |
|
1574 |
} |
|
1575 |
val = val.toLowerCase(); |
|
1576 |
if (val.equals("true") || val.equals("1")) { |
|
1577 |
return true; |
|
1578 |
} else if (val.equals("false") || val.equals("0")) { |
|
1579 |
return false; |
|
1580 |
} |
|
1581 |
return defaultValue; |
|
1582 |
} |
|
1583 |
||
1584 |
// Package private method to get a Level property. |
|
1585 |
// If the property is not defined or cannot be parsed |
|
1586 |
// we return the given default value. |
|
1587 |
Level getLevelProperty(String name, Level defaultValue) { |
|
1588 |
String val = getProperty(name); |
|
1589 |
if (val == null) { |
|
1590 |
return defaultValue; |
|
1591 |
} |
|
16098 | 1592 |
Level l = Level.findLevel(val.trim()); |
1593 |
return l != null ? l : defaultValue; |
|
2 | 1594 |
} |
1595 |
||
1596 |
// Package private method to get a filter property. |
|
1597 |
// We return an instance of the class named by the "name" |
|
1598 |
// property. If the property is not defined or has problems |
|
1599 |
// we return the defaultValue. |
|
1600 |
Filter getFilterProperty(String name, Filter defaultValue) { |
|
1601 |
String val = getProperty(name); |
|
1602 |
try { |
|
1603 |
if (val != null) { |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9700
diff
changeset
|
1604 |
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val); |
2 | 1605 |
return (Filter) clz.newInstance(); |
1606 |
} |
|
1607 |
} catch (Exception ex) { |
|
1608 |
// We got one of a variety of exceptions in creating the |
|
1609 |
// class or creating an instance. |
|
1610 |
// Drop through. |
|
1611 |
} |
|
1612 |
// We got an exception. Return the defaultValue. |
|
1613 |
return defaultValue; |
|
1614 |
} |
|
1615 |
||
1616 |
||
1617 |
// Package private method to get a formatter property. |
|
1618 |
// We return an instance of the class named by the "name" |
|
1619 |
// property. If the property is not defined or has problems |
|
1620 |
// we return the defaultValue. |
|
1621 |
Formatter getFormatterProperty(String name, Formatter defaultValue) { |
|
1622 |
String val = getProperty(name); |
|
1623 |
try { |
|
1624 |
if (val != null) { |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9700
diff
changeset
|
1625 |
Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val); |
2 | 1626 |
return (Formatter) clz.newInstance(); |
1627 |
} |
|
1628 |
} catch (Exception ex) { |
|
1629 |
// We got one of a variety of exceptions in creating the |
|
1630 |
// class or creating an instance. |
|
1631 |
// Drop through. |
|
1632 |
} |
|
1633 |
// We got an exception. Return the defaultValue. |
|
1634 |
return defaultValue; |
|
1635 |
} |
|
1636 |
||
1637 |
// Private method to load the global handlers. |
|
1638 |
// We do the real work lazily, when the global handlers |
|
1639 |
// are first used. |
|
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1640 |
private void initializeGlobalHandlers() { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1641 |
int state = globalHandlersState; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1642 |
if (state == STATE_INITIALIZED || |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1643 |
state == STATE_SHUTDOWN) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1644 |
// Nothing to do: return. |
2 | 1645 |
return; |
1646 |
} |
|
1647 |
||
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1648 |
// If we have not initialized global handlers yet (or need to |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1649 |
// reinitialize them), lets do it now (this case is indicated by |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1650 |
// globalHandlersState == STATE_UNINITIALIZED). |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1651 |
// If we are in the process of initializing global handlers we |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1652 |
// also need to lock & wait (this case is indicated by |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1653 |
// globalHandlersState == STATE_INITIALIZING). |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1654 |
// If we are in the process of reading configuration we also need to |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1655 |
// wait to see what the outcome will be (this case |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1656 |
// is indicated by globalHandlersState == STATE_READING_CONFIG) |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1657 |
// So in either case we need to wait for the lock. |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1658 |
configurationLock.lock(); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1659 |
try { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1660 |
if (globalHandlersState != STATE_UNINITIALIZED) { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1661 |
return; // recursive call or nothing to do |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1662 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1663 |
// set globalHandlersState to STATE_INITIALIZING first to avoid |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1664 |
// getting an infinite recursion when loadLoggerHandlers(...) |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1665 |
// is going to call addHandler(...) |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1666 |
globalHandlersState = STATE_INITIALIZING; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1667 |
try { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1668 |
loadLoggerHandlers(rootLogger, null, "handlers"); |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1669 |
} finally { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1670 |
globalHandlersState = STATE_INITIALIZED; |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1671 |
} |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1672 |
} finally { |
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1673 |
configurationLock.unlock(); |
2 | 1674 |
} |
1675 |
} |
|
1676 |
||
22110
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
22086
diff
changeset
|
1677 |
static final Permission controlPermission = new LoggingPermission("control", null); |
2 | 1678 |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1679 |
void checkPermission() { |
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1680 |
SecurityManager sm = System.getSecurityManager(); |
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1681 |
if (sm != null) |
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1682 |
sm.checkPermission(controlPermission); |
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1683 |
} |
2 | 1684 |
|
1685 |
/** |
|
1686 |
* Check that the current context is trusted to modify the logging |
|
1687 |
* configuration. This requires LoggingPermission("control"). |
|
1688 |
* <p> |
|
1689 |
* If the check fails we throw a SecurityException, otherwise |
|
1690 |
* we return normally. |
|
1691 |
* |
|
1692 |
* @exception SecurityException if a security manager exists and if |
|
1693 |
* the caller does not have LoggingPermission("control"). |
|
1694 |
*/ |
|
1695 |
public void checkAccess() throws SecurityException { |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
13578
diff
changeset
|
1696 |
checkPermission(); |
2 | 1697 |
} |
1698 |
||
1699 |
// Nested class to represent a node in our tree of named loggers. |
|
1700 |
private static class LogNode { |
|
1701 |
HashMap<String,LogNode> children; |
|
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1702 |
LoggerWeakRef loggerRef; |
2 | 1703 |
LogNode parent; |
16098 | 1704 |
final LoggerContext context; |
2 | 1705 |
|
16098 | 1706 |
LogNode(LogNode parent, LoggerContext context) { |
2 | 1707 |
this.parent = parent; |
16098 | 1708 |
this.context = context; |
2 | 1709 |
} |
1710 |
||
1711 |
// Recursive method to walk the tree below a node and set |
|
1712 |
// a new parent logger. |
|
1713 |
void walkAndSetParent(Logger parent) { |
|
1714 |
if (children == null) { |
|
1715 |
return; |
|
1716 |
} |
|
22078
bdec5d53e98c
8030851: Update code in java.util to use newer language features
psandoz
parents:
22046
diff
changeset
|
1717 |
for (LogNode node : children.values()) { |
5964
0496aa46ae9f
6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents:
5506
diff
changeset
|
1718 |
LoggerWeakRef ref = node.loggerRef; |
2 | 1719 |
Logger logger = (ref == null) ? null : ref.get(); |
1720 |
if (logger == null) { |
|
1721 |
node.walkAndSetParent(parent); |
|
1722 |
} else { |
|
1723 |
doSetParent(logger, parent); |
|
1724 |
} |
|
1725 |
} |
|
1726 |
} |
|
1727 |
} |
|
1728 |
||
1729 |
// We use a subclass of Logger for the root logger, so |
|
1730 |
// that we only instantiate the global handlers when they |
|
1731 |
// are first needed. |
|
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1732 |
private final class RootLogger extends Logger { |
2 | 1733 |
private RootLogger() { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1734 |
// We do not call the protected Logger two args constructor here, |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1735 |
// to avoid calling LogManager.getLogManager() from within the |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1736 |
// RootLogger constructor. |
23899 | 1737 |
super("", null, null, LogManager.this, true); |
2 | 1738 |
} |
1739 |
||
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1740 |
@Override |
2 | 1741 |
public void log(LogRecord record) { |
1742 |
// Make sure that the global handlers have been instantiated. |
|
1743 |
initializeGlobalHandlers(); |
|
1744 |
super.log(record); |
|
1745 |
} |
|
1746 |
||
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1747 |
@Override |
2 | 1748 |
public void addHandler(Handler h) { |
1749 |
initializeGlobalHandlers(); |
|
1750 |
super.addHandler(h); |
|
1751 |
} |
|
1752 |
||
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1753 |
@Override |
2 | 1754 |
public void removeHandler(Handler h) { |
1755 |
initializeGlobalHandlers(); |
|
1756 |
super.removeHandler(h); |
|
1757 |
} |
|
1758 |
||
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
19809
diff
changeset
|
1759 |
@Override |
23899 | 1760 |
Handler[] accessCheckedHandlers() { |
2 | 1761 |
initializeGlobalHandlers(); |
23899 | 1762 |
return super.accessCheckedHandlers(); |
2 | 1763 |
} |
1764 |
} |
|
1765 |
||
1766 |
||
1767 |
// Private method to be called when the configuration has |
|
1768 |
// changed to apply any level settings to any pre-existing loggers. |
|
30643
1fcf87dbdc3c
8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents:
29919
diff
changeset
|
1769 |
private void setLevelsOnExistingLoggers() { |
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9700
diff
changeset
|
1770 |
Enumeration<?> enum_ = props.propertyNames(); |
2 | 1771 |
while (enum_.hasMoreElements()) { |
1772 |
String key = (String)enum_.nextElement(); |
|
1773 |
if (!key.endsWith(".level")) { |
|
1774 |
// Not a level definition. |
|
1775 |
continue; |
|
1776 |
} |
|
1777 |
int ix = key.length() - 6; |
|
1778 |
String name = key.substring(0, ix); |
|
1779 |
Level level = getLevelProperty(key, null); |
|
1780 |
if (level == null) { |
|
1781 |
System.err.println("Bad level value for property: " + key); |
|
1782 |
continue; |
|
1783 |
} |
|
16098 | 1784 |
for (LoggerContext cx : contexts()) { |
1785 |
Logger l = cx.findLogger(name); |
|
1786 |
if (l == null) { |
|
1787 |
continue; |
|
1788 |
} |
|
1789 |
l.setLevel(level); |
|
2 | 1790 |
} |
1791 |
} |
|
1792 |
} |
|
1793 |
||
1794 |
// Management Support |
|
1795 |
private static LoggingMXBean loggingMXBean = null; |
|
1796 |
/** |
|
1797 |
* String representation of the |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1798 |
* {@link javax.management.ObjectName} for the management interface |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1799 |
* for the logging facility. |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1800 |
* |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1801 |
* @see java.lang.management.PlatformLoggingMXBean |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1802 |
* @see java.util.logging.LoggingMXBean |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1803 |
* |
2 | 1804 |
* @since 1.5 |
1805 |
*/ |
|
1806 |
public final static String LOGGING_MXBEAN_NAME |
|
1807 |
= "java.util.logging:type=Logging"; |
|
1808 |
||
1809 |
/** |
|
1810 |
* Returns <tt>LoggingMXBean</tt> for managing loggers. |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1811 |
* An alternative way to manage loggers is through the |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1812 |
* {@link java.lang.management.PlatformLoggingMXBean} interface |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1813 |
* that can be obtained by calling: |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3861
diff
changeset
|
1814 |
* <pre> |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1815 |
* PlatformLoggingMXBean logging = {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class) |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1816 |
* ManagementFactory.getPlatformMXBean}(PlatformLoggingMXBean.class); |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
3861
diff
changeset
|
1817 |
* </pre> |
2 | 1818 |
* |
1819 |
* @return a {@link LoggingMXBean} object. |
|
1820 |
* |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1821 |
* @see java.lang.management.PlatformLoggingMXBean |
2 | 1822 |
* @since 1.5 |
1823 |
*/ |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
7803
diff
changeset
|
1824 |
public static synchronized LoggingMXBean getLoggingMXBean() { |
2 | 1825 |
if (loggingMXBean == null) { |
1826 |
loggingMXBean = new Logging(); |
|
1827 |
} |
|
1828 |
return loggingMXBean; |
|
1829 |
} |
|
26859
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1830 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1831 |
/** |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1832 |
* Adds a configuration listener to be invoked each time the logging |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1833 |
* configuration is read. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1834 |
* If the listener is already registered the method does nothing. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1835 |
* <p> |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1836 |
* The listener is invoked with privileges that are restricted by the |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1837 |
* calling context of this method. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1838 |
* The order in which the listeners are invoked is unspecified. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1839 |
* <p> |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1840 |
* It is recommended that listeners do not throw errors or exceptions. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1841 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1842 |
* If a listener terminates with an uncaught error or exception then |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1843 |
* the first exception will be propagated to the caller of |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1844 |
* {@link #readConfiguration()} (or {@link #readConfiguration(java.io.InputStream)}) |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1845 |
* after all listeners have been invoked. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1846 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1847 |
* @implNote If more than one listener terminates with an uncaught error or |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1848 |
* exception, an implementation may record the additional errors or |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1849 |
* exceptions as {@linkplain Throwable#addSuppressed(java.lang.Throwable) |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1850 |
* suppressed exceptions}. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1851 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1852 |
* @param listener A configuration listener that will be invoked after the |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1853 |
* configuration changed. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1854 |
* @return This LogManager. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1855 |
* @throws SecurityException if a security manager exists and if the |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1856 |
* caller does not have LoggingPermission("control"). |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1857 |
* @throws NullPointerException if the listener is null. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1858 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1859 |
* @since 1.9 |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1860 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1861 |
public LogManager addConfigurationListener(Runnable listener) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1862 |
final Runnable r = Objects.requireNonNull(listener); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1863 |
checkPermission(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1864 |
final SecurityManager sm = System.getSecurityManager(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1865 |
final AccessControlContext acc = |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1866 |
sm == null ? null : AccessController.getContext(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1867 |
final PrivilegedAction<Void> pa = |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1868 |
acc == null ? null : () -> { r.run() ; return null; }; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1869 |
final Runnable pr = |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1870 |
acc == null ? r : () -> AccessController.doPrivileged(pa, acc); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1871 |
// Will do nothing if already registered. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1872 |
listeners.putIfAbsent(r, pr); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1873 |
return this; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1874 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1875 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1876 |
/** |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1877 |
* Removes a previously registered configuration listener. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1878 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1879 |
* Returns silently if the listener is not found. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1880 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1881 |
* @param listener the configuration listener to remove. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1882 |
* @throws NullPointerException if the listener is null. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1883 |
* @throws SecurityException if a security manager exists and if the |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1884 |
* caller does not have LoggingPermission("control"). |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1885 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1886 |
* @since 1.9 |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1887 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1888 |
public void removeConfigurationListener(Runnable listener) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1889 |
final Runnable key = Objects.requireNonNull(listener); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1890 |
checkPermission(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1891 |
listeners.remove(key); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1892 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1893 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1894 |
private void invokeConfigurationListeners() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1895 |
Throwable t = null; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1896 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1897 |
// We're using an IdentityHashMap because we want to compare |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1898 |
// keys using identity (==). |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1899 |
// We don't want to loop within a block synchronized on 'listeners' |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1900 |
// to avoid invoking listeners from yet another synchronized block. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1901 |
// So we're taking a snapshot of the values list to avoid the risk of |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1902 |
// ConcurrentModificationException while looping. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1903 |
// |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1904 |
for (Runnable c : listeners.values().toArray(new Runnable[0])) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1905 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1906 |
c.run(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1907 |
} catch (ThreadDeath death) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1908 |
throw death; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1909 |
} catch (Error | RuntimeException x) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1910 |
if (t == null) t = x; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1911 |
else t.addSuppressed(x); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1912 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1913 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1914 |
// Listeners are not supposed to throw exceptions, but if that |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1915 |
// happens, we will rethrow the first error or exception that is raised |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1916 |
// after all listeners have been invoked. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1917 |
if (t instanceof Error) throw (Error)t; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1918 |
if (t instanceof RuntimeException) throw (RuntimeException)t; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1919 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
25859
diff
changeset
|
1920 |
|
2 | 1921 |
} |