src/java.logging/share/classes/java/util/logging/LogManager.java
author rpatil
Wed, 26 Dec 2018 17:09:19 +0530
changeset 53120 de9fd809bb47
parent 52902 e3398b2e1ab0
child 54075 daec95ed6795
permissions -rw-r--r--
8214567: Use {@systemProperty} for definitions of system properties 8214569: Use {@systemProperty} for definitions of system properties Reviewed-by: lancea, mchung, alanb, naoto Contributed-by: Deepak kejriwal <deepak.kejriwal@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48674
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.logging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
    31
import java.lang.ref.ReferenceQueue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.ref.WeakReference;
29740
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
    33
import java.util.concurrent.ConcurrentHashMap;
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    34
import java.nio.file.Paths;
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;
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    37
import java.util.function.BiFunction;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    38
import java.util.function.Function;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    39
import java.util.function.Predicate;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    40
import java.util.stream.Collectors;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    41
import java.util.stream.Stream;
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 48674
diff changeset
    42
import jdk.internal.access.JavaAWTAccess;
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 48674
diff changeset
    43
import jdk.internal.access.SharedSecrets;
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
    44
import sun.util.logging.internal.LoggingProviderImpl;
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
    45
import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * There is a single global LogManager object that is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * maintain a set of shared state about Loggers and log services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * This LogManager object:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <li> Manages a hierarchical namespace of Logger objects.  All
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *      named Loggers are stored in this namespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <li> Manages a set of logging control properties.  These are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      simple key-value pairs that can be used by Handlers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      other logging objects to configure themselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * The global LogManager object can be retrieved using LogManager.getLogManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * The LogManager object is created during class initialization and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * cannot subsequently be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * At startup the LogManager class is located using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * java.util.logging.manager system property.
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    66
 *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    67
 * <h3>LogManager Configuration</h3>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    68
 *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    69
 * A LogManager initializes the logging configuration via
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    70
 * the {@link #readConfiguration()} method during LogManager initialization.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    71
 * By default, LogManager default configuration is used.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    72
 * The logging configuration read by LogManager must be in the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    73
 * {@linkplain Properties properties file} format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
14691
22056e110b04 8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents: 14342
diff changeset
    75
 * The LogManager defines two optional system properties that allow control over
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    76
 * the initial configuration, as specified in the {@link #readConfiguration()}
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    77
 * method:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <ul>
53120
de9fd809bb47 8214567: Use {@systemProperty} for definitions of system properties
rpatil
parents: 52902
diff changeset
    79
 * <li>{@systemProperty java.util.logging.config.class}
de9fd809bb47 8214567: Use {@systemProperty} for definitions of system properties
rpatil
parents: 52902
diff changeset
    80
 * <li>{@systemProperty java.util.logging.config.file}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * </ul>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    82
 * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    83
 * These two system properties may be specified on the command line to the "java"
14691
22056e110b04 8003949: LogManager, downgrade normative reference to ${java.home}/lib/logging.properties
alanb
parents: 14342
diff changeset
    84
 * command, or as system property definitions passed to JNI_CreateJavaVM.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    86
 * The {@linkplain Properties properties} for loggers and Handlers will have
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
    87
 * names starting with the dot-separated name for the handler or logger.<br>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * The global logging properties may include:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <li>A property "handlers".  This defines a whitespace or comma separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * list of class names for handler classes to load and register as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * handlers on the root Logger (the Logger named "").  Each class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * name must be for a Handler class which has a default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * Note that these Handlers may be created lazily, when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * first used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <li>A property "&lt;logger&gt;.handlers". This defines a whitespace or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * comma separated list of class names for handlers classes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * load and register as handlers to the specified logger. Each class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * name must be for a Handler class which has a default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Note that these Handlers may be created lazily, when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * first used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
27754
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   104
 * <li>A property "&lt;logger&gt;.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
   105
 * a boolean value. If "&lt;logger&gt;.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
   106
 * 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
   107
 * 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
   108
 * 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
   109
 * by explicitly setting "&lt;logger&gt;.handlers.ensureCloseOnReset=false" in
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   110
 * 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
   111
 * 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
   112
 * {@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
   113
 * 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
   114
 * 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
   115
 * collected.
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   116
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <li>A property "&lt;logger&gt;.useParentHandlers". This defines a boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * value. By default every logger calls its parent in addition to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * handling the logging message itself, this often result in messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * being handled by the root logger as well. When setting this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * to false a Handler needs to be configured for this logger otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * no logging messages are delivered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <li>A property "config".  This property is intended to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * arbitrary configuration code to be run.  The property defines a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * whitespace or comma separated list of class names.  A new instance will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * created for each named class.  The default constructor of each class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * may execute arbitrary code to update the logging configuration, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * setting logger levels, adding handlers, adding filters, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * Note that all classes loaded during LogManager configuration are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * first searched on the system class path before any user class path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * That includes the LogManager class, any config classes, and any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * handler classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * Loggers are organized into a naming hierarchy based on their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * dot separated names.  Thus "a.b.c" is a child of "a.b", but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * "a.b1" and a.b2" are peers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * All properties whose names end with ".level" are assumed to define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * log levels for Loggers.  Thus "foo.level" defines a log level for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * the logger called "foo" and (recursively) for any of its children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * in the naming hierarchy.  Log Levels are applied in the order they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * are defined in the properties file.  Thus level settings for child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * nodes in the tree should come after settings for their parents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * The property name ".level" can be used to set the level for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * root of the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * All methods on the LogManager object are multi-thread safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
public class LogManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    // The global LogManager object
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   157
    private static final LogManager manager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   159
    // 'props' is assigned within a lock but accessed without it.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   160
    // Declaring it volatile makes sure that another thread will not
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   161
    // be able to see a partially constructed 'props' object.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   162
    // (seeing a partially constructed 'props' object can result in
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   163
    // NPE being thrown in Hashtable.get(), because it leaves the door
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   164
    // open for props.getProperties() to be called before the construcor
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   165
    // of Hashtable is actually completed).
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   166
    private volatile Properties props = new Properties();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private final static Level defaultLevel = Level.INFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   169
    // LoggerContext for system loggers and user loggers
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   170
    private final LoggerContext systemContext = new SystemLoggerContext();
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   171
    private final LoggerContext userContext = new LoggerContext();
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   172
    // 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
   173
    // will see the new value once ensureLogManagerInitialized() has finished
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   174
    // executing.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   175
    private volatile Logger rootLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    // Have we done the primordial reading of the configuration file?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    // (Must be done after a suitable amount of java.lang.System
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    // initialization has been done)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private volatile boolean readPrimordialConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    // Have we initialized global (root) handlers yet?
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   181
    // This gets set to STATE_UNINITIALIZED in readConfiguration
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   182
    private static final int
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   183
            STATE_INITIALIZED = 0, // initial state
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   184
            STATE_INITIALIZING = 1,
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   185
            STATE_READING_CONFIG = 2,
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   186
            STATE_UNINITIALIZED = 3,
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   187
            STATE_SHUTDOWN = 4;    // terminal state
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   188
    private volatile int globalHandlersState; // = STATE_INITIALIZED;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   189
    // A concurrency lock for reset(), readConfiguration() and Cleaner.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
   190
    private final ReentrantLock configurationLock = new ReentrantLock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
27754
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   192
    // 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
   193
    // 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
   194
    // 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
   195
    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
   196
        private final Logger logger;
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   197
        private CloseOnReset(Logger ref) {
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   198
            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
   199
        }
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   200
        @Override
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   201
        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
   202
            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
   203
        }
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   204
        @Override
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   205
        public int hashCode() {
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   206
            return System.identityHashCode(logger);
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   207
        }
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   208
        public Logger get() {
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   209
            return 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 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
   212
            return new CloseOnReset(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
    }
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
   215
    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
   216
            new CopyOnWriteArrayList<>();
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
26859
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
   219
    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
   220
            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
   221
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    static {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   223
        manager = AccessController.doPrivileged(new PrivilegedAction<LogManager>() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   224
            @Override
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   225
            public LogManager run() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   226
                LogManager mgr = null;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   227
                String cname = null;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   228
                try {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   229
                    cname = System.getProperty("java.util.logging.manager");
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   230
                    if (cname != null) {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   231
                        try {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   232
                            @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   233
                            Object tmp = ClassLoader.getSystemClassLoader()
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   234
                                .loadClass(cname).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   235
                            mgr = (LogManager) tmp;
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   236
                        } catch (ClassNotFoundException ex) {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   237
                            @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   238
                            Object tmp = Thread.currentThread()
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   239
                                .getContextClassLoader().loadClass(cname).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   240
                            mgr = (LogManager) tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    }
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   243
                } catch (Exception ex) {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   244
                    System.err.println("Could not load Logmanager \"" + cname + "\"");
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   245
                    ex.printStackTrace();
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   246
                }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   247
                if (mgr == null) {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   248
                    mgr = new LogManager();
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   249
                }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   250
                return mgr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   252
            }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   253
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    // This private class is used as a shutdown hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    // It does a "reset" to close all open handlers.
37520
f308aaf25d07 8153158: Remove sun.misc.ManagedLocalsThread from java.logging
chegar
parents: 35302
diff changeset
   258
    private class Cleaner extends Thread {
2384
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents: 2
diff changeset
   259
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents: 2
diff changeset
   260
        private Cleaner() {
37520
f308aaf25d07 8153158: Remove sun.misc.ManagedLocalsThread from java.logging
chegar
parents: 35302
diff changeset
   261
            super(null, null, "Logging-Cleaner", 0, false);
2384
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            // This is to ensure the LogManager.<clinit> is completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // before synchronized block. Otherwise deadlocks are possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            LogManager mgr = manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            // Do a reset to close all active handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Protected constructor.  This is protected so that container applications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * (such as J2EE containers) can subclass the object.  It is non-public as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    protected LogManager() {
22321
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   294
        this(checkSubclassPermissions());
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   295
    }
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   296
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   297
    private LogManager(Void checked) {
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   298
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // Add a shutdown hook to close the global handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            Runtime.getRuntime().addShutdownHook(new Cleaner());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        } catch (IllegalStateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            // If the VM is already shutting down,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            // We do not need to register shutdownHook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
22321
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   308
    private static Void checkSubclassPermissions() {
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   309
        final SecurityManager sm = System.getSecurityManager();
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   310
        if (sm != null) {
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   311
            // These permission will be checked in the LogManager constructor,
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   312
            // in order to register the Cleaner() thread as a shutdown hook.
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   313
            // Check them here to avoid the penalty of constructing the object
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   314
            // etc...
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   315
            sm.checkPermission(new RuntimePermission("shutdownHooks"));
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   316
            sm.checkPermission(new RuntimePermission("setContextClassLoader"));
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   317
        }
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   318
        return null;
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   319
    }
37f8c8b6ef7a 8024867: Enhance logging start up
dfuchs
parents: 19825
diff changeset
   320
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
        //
32035
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   356
        configurationLock.lock();
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   357
        try {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   358
            // 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
   359
            // the process of initializing the LogManager in this thread.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   360
            // There has been a recursive call to ensureLogManagerInitialized().
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   361
            final boolean isRecursiveInitialization = (initializedCalled == true);
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   362
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   363
            assert initializedCalled || !initializationDone
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   364
                    : "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
   365
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   366
            if (isRecursiveInitialization || initializationDone) {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   367
                // If isRecursiveInitialization is true it means that we're
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   368
                // already in the process of initializing the LogManager in
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   369
                // this thread. There has been a recursive call to
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   370
                // ensureLogManagerInitialized(). We should not proceed as
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   371
                // it would lead to infinite recursion.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   372
                //
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   373
                // If initializationDone is true then it means the manager
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   374
                // has finished initializing; just return: we're done.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   375
                return;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   376
            }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   377
            // Calling addLogger below will in turn call requiresDefaultLogger()
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   378
            // which will call ensureLogManagerInitialized().
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   379
            // We use initializedCalled to break the recursion.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   380
            initializedCalled = true;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   381
            try {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   382
                AccessController.doPrivileged(new PrivilegedAction<Object>() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   383
                    @Override
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   384
                    public Object run() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   385
                        assert rootLogger == null;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   386
                        assert initializedCalled && !initializationDone;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   387
39634
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   388
                        // create root logger before reading primordial
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   389
                        // configuration - to ensure that it will be added
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   390
                        // before the global logger, and not after.
48221
0ba2a82e4755 8191033: Regression in logging.properties: specifying .handlers= for root logger (instead of handlers=) no longer works
dfuchs
parents: 47216
diff changeset
   391
                        final Logger root = owner.rootLogger = owner.new RootLogger();
39634
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   392
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   393
                        // Read configuration.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   394
                        owner.readPrimordialConfiguration();
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   395
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   396
                        // Create and retain Logger for the root of the namespace.
48221
0ba2a82e4755 8191033: Regression in logging.properties: specifying .handlers= for root logger (instead of handlers=) no longer works
dfuchs
parents: 47216
diff changeset
   397
                        owner.addLogger(root);
0ba2a82e4755 8191033: Regression in logging.properties: specifying .handlers= for root logger (instead of handlers=) no longer works
dfuchs
parents: 47216
diff changeset
   398
0ba2a82e4755 8191033: Regression in logging.properties: specifying .handlers= for root logger (instead of handlers=) no longer works
dfuchs
parents: 47216
diff changeset
   399
                        // Initialize level if not yet initialized
0ba2a82e4755 8191033: Regression in logging.properties: specifying .handlers= for root logger (instead of handlers=) no longer works
dfuchs
parents: 47216
diff changeset
   400
                        if (!root.isLevelInitialized()) {
0ba2a82e4755 8191033: Regression in logging.properties: specifying .handlers= for root logger (instead of handlers=) no longer works
dfuchs
parents: 47216
diff changeset
   401
                            root.setLevel(defaultLevel);
22086
866b0a7d0127 8030850: Setting .level=FINEST in logging configuration file doesn't work
dfuchs
parents: 22078
diff changeset
   402
                        }
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   403
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   404
                        // Adding the global Logger.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   405
                        // 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
   406
                        // subtle inter-dependency issues.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   407
                        @SuppressWarnings("deprecation")
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   408
                        final Logger global = Logger.global;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   409
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   410
                        // 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
   411
                        // global manager
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   412
                        owner.addLogger(global);
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   413
                        return null;
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
                });
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   416
            } finally {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   417
                initializationDone = true;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   418
            }
32035
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   419
        } finally {
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   420
            configurationLock.unlock();
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   421
        }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   422
    }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   423
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   424
    /**
18565
5025d43d3731 8019315: Fix doclint issues in java.util.logging
darcy
parents: 18269
diff changeset
   425
     * Returns the global LogManager object.
5025d43d3731 8019315: Fix doclint issues in java.util.logging
darcy
parents: 18269
diff changeset
   426
     * @return the global LogManager object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public static LogManager getLogManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if (manager != null) {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   430
            manager.ensureLogManagerInitialized();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
32035
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   435
    private void readPrimordialConfiguration() { // must be called while holding configurationLock
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (!readPrimordialConfiguration) {
32035
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   437
            // If System.in/out/err are null, it's a good
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   438
            // indication that we're still in the
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   439
            // bootstrapping phase
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   440
            if (System.out == null) {
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   441
                return;
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   442
            }
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   443
            readPrimordialConfiguration = true;
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   444
            try {
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   445
                readConfiguration();
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   446
32035
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   447
                // Platform loggers begin to delegate to java.util.logging.Logger
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
   448
                jdk.internal.logger.BootstrapLogger.redirectTemporaryLoggers();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
   449
32035
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   450
            } catch (Exception ex) {
073a449c007d 8132550: java/util/logging/LoggingDeadlock2.java times out
dfuchs
parents: 31150
diff changeset
   451
                assert false : "Exception raised while reading logging configuration: " + ex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
19809
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   456
    // LoggerContext maps from AppContext
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   457
    private WeakHashMap<Object, LoggerContext> contextsMap = null;
19809
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   458
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   459
    // Returns the LoggerContext for the user code (i.e. application or AppContext).
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   460
    // Loggers are isolated from each AppContext.
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   461
    private LoggerContext getUserContext() {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   462
        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
   463
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   464
        SecurityManager sm = System.getSecurityManager();
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   465
        JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   466
        if (sm != null && javaAwtAccess != null) {
19809
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   467
            // 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
   468
            final Object ecx = javaAwtAccess.getAppletContext();
654c0f23c1c0 8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents: 27799
diff changeset
   469
            if (ecx != null) {
654c0f23c1c0 8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents: 27799
diff changeset
   470
                synchronized (javaAwtAccess) {
654c0f23c1c0 8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents: 27799
diff changeset
   471
                    // find the AppContext of the applet code
654c0f23c1c0 8065991: LogManager unecessarily calls JavaAWTAccess from within a critical section
dfuchs
parents: 27799
diff changeset
   472
                    // 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
   473
                    if (contextsMap == null) {
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   474
                        contextsMap = new WeakHashMap<>();
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   475
                    }
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   476
                    context = contextsMap.get(ecx);
18202
e9a6d59491ab 8004584: Augment applet contextualization
leonidr
parents: 16117
diff changeset
   477
                    if (context == null) {
19809
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   478
                        // Create a new LoggerContext for the applet.
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   479
                        context = new LoggerContext();
19809
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   480
                        contextsMap.put(ecx, context);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   481
                    }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   482
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   483
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   484
        }
19809
dc0480c1b36c 8019853: Break logging and AWT circular dependency
dfuchs
parents: 18595
diff changeset
   485
        // for standalone app, return userContext
18202
e9a6d59491ab 8004584: Augment applet contextualization
leonidr
parents: 16117
diff changeset
   486
        return context != null ? context : userContext;
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   487
    }
9700
fdbacf68f185 7016208: 4/3 null sometimes returned by java.util.logging.Logger.getLogger(String name) in -server -Xcomp
dcubed
parents: 9013
diff changeset
   488
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   489
    // The system context.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   490
    final LoggerContext getSystemContext() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   491
        return systemContext;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   492
    }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   493
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   494
    private List<LoggerContext> contexts() {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   495
        List<LoggerContext> cxs = new ArrayList<>();
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   496
        cxs.add(getSystemContext());
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   497
        cxs.add(getUserContext());
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   498
        return cxs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   501
    // 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
   502
    // 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
   503
    // 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
   504
    // in the LogManager global namespace.
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   505
    // 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
   506
    // Synchronization is not required here. All synchronization for
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   507
    // 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
   508
    //
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   509
    // 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
   510
    // 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
   511
    // 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
   512
    // readConfiguration, and other methods.
17487
77566e5979d1 8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents: 17164
diff changeset
   513
    Logger demandLogger(String name, String resourceBundleName, Class<?> caller) {
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   514
        final Module module = caller == null ? null : caller.getModule();
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   515
        return demandLogger(name, resourceBundleName, module);
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   516
    }
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   517
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   518
    Logger demandLogger(String name, String resourceBundleName, Module module) {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   519
        Logger result = getLogger(name);
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   520
        if (result == null) {
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   521
            // only allocate the new logger once
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   522
            Logger newLogger = new Logger(name, resourceBundleName,
39634
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   523
                                          module, this, false);
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   524
            do {
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   525
                if (addLogger(newLogger)) {
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   526
                    // We successfully added the new Logger that we
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   527
                    // created above so return it without refetching.
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   528
                    return newLogger;
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   529
                }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   530
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   531
                // 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
   532
                // 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
   533
                // 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
   534
                // 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
   535
                // addLogger() returns a boolean instead of the Logger
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   536
                // reference itself. However, if the thread that created
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   537
                // 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
   538
                // 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
   539
                // 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
   540
                // 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
   541
                // we'll just loop around and try again.
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   542
                result = getLogger(name);
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   543
            } while (result == null);
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   544
        }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   545
        return result;
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   546
    }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   547
31150
2aa1d300cd75 8080933: LogManager.demandSystemLogger should accept a 'caller' argument.
dfuchs
parents: 30643
diff changeset
   548
    Logger demandSystemLogger(String name, String resourceBundleName, Class<?> caller) {
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   549
        final Module module = caller == null ? null : caller.getModule();
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   550
        return demandSystemLogger(name, resourceBundleName, module);
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   551
    }
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   552
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   553
    Logger demandSystemLogger(String name, String resourceBundleName, Module module) {
16111
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   554
        // Add a system logger in the system context's namespace
31150
2aa1d300cd75 8080933: LogManager.demandSystemLogger should accept a 'caller' argument.
dfuchs
parents: 30643
diff changeset
   555
        final Logger sysLogger = getSystemContext()
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   556
                .demandLogger(name, resourceBundleName, module);
16111
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   557
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   558
        // 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
   559
        // 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
   560
        // System loggers are visible to applications unless a logger of
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   561
        // the same name has been added.
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   562
        Logger logger;
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   563
        do {
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   564
            // First attempt to call addLogger instead of getLogger
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   565
            // This would avoid potential bug in custom LogManager.getLogger
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   566
            // implementation that adds a logger if does not exist
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   567
            if (addLogger(sysLogger)) {
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   568
                // successfully added the new system logger
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   569
                logger = sysLogger;
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   570
            } else {
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   571
                logger = getLogger(name);
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   572
            }
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   573
        } while (logger == null);
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   574
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   575
        // LogManager will set the sysLogger's handlers via LogManager.addLogger method.
39634
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   576
        if (logger != sysLogger) {
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   577
            // if logger already exists we merge the two logger configurations.
16111
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   578
            final Logger l = logger;
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   579
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   580
                @Override
16111
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   581
                public Void run() {
39634
812020bcb9f1 8159245: Loggers created by system classes are not initialized correctly when configured programmatically from application code.
dfuchs
parents: 38370
diff changeset
   582
                    l.mergeWithSystemLogger(sysLogger);
16111
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   583
                    return null;
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   584
                }
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   585
            });
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   586
        }
5c5fc1d5bb38 8007393: Possible race condition after JDK-6664509
mchung
parents: 16105
diff changeset
   587
        return sysLogger;
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   588
    }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   589
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   590
    // LoggerContext maintains the logger namespace per context.
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   591
    // 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
   592
    // 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
   593
    // 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
   594
    // 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
   595
    // 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
   596
    // added in the user context.
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   597
    class LoggerContext {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   598
        // 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
   599
        private final ConcurrentHashMap<String,LoggerWeakRef> namedLoggers =
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   600
                new ConcurrentHashMap<>();
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   601
        // Tree of named Loggers
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   602
        private final LogNode root;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   603
        private LoggerContext() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   604
            this.root = new LogNode(null, this);
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
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   607
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   608
        // Tells whether default loggers are required in this context.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   609
        // If true, the default loggers will be lazily added.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   610
        final boolean requiresDefaultLoggers() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   611
            final boolean requiresDefaultLoggers = (getOwner() == manager);
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   612
            if (requiresDefaultLoggers) {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   613
                getOwner().ensureLogManagerInitialized();
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   614
            }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   615
            return requiresDefaultLoggers;
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   616
        }
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   617
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   618
        // This context's LogManager.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   619
        final LogManager getOwner() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   620
            return LogManager.this;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   621
        }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   622
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   623
        // 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
   624
        // 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
   625
        // logger's tree.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   626
        final Logger getRootLogger() {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   627
            return getOwner().rootLogger;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   628
        }
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   629
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   630
        // The global logger, which if not null, and if
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   631
        // 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
   632
        // logger's tree.
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   633
        final Logger getGlobalLogger() {
23342
d7a41da68b85 8036916: Deprecation warnings in LogManager
dfuchs
parents: 22342
diff changeset
   634
            @SuppressWarnings("deprecation") // avoids initialization cycles.
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   635
            final Logger global = Logger.global;
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   636
            return global;
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   637
        }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   638
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   639
        Logger demandLogger(String name, String resourceBundleName, Module module) {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   640
            // 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
   641
            // 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
   642
            final LogManager owner = getOwner();
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   643
            return owner.demandLogger(name, resourceBundleName, module);
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   644
        }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   645
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   646
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   647
        // Due to subtle deadlock issues getUserContext() no longer
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   648
        // calls addLocalLogger(rootLogger);
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   649
        // 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
   650
        // Checks that the context is properly initialized
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   651
        // 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
   652
        // or getLoggerNames()
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   653
        //
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   654
        private void ensureInitialized() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   655
            if (requiresDefaultLoggers()) {
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   656
                // 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
   657
                ensureDefaultLogger(getRootLogger());
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   658
                ensureDefaultLogger(getGlobalLogger());
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   659
            }
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   660
        }
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   661
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   662
29740
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   663
        Logger findLogger(String name) {
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   664
            // Attempt to find logger without locking.
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   665
            LoggerWeakRef ref = namedLoggers.get(name);
29740
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   666
            Logger logger = ref == null ? null : ref.get();
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   667
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   668
            // 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
   669
            // if name is "" or "global" and logger is null
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   670
            // 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
   671
            // initialized.
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   672
            // 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
   673
            // fall through.
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   674
            if (logger != null || (ref == null && !name.isEmpty()
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   675
                    && !name.equals(Logger.GLOBAL_LOGGER_NAME))) {
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   676
                return logger;
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   677
            }
29740
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   678
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   679
            // 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
   680
            // "" or "global" and didn't find them.
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   681
            // Make sure context is initialized (has the default loggers),
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   682
            // 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
   683
            // 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
   684
            // a synchronized block.
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   685
            synchronized(this) {
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   686
                // ensure that this context is properly initialized before
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   687
                // looking for loggers.
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   688
                ensureInitialized();
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   689
                ref = namedLoggers.get(name);
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   690
                if (ref == null) {
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   691
                    return null;
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   692
                }
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   693
                logger = ref.get();
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   694
                if (logger == null) {
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   695
                    // The namedLoggers map holds stale weak reference
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   696
                    // to a logger which has been GC-ed.
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   697
                    ref.dispose();
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   698
                }
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   699
                return logger;
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   700
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   701
        }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   702
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   703
        // 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
   704
        // context.
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   705
        // 'logger' is the context that will be added.
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   706
        // 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
   707
        // before adding 'logger'.
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
        private void ensureAllDefaultLoggers(Logger logger) {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   710
            if (requiresDefaultLoggers()) {
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   711
                final String name = logger.getName();
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   712
                if (!name.isEmpty()) {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   713
                    ensureDefaultLogger(getRootLogger());
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   714
                    if (!Logger.GLOBAL_LOGGER_NAME.equals(name)) {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   715
                        ensureDefaultLogger(getGlobalLogger());
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   716
                    }
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   717
                }
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   718
            }
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   719
        }
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   720
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   721
        private void ensureDefaultLogger(Logger logger) {
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   722
            // 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
   723
            // to a LoggerContext.
18202
e9a6d59491ab 8004584: Augment applet contextualization
leonidr
parents: 16117
diff changeset
   724
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   725
            // 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
   726
            // 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
   727
            // or owner.rootLogger.
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   728
            if (!requiresDefaultLoggers() || logger == null
23342
d7a41da68b85 8036916: Deprecation warnings in LogManager
dfuchs
parents: 22342
diff changeset
   729
                    || logger != getGlobalLogger() && logger != LogManager.this.rootLogger ) {
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   730
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   731
                // 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
   732
                // Logger.global nor manager.rootLogger indicates a serious
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   733
                // issue - as ensureDefaultLogger should never be called
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   734
                // 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
   735
                // e.g manager.rootLogger is not yet initialized)...
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   736
                assert logger == null;
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   737
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   738
                return;
18202
e9a6d59491ab 8004584: Augment applet contextualization
leonidr
parents: 16117
diff changeset
   739
            }
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   740
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   741
            // 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
   742
            if (!namedLoggers.containsKey(logger.getName())) {
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   743
                // It is important to prevent addLocalLogger to
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   744
                // call ensureAllDefaultLoggers when we're in the process
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   745
                // 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
   746
                // immediately cause a stack overflow.
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   747
                // Therefore we must pass addDefaultLoggersIfNeeded=false,
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   748
                // even if requiresDefaultLoggers is true.
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   749
                addLocalLogger(logger, false);
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   750
            }
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   751
        }
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   752
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   753
        boolean addLocalLogger(Logger logger) {
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   754
            // 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
   755
            return addLocalLogger(logger, requiresDefaultLoggers());
18202
e9a6d59491ab 8004584: Augment applet contextualization
leonidr
parents: 16117
diff changeset
   756
        }
e9a6d59491ab 8004584: Augment applet contextualization
leonidr
parents: 16117
diff changeset
   757
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   758
        // 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
   759
        // 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
   760
        synchronized boolean addLocalLogger(Logger logger, boolean addDefaultLoggersIfNeeded) {
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   761
            // addDefaultLoggersIfNeeded serves to break recursion when adding
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   762
            // 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
   763
            // (we're being called from ensureDefaultLogger()) then
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   764
            // 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
   765
            // call ensureAllDefaultLoggers again.
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   766
            //
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   767
            // Note: addDefaultLoggersIfNeeded can also be false when
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   768
            //       requiresDefaultLoggers is false - since calling
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   769
            //       ensureAllDefaultLoggers would have no effect in this case.
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   770
            if (addDefaultLoggersIfNeeded) {
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   771
                ensureAllDefaultLoggers(logger);
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   772
            }
18202
e9a6d59491ab 8004584: Augment applet contextualization
leonidr
parents: 16117
diff changeset
   773
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   774
            final String name = logger.getName();
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   775
            if (name == null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   776
                throw new NullPointerException();
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   777
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   778
            LoggerWeakRef ref = namedLoggers.get(name);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   779
            if (ref != null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   780
                if (ref.get() == null) {
17164
1304199c8641 8010939: Deadlock in LogManager
jgish
parents: 16117
diff changeset
   781
                    // It's possible that the Logger was GC'ed after a
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   782
                    // drainLoggerRefQueueBounded() call above so allow
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   783
                    // a new one to be registered.
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   784
                    ref.dispose();
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   785
                } else {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   786
                    // We already have a registered logger with the given name.
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   787
                    return false;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   788
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   789
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   790
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   791
            // We're adding a new logger.
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   792
            // 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
   793
            final LogManager owner = getOwner();
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   794
            logger.setLogManager(owner);
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   795
            ref = owner.new LoggerWeakRef(logger);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   796
21304
7971ecf0fbed 8026499: Root Logger level can be reset unexpectedly
dfuchs
parents: 19825
diff changeset
   797
            // Apply any initial level defined for the new logger, unless
7971ecf0fbed 8026499: Root Logger level can be reset unexpectedly
dfuchs
parents: 19825
diff changeset
   798
            // the logger's level is already initialized
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   799
            Level level = owner.getLevelProperty(name + ".level", null);
21304
7971ecf0fbed 8026499: Root Logger level can be reset unexpectedly
dfuchs
parents: 19825
diff changeset
   800
            if (level != null && !logger.isLevelInitialized()) {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   801
                doSetLevel(logger, level);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   802
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   803
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   804
            // 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
   805
            // 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
   806
            // subclass for the custom log manager case
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   807
            processParentHandlers(logger, name, VisitedLoggers.NEVER);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   808
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   809
            // Find the new node and its parent.
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   810
            LogNode node = getNode(name);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   811
            node.loggerRef = ref;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   812
            Logger parent = null;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   813
            LogNode nodep = node.parent;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   814
            while (nodep != null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   815
                LoggerWeakRef nodeRef = nodep.loggerRef;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   816
                if (nodeRef != null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   817
                    parent = nodeRef.get();
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   818
                    if (parent != null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   819
                        break;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   820
                    }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   821
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   822
                nodep = nodep.parent;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   823
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   824
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   825
            if (parent != null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   826
                doSetParent(logger, parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            }
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   828
            // Walk over the children and tell them we are their new parent.
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   829
            node.walkAndSetParent(logger);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   830
            // new LogNode is ready so tell the LoggerWeakRef about it
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   831
            ref.setNode(node);
29740
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   832
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   833
            // 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
   834
            // 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
   835
            // soon as it is published in namedLoggers (findLogger takes
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   836
            // benefit of the ConcurrentHashMap implementation of namedLoggers
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   837
            // to avoid synchronizing on retrieval when that is possible).
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   838
            namedLoggers.put(name, ref);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   839
            return true;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   840
        }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   841
29740
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   842
        void removeLoggerRef(String name, LoggerWeakRef ref) {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
   843
            namedLoggers.remove(name, ref);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   844
        }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   845
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   846
        synchronized Enumeration<String> getLoggerNames() {
18593
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   847
            // ensure that this context is properly initialized before
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   848
            // returning logger names.
40715ebb6681 8017174: NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
dfuchs
parents: 18565
diff changeset
   849
            ensureInitialized();
29740
d9f64fdd3c97 7113878: LogManager - namedLoggers should be ConcurrentHashMap instead of Hashtable
dfuchs
parents: 29739
diff changeset
   850
            return Collections.enumeration(namedLoggers.keySet());
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   851
        }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   852
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   853
        // If logger.getUseParentHandlers() returns 'true' and any of the logger's
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   854
        // parents have levels or handlers defined, make sure they are instantiated.
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   855
        private void processParentHandlers(final Logger logger, final String name,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   856
               Predicate<Logger> visited) {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   857
            final LogManager owner = getOwner();
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   858
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   859
                @Override
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   860
                public Void run() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   861
                    if (logger != owner.rootLogger) {
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   862
                        boolean useParent = owner.getBooleanProperty(name + ".useParentHandlers", true);
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   863
                        if (!useParent) {
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   864
                            logger.setUseParentHandlers(false);
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   865
                        }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   866
                    }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   867
                    return null;
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   868
                }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   869
            });
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   870
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   871
            int ix = 1;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   872
            for (;;) {
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 24196
diff changeset
   873
                int ix2 = name.indexOf('.', ix);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   874
                if (ix2 < 0) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   875
                    break;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   876
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   877
                String pname = name.substring(0, ix2);
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   878
                if (owner.getProperty(pname + ".level") != null ||
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   879
                    owner.getProperty(pname + ".handlers") != null) {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   880
                    // This pname has a level/handlers definition.
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   881
                    // Make sure it exists.
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   882
                    if (visited.test(demandLogger(pname, null, null))) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   883
                        break;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   884
                    }
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   885
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   886
                ix = ix2+1;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   887
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   888
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   890
        // Gets a node in our tree of logger nodes.
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   891
        // If necessary, create it.
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   892
        LogNode getNode(String name) {
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 52427
diff changeset
   893
            if (name == null || name.isEmpty()) {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   894
                return root;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   895
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   896
            LogNode node = root;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   897
            while (name.length() > 0) {
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 24196
diff changeset
   898
                int ix = name.indexOf('.');
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   899
                String head;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   900
                if (ix > 0) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   901
                    head = name.substring(0, ix);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   902
                    name = name.substring(ix + 1);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   903
                } else {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   904
                    head = name;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   905
                    name = "";
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   906
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   907
                if (node.children == null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   908
                    node.children = new HashMap<>();
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   909
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   910
                LogNode child = node.children.get(head);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   911
                if (child == null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   912
                    child = new LogNode(node, this);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   913
                    node.children.put(head, child);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   914
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   915
                node = child;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            }
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   917
            return node;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   918
        }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   919
    }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   920
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   921
    final class SystemLoggerContext extends LoggerContext {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   922
        // 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
   923
        // 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
   924
        // 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
   925
        // 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
   926
        @Override
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   927
        Logger demandLogger(String name, String resourceBundleName,
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   928
                            Module module) {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   929
            Logger result = findLogger(name);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   930
            if (result == null) {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   931
                // only allocate the new system logger once
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   932
                Logger newLogger = new Logger(name, resourceBundleName,
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
   933
                                              module, getOwner(), true);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   934
                do {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   935
                    if (addLocalLogger(newLogger)) {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   936
                        // We successfully added the new Logger that we
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   937
                        // created above so return it without refetching.
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   938
                        result = newLogger;
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   939
                    } else {
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   940
                        // 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
   941
                        // 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
   942
                        // 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
   943
                        // 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
   944
                        // addLogger() returns a boolean instead of the Logger
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   945
                        // reference itself. However, if the thread that created
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   946
                        // 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
   947
                        // 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
   948
                        // 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
   949
                        // 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
   950
                        // we'll just loop around and try again.
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   951
                        result = findLogger(name);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   952
                    }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   953
                } while (result == null);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   954
            }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
   955
            return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    // Add new per logger handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    // We need to raise privilege here. All our decisions will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    // be made based on the logging configuration, which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    // only be modified by trusted code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    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
   964
                                    final String handlersPropertyName)
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   965
    {
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   966
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
   967
            @Override
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   968
            public Void run() {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   969
                setLoggerHandlers(logger, name, handlersPropertyName,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   970
                    createLoggerHandlers(name, handlersPropertyName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                return null;
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   972
            }
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
   973
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   976
    private void setLoggerHandlers(final Logger logger, final String name,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   977
                                   final String handlersPropertyName,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   978
                                   List<Handler> handlers)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   979
    {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   980
        final boolean ensureCloseOnReset = ! handlers.isEmpty()
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   981
                    && getBooleanProperty(handlersPropertyName + ".ensureCloseOnReset",true);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   982
        int count = 0;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   983
        for (Handler hdl : handlers) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   984
            logger.addHandler(hdl);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   985
            if (++count == 1 && ensureCloseOnReset) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   986
                // add this logger to the closeOnResetLoggers list.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   987
                closeOnResetLoggers.addIfAbsent(CloseOnReset.create(logger));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   988
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   989
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   990
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   991
48674
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
   992
    private List<Handler> createLoggerHandlers(final String name,
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
   993
                                               final String handlersPropertyName)
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   994
    {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   995
        String names[] = parseClassNames(handlersPropertyName);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   996
        List<Handler> handlers = new ArrayList<>(names.length);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   997
        for (String type : names) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
   998
            try {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
   999
                @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1000
                Object o = ClassLoader.getSystemClassLoader().loadClass(type).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1001
                Handler hdl = (Handler) o;
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1002
                // Check if there is a property defining the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1003
                // this handler's level.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1004
                String levs = getProperty(type + ".level");
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1005
                if (levs != null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1006
                    Level l = Level.findLevel(levs);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1007
                    if (l != null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1008
                        hdl.setLevel(l);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1009
                    } else {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1010
                        // Probably a bad level. Drop through.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1011
                        System.err.println("Can't set level for " + type);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1012
                    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1013
                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1014
                // Add this Handler to the logger
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1015
                handlers.add(hdl);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1016
            } catch (Exception ex) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1017
                System.err.println("Can't load log handler \"" + type + "\"");
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1018
                System.err.println("" + ex);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1019
                ex.printStackTrace();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1020
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1021
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1022
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1023
        return handlers;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1024
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1025
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1026
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1027
    // loggerRefQueue holds LoggerWeakRef objects for Logger objects
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1028
    // that have been GC'ed.
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1029
    private final ReferenceQueue<Logger> loggerRefQueue
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 6675
diff changeset
  1030
        = new ReferenceQueue<>();
5964
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
    // Package-level inner class.
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1033
    // 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
  1034
    //
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1035
    // LogManager.namedLoggers
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1036
    //     - has weak references to all named Loggers
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1037
    //     - 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
  1038
    //       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
  1039
    //       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
  1040
    // LogManager.LogNode.loggerRef
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1041
    //     - 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
  1042
    //     - 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
  1043
    //       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
  1044
    // Logger.kids
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1045
    //     - 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
  1046
    //       includes anonymous and named Loggers
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1047
    //     - 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
  1048
    //       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
  1049
    //       LoggerWeakRef objects for the anonymous Loggers around
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1050
    //       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
  1051
    //
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1052
    final class LoggerWeakRef extends WeakReference<Logger> {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1053
        private String                name;       // for namedLoggers cleanup
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1054
        private LogNode               node;       // for loggerRef cleanup
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1055
        private WeakReference<Logger> parentRef;  // for kids cleanup
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1056
        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
  1057
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1058
        LoggerWeakRef(Logger logger) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1059
            super(logger, loggerRefQueue);
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1060
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1061
            name = logger.getName();  // save for namedLoggers cleanup
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1062
        }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1063
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1064
        // dispose of this LoggerWeakRef object
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1065
        void dispose() {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1066
            // Avoid calling dispose twice. When a Logger is gc'ed, its
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1067
            // LoggerWeakRef will be enqueued.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1068
            // 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
  1069
            // up) before the queue is drained. When that happens, dispose()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1070
            // will be called by addLocalLogger() or findLogger().
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1071
            // Later when the queue is drained, dispose() will be called again
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1072
            // for the same LoggerWeakRef. Marking LoggerWeakRef as disposed
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1073
            // avoids processing the data twice (even though the code should
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1074
            // now be reentrant).
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1075
            synchronized(this) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1076
                // Note to maintainers:
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1077
                // Be careful not to call any method that tries to acquire
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1078
                // another lock from within this block - as this would surely
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1079
                // lead to deadlocks, given that dispose() can be called by
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1080
                // multiple threads, and from within different synchronized
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1081
                // methods/blocks.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1082
                if (disposed) return;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1083
                disposed = true;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1084
            }
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1085
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1086
            final LogNode n = node;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1087
            if (n != null) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1088
                // n.loggerRef can only be safely modified from within
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1089
                // a lock on LoggerContext. removeLoggerRef is already
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1090
                // synchronized on LoggerContext so calling
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1091
                // n.context.removeLoggerRef from within this lock is safe.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1092
                synchronized (n.context) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1093
                    // if we have a LogNode, then we were a named Logger
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1094
                    // so clear namedLoggers weak ref to us
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1095
                    n.context.removeLoggerRef(name, this);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1096
                    name = null;  // clear our ref to the Logger's name
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1097
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1098
                    // LogNode may have been reused - so only clear
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1099
                    // LogNode.loggerRef if LogNode.loggerRef == this
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1100
                    if (n.loggerRef == this) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1101
                        n.loggerRef = null;  // clear LogNode's weak ref to us
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1102
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1103
                    node = null;            // clear our ref to LogNode
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1104
                }
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1105
            }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1106
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1107
            if (parentRef != null) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1108
                // 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
  1109
                Logger parent = parentRef.get();
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1110
                if (parent != null) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1111
                    // 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
  1112
                    // parent Logger's weak ref to us
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1113
                    parent.removeChildLogger(this);
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
                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
  1116
            }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1117
        }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1118
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1119
        // 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
  1120
        void setNode(LogNode node) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1121
            this.node = node;
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1122
        }
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
        // 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
  1125
        void setParentRef(WeakReference<Logger> parentRef) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1126
            this.parentRef = parentRef;
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1127
        }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1128
    }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1129
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1130
    // Package-level method.
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1131
    // 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
  1132
    //
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1133
    // drainLoggerRefQueueBounded() is called by addLogger() below
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1134
    // 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
  1135
    // 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
  1136
    //
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1137
    // 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
  1138
    // 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
  1139
    // 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
  1140
    // 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
  1141
    //   - test duration 1 minute
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1142
    //   - sample size of 125 sets of 400
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1143
    //   - average: 1.99 ms
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1144
    //   - minimum: 0.57 ms
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1145
    //   - maximum: 25.3 ms
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1146
    //
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1147
    // 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
  1148
    // 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
  1149
    // 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
  1150
    //   - test duration 2 minutes
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1151
    //   - sample size of 506 sets of 400
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1152
    //   - average: 0.57 ms
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1153
    //   - minimum: 0.02 ms
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1154
    //   - maximum: 10.9 ms
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1155
    //
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1156
    private final static int MAX_ITERATIONS = 400;
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents: 21304
diff changeset
  1157
    final void drainLoggerRefQueueBounded() {
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1158
        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
  1159
            if (loggerRefQueue == null) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1160
                // haven't finished loading LogManager yet
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1161
                break;
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1162
            }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1163
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1164
            LoggerWeakRef ref = (LoggerWeakRef) loggerRefQueue.poll();
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1165
            if (ref == null) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1166
                break;
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1167
            }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1168
            // 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
  1169
            ref.dispose();
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1170
        }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1171
    }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1172
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * Add a named logger.  This does nothing and returns false if a logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * with the same name is already registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * The Logger factory methods call this method to register each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * newly created Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * The application should retain its own reference to the Logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * object to avoid it being garbage collected.  The LogManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * may only retain a weak reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * @param   logger the new logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @return  true if the argument logger was registered successfully,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *          false if a logger of that name already exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @exception NullPointerException if the logger name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     */
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  1189
    public boolean addLogger(Logger logger) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        final String name = logger.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        }
17164
1304199c8641 8010939: Deadlock in LogManager
jgish
parents: 16117
diff changeset
  1194
        drainLoggerRefQueueBounded();
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1195
        LoggerContext cx = getUserContext();
48674
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1196
        if (cx.addLocalLogger(logger) || forceLoadHandlers(logger)) {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1197
            // Do we have a per logger handler too?
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1198
            // Note: this will add a 200ms penalty
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1199
            loadLoggerHandlers(logger, name, name + ".handlers");
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1200
            return true;
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1201
        } else {
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  1202
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
48674
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1206
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1207
    // Checks whether the given logger is a special logger
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1208
    // that still requires handler initialization.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1209
    // This method will only return true for the root and
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1210
    // global loggers and only if called by the thread that
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1211
    // performs initialization of the LogManager, during that
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1212
    // initialization. Must only be called by addLogger.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1213
    @SuppressWarnings("deprecation")
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1214
    private boolean forceLoadHandlers(Logger logger) {
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1215
        // Called just after reading the primordial configuration, in
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1216
        // the same thread that reads it.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1217
        // The root and global logger would already be present in the context
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1218
        // by this point, but we would not have called loadLoggerHandlers
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1219
        // yet.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1220
        return (logger == rootLogger ||  logger == Logger.global)
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1221
                && !initializationDone
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1222
                && initializedCalled
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1223
                && configurationLock.isHeldByCurrentThread();
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1224
    }
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents: 48221
diff changeset
  1225
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    // Private method to set a level on a logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    // If necessary, we raise privilege before doing the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    private static void doSetLevel(final Logger logger, final Level level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        if (sm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            // There is no security manager, so things are easy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            logger.setLevel(level);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        // There is a security manager.  Raise privilege before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        // calling setLevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  1238
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                logger.setLevel(level);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    // Private method to set a parent on a logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    // If necessary, we raise privilege before doing the setParent call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    private static void doSetParent(final Logger logger, final Logger parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        if (sm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            // There is no security manager, so things are easy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            logger.setParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        // There is a security manager.  Raise privilege before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        // calling setParent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  1257
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                logger.setParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * Method to find a named logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * Note that since untrusted code may create loggers with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * arbitrary names this method should not be relied on to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * 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
  1270
     * 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
  1271
     * 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
  1272
     * 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
  1273
     * 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
  1274
     * 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
  1275
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * @param name name of the logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * @return  matching logger or null if none is found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     */
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  1279
    public Logger getLogger(String name) {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1280
        return getUserContext().findLogger(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * Get an enumeration of known logger names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * Note:  Loggers may be added dynamically as new classes are loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * 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
  1288
     * 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
  1289
     * 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
  1290
     * 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
  1291
     * 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
  1292
     * 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
  1293
     * 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
  1294
     * 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
  1295
     * 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
  1296
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * @return  enumeration of logger name strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     */
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  1299
    public Enumeration<String> getLoggerNames() {
16105
fe7392acb767 8005615: Java Logger fails to load tomcat logger implementation (JULI)
mchung
parents: 16100
diff changeset
  1300
        return getUserContext().getLoggerNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    /**
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1304
     * Reads and initializes the logging configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1305
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1306
     * If the "java.util.logging.config.class" system property is set, then the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1307
     * property value is treated as a class name.  The given class will be
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1308
     * loaded, an object will be instantiated, and that object's constructor
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1309
     * is responsible for reading in the initial configuration.  (That object
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1310
     * may use other system properties to control its configuration.)  The
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1311
     * alternate configuration class can use {@code readConfiguration(InputStream)}
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1312
     * to define properties in the LogManager.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * <p>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1314
     * If "java.util.logging.config.class" system property is <b>not</b> set,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1315
     * then this method will read the initial configuration from a properties
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1316
     * file and calls the {@link #readConfiguration(InputStream)} method to initialize
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1317
     * the configuration. The "java.util.logging.config.file" system property can be used
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1318
     * to specify the properties file that will be read as the initial configuration;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1319
     * if not set, then the LogManager default configuration is used.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1320
     * The default configuration is typically loaded from the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1321
     * properties file "{@code conf/logging.properties}" in the Java installation
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1322
     * directory.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1323
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * <p>
26859
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  1325
     * 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
  1326
     * listener} will be invoked after the properties are read.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     *
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1328
     * @apiNote This {@code readConfiguration} method should only be used for
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1329
     * initializing the configuration during LogManager initialization or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1330
     * used with the "java.util.logging.config.class" property.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1331
     * When this method is called after loggers have been created, and
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1332
     * the "java.util.logging.config.class" system property is not set, all
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1333
     * existing loggers will be {@linkplain #reset() reset}. Then any
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1334
     * existing loggers that have a level property specified in the new
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1335
     * configuration stream will be {@linkplain
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1336
     * Logger#setLevel(java.util.logging.Level) set} to the specified log level.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1337
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1338
     * To properly update the logging configuration, use the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1339
     * {@link #updateConfiguration(java.util.function.Function)} or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1340
     * {@link #updateConfiguration(java.io.InputStream, java.util.function.Function)}
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1341
     * methods instead.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1342
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1343
     * @throws   SecurityException  if a security manager exists and if
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1344
     *              the caller does not have LoggingPermission("control").
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1345
     * @throws   IOException if there are IO problems reading the configuration.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    public void readConfiguration() throws IOException, SecurityException {
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  1348
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        // if a configuration class is specified, load it and use it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        String cname = System.getProperty("java.util.logging.config.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                // Instantiate the named class.  It is its constructor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                // responsibility to initialize the logging configuration, by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                // calling readConfiguration(InputStream) with a suitable stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                try {
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9700
diff changeset
  1358
                    Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1359
                    @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1360
                    Object witness = clz.newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                } catch (ClassNotFoundException ex) {
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9700
diff changeset
  1363
                    Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1364
                    @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1365
                    Object witness = clz.newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                System.err.println("Logging configuration class \"" + cname + "\" failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                System.err.println("" + ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                // keep going and useful config file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1375
        String fname = getConfigurationFileName();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1376
        try (final InputStream in = new FileInputStream(fname)) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1377
            final BufferedInputStream bin = new BufferedInputStream(in);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1378
            readConfiguration(bin);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1379
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1380
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1381
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1382
    String getConfigurationFileName() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        String fname = System.getProperty("java.util.logging.config.file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        if (fname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            fname = System.getProperty("java.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            if (fname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                throw new Error("Can't find java.home ??");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            }
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1389
            fname = Paths.get(fname, "conf", "logging.properties")
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1390
                    .toAbsolutePath().normalize().toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        }
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1392
        return fname;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * Reset the logging configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * For all named loggers, the reset operation removes and closes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * all Handlers and (except for the root logger) sets the level
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1400
     * to {@code null}. The root logger's level is set to {@code Level.INFO}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     *
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1402
     * @apiNote Calling this method also clears the LogManager {@linkplain
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1403
     * #getProperty(java.lang.String) properties}. The {@link
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1404
     * #updateConfiguration(java.util.function.Function)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1405
     * updateConfiguration(Function)} or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1406
     * {@link #updateConfiguration(java.io.InputStream, java.util.function.Function)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1407
     * updateConfiguration(InputStream, Function)} method can be used to
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1408
     * properly update to a new configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1409
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1410
     * @throws  SecurityException  if a security manager exists and if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    public void reset() throws SecurityException {
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  1415
        checkPermission();
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1416
27754
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
  1417
        List<CloseOnReset> persistent;
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1418
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1419
        // We don't want reset() and readConfiguration()
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1420
        // to run in parallel
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1421
        configurationLock.lock();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1422
        try {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1423
            // install new empty properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            props = new Properties();
27754
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
  1425
            // 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
  1426
            // 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
  1427
            // 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
  1428
            // 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
  1429
            persistent = new ArrayList<>(closeOnResetLoggers);
ee2f7768e1c9 8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed
dfuchs
parents: 27191
diff changeset
  1430
            closeOnResetLoggers.clear();
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1431
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1432
            // if reset has been called from shutdown-hook (Cleaner),
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1433
            // or if reset has been called from readConfiguration() which
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1434
            // 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
  1435
            // then do not change state here...
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1436
            if (globalHandlersState != STATE_SHUTDOWN &&
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1437
                globalHandlersState != STATE_READING_CONFIG) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1438
                // ...else user called reset()...
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1439
                // 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
  1440
                // 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
  1441
                globalHandlersState = STATE_INITIALIZED;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1442
            }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1443
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1444
            for (LoggerContext cx : contexts()) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1445
                resetLoggerContext(cx);
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1446
            }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1447
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1448
            persistent.clear();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1449
        } finally {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1450
            configurationLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        }
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1452
    }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1453
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1454
    private void resetLoggerContext(LoggerContext cx) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1455
        Enumeration<String> enum_ = cx.getLoggerNames();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1456
        while (enum_.hasMoreElements()) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1457
            String name = enum_.nextElement();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1458
            Logger logger = cx.findLogger(name);
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1459
            if (logger != null) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1460
                resetLogger(logger);
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  1461
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1465
    private void closeHandlers(Logger logger) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        Handler[] targets = logger.getHandlers();
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 22046
diff changeset
  1467
        for (Handler h : targets) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            logger.removeHandler(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                h.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                // Problems closing a handler?  Keep going...
41835
90450650fe74 8152515: (logging) LogManager.resetLogger should ignore LinkageError
dfuchs
parents: 39634
diff changeset
  1473
            } catch (Error e) {
90450650fe74 8152515: (logging) LogManager.resetLogger should ignore LinkageError
dfuchs
parents: 39634
diff changeset
  1474
                // ignore Errors while shutting down
90450650fe74 8152515: (logging) LogManager.resetLogger should ignore LinkageError
dfuchs
parents: 39634
diff changeset
  1475
                if (globalHandlersState != STATE_SHUTDOWN) {
90450650fe74 8152515: (logging) LogManager.resetLogger should ignore LinkageError
dfuchs
parents: 39634
diff changeset
  1476
                    throw e;
90450650fe74 8152515: (logging) LogManager.resetLogger should ignore LinkageError
dfuchs
parents: 39634
diff changeset
  1477
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        }
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1480
    }
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
    // Private method to reset an individual target logger.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1483
    private void resetLogger(Logger logger) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1484
        // Close all the Logger handlers.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1485
        closeHandlers(logger);
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1486
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1487
        // Reset Logger level
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  1488
        String name = logger.getName();
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 52427
diff changeset
  1489
        if (name != null && name.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            // This is the root logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            logger.setLevel(defaultLevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            logger.setLevel(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    // get a list of whitespace separated classnames from a property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    private String[] parseClassNames(String propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        String hands = getProperty(propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        if (hands == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        hands = hands.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        int ix = 0;
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  1505
        final List<String> result = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        while (ix < hands.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            int end = ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            while (end < hands.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                if (Character.isWhitespace(hands.charAt(end))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                if (hands.charAt(end) == ',') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            String word = hands.substring(ix, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            ix = end+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            word = word.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            if (word.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            result.add(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        return result.toArray(new String[result.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    /**
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1529
     * Reads and initializes the logging configuration from the given input stream.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1530
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1531
     * <p>
26859
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  1532
     * 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
  1533
     * listener} will be invoked after the properties are read.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  1534
     *
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1535
     * @apiNote This {@code readConfiguration} method should only be used for
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1536
     * initializing the configuration during LogManager initialization or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1537
     * used with the "java.util.logging.config.class" property.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1538
     * When this method is called after loggers have been created, all
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1539
     * existing loggers will be {@linkplain #reset() reset}. Then any
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1540
     * existing loggers that have a level property specified in the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1541
     * given input stream will be {@linkplain
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1542
     * Logger#setLevel(java.util.logging.Level) set} to the specified log level.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1543
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1544
     * To properly update the logging configuration, use the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1545
     * {@link #updateConfiguration(java.util.function.Function)} or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1546
     * {@link #updateConfiguration(java.io.InputStream, java.util.function.Function)}
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1547
     * method instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     *
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1549
     * @param ins  stream to read properties from
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1550
     * @throws  SecurityException  if a security manager exists and if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     *             the caller does not have LoggingPermission("control").
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1552
     * @throws  IOException if there are problems reading from the stream,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1553
     *             or the given stream is not in the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1554
     *             {@linkplain java.util.Properties properties file} format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    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
  1557
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1559
        // We don't want reset() and readConfiguration() to run
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1560
        // in parallel.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1561
        configurationLock.lock();
29739
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents: 27932
diff changeset
  1562
        try {
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1563
            if (globalHandlersState == STATE_SHUTDOWN) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1564
                // already in terminal state: don't even bother
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1565
                // to read the configuration
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1566
                return;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1567
            }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1568
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1569
            // 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
  1570
            globalHandlersState = STATE_READING_CONFIG;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1571
            try {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1572
                // reset configuration which leaves globalHandlersState at STATE_READING_CONFIG
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1573
                // 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
  1574
                // 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
  1575
                reset();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1576
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1577
                try {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1578
                    // Load the properties
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1579
                    props.load(ins);
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1580
                } catch (IllegalArgumentException x) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1581
                    // props.load may throw an IllegalArgumentException if the stream
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1582
                    // contains malformed Unicode escape sequences.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1583
                    // We wrap that in an IOException as readConfiguration is
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1584
                    // specified to throw IOException if there are problems reading
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1585
                    // from the stream.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1586
                    // 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
  1587
                    // concise error message than new IOException(x);
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1588
                    throw new IOException(x.getMessage(), x);
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1589
                }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1590
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1591
                // Instantiate new configuration objects.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1592
                String names[] = parseClassNames("config");
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1593
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1594
                for (String word : names) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1595
                    try {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1596
                        Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(word);
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1597
                        @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  1598
                        Object witness = clz.newInstance();
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1599
                    } catch (Exception ex) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1600
                        System.err.println("Can't load config class \"" + word + "\"");
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1601
                        System.err.println("" + ex);
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1602
                        // ex.printStackTrace();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1603
                    }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1604
                }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1605
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1606
                // 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
  1607
                setLevelsOnExistingLoggers();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1608
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1609
                // Note that we need to reinitialize global handles when
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1610
                // they are first referenced.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1611
                globalHandlersState = STATE_UNINITIALIZED;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1612
            } catch (Throwable t) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1613
                // 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
  1614
                // 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
  1615
                // initialized configuration.
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1616
                globalHandlersState = STATE_INITIALIZED;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1617
                // re-throw
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1618
                throw t;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1619
            }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1620
        } finally {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1621
            configurationLock.unlock();
29739
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents: 27932
diff changeset
  1622
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents: 27932
diff changeset
  1623
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1624
        // 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
  1625
        // when user code is involved
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  1626
        invokeConfigurationListeners();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1629
    // This enum enumerate the configuration properties that will be
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1630
    // updated on existing loggers when the configuration is updated
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1631
    // with LogManager.updateConfiguration().
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1632
    //
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1633
    // Note that this works properly only for the global LogManager - as
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1634
    // Handler and its subclasses get their configuration from
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1635
    // LogManager.getLogManager().
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1636
    //
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1637
    static enum ConfigProperty {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1638
        LEVEL(".level"), HANDLERS(".handlers"), USEPARENT(".useParentHandlers");
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1639
        final String suffix;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1640
        final int length;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1641
        private ConfigProperty(String suffix) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1642
            this.suffix = Objects.requireNonNull(suffix);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1643
            length = suffix.length();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1644
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1645
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1646
        public boolean handleKey(String key) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1647
            if (this == HANDLERS && suffix.substring(1).equals(key)) return true;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1648
            if (this == HANDLERS && suffix.equals(key)) return false;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1649
            return key.endsWith(suffix);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1650
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1651
        String key(String loggerName) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1652
            if (this == HANDLERS && (loggerName == null || loggerName.isEmpty())) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1653
                return suffix.substring(1);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1654
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1655
            return loggerName + suffix;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1656
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1657
        String loggerName(String key) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1658
            assert key.equals(suffix.substring(1)) && this == HANDLERS || key.endsWith(suffix);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1659
            if (this == HANDLERS && suffix.substring(1).equals(key)) return "";
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1660
            return key.substring(0, key.length() - length);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1661
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1662
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1663
        /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1664
         * If the property is one that should be updated on existing loggers by
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1665
         * updateConfiguration, returns the name of the logger for which the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1666
         * property is configured. Otherwise, returns null.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1667
         * @param property a property key in 'props'
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1668
         * @return the name of the logger on which the property is to be set,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1669
         *         if the property is one that should be updated on existing
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1670
         *         loggers, {@code null} otherwise.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1671
         */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1672
        static String getLoggerName(String property) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1673
            for (ConfigProperty p : ConfigProperty.ALL) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1674
                if (p.handleKey(property)) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1675
                    return p.loggerName(property);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1676
                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1677
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1678
            return null; // Not a property that should be updated.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1679
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1680
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1681
        /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1682
         * Find the ConfigProperty corresponding to the given
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1683
         * property key (may find none).
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1684
         * @param property a property key in 'props'
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1685
         * @return An optional containing a ConfigProperty object,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1686
         *         if the property is one that should be updated on existing
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1687
         *         loggers, empty otherwise.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1688
         */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1689
        static Optional<ConfigProperty> find(String property) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1690
            return ConfigProperty.ALL.stream()
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1691
                    .filter(p -> p.handleKey(property))
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1692
                    .findFirst();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1693
         }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1694
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1695
        /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1696
         * Returns true if the given property is one that should be updated
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1697
         * on existing loggers.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1698
         * Used to filter property name streams.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1699
         * @param property a property key from the configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1700
         * @return true if this property is of interest for updateConfiguration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1701
         */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1702
        static boolean matches(String property) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1703
            return find(property).isPresent();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1704
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1705
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1706
        /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1707
         * Returns true if the new property value is different from the old,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1708
         * and therefore needs to be updated on existing loggers.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1709
         * @param k a property key in the configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1710
         * @param previous the old configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1711
         * @param next the new configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1712
         * @return true if the property is changing value between the two
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1713
         *         configurations.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1714
         */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1715
        static boolean needsUpdating(String k, Properties previous, Properties next) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1716
            final String p = trim(previous.getProperty(k, null));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1717
            final String n = trim(next.getProperty(k, null));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1718
            return ! Objects.equals(p,n);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1719
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1720
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1721
        /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1722
         * Applies the mapping function for the given key to the next
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1723
         * configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1724
         * If the mapping function is null then this method does nothing.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1725
         * Otherwise, it calls the mapping function to compute the value
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1726
         * that should be associated with {@code key} in the resulting
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1727
         * configuration, and applies it to {@code next}.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1728
         * If the mapping function returns {@code null} the key is removed
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1729
         * from {@code next}.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1730
         *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1731
         * @param k a property key in the configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1732
         * @param previous the old configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1733
         * @param next the new configuration (modified by this function)
48221
0ba2a82e4755 8191033: Regression in logging.properties: specifying .handlers= for root logger (instead of handlers=) no longer works
dfuchs
parents: 47216
diff changeset
  1734
         * @param mappingFunction the mapping function.
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1735
         */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1736
        static void merge(String k, Properties previous, Properties next,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1737
                          BiFunction<String, String, String> mappingFunction) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1738
            String p = trim(previous.getProperty(k, null));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1739
            String n = trim(next.getProperty(k, null));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1740
            String mapped = trim(mappingFunction.apply(p,n));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1741
            if (!Objects.equals(n, mapped)) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1742
                if (mapped == null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1743
                    next.remove(k);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1744
                } else {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1745
                    next.setProperty(k, mapped);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1746
                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1747
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1748
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1749
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1750
        private static final EnumSet<ConfigProperty> ALL =
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1751
                EnumSet.allOf(ConfigProperty.class);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1752
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1753
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1754
    // trim the value if not null.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1755
    private static String trim(String value) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1756
        return value == null ? null : value.trim();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1757
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1758
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1759
    /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1760
     * An object that keep track of loggers we have already visited.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1761
     * Used when updating configuration, to avoid processing the same logger
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1762
     * twice.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1763
     */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1764
    static final class VisitedLoggers implements Predicate<Logger> {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1765
        final IdentityHashMap<Logger,Boolean> visited;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1766
        private VisitedLoggers(IdentityHashMap<Logger,Boolean> visited) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1767
            this.visited = visited;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1768
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1769
        VisitedLoggers() {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1770
            this(new IdentityHashMap<>());
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1771
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1772
        @Override
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1773
        public boolean test(Logger logger) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1774
            return visited != null && visited.put(logger, Boolean.TRUE) != null;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1775
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1776
        public void clear() {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1777
            if (visited != null) visited.clear();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1778
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1779
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1780
        // An object that considers that no logger has ever been visited.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1781
        // This is used when processParentHandlers is called from
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1782
        // LoggerContext.addLocalLogger
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1783
        static final VisitedLoggers NEVER = new VisitedLoggers(null);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1784
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1785
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1786
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1787
    /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1788
     * Type of the modification for a given property. One of SAME, ADDED, CHANGED,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1789
     * or REMOVED.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1790
     */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1791
    static enum ModType {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1792
        SAME,    // property had no value in the old and new conf, or had the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1793
                 // same value in both.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1794
        ADDED,   // property had no value in the old conf, but has one in the new.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1795
        CHANGED, // property has a different value in the old conf and the new conf.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1796
        REMOVED; // property has no value in the new conf, but had one in the old.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1797
        static ModType of(String previous, String next) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1798
            if (previous == null && next != null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1799
                return ADDED;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1800
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1801
            if (next == null && previous != null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1802
                return REMOVED;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1803
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1804
            if (!Objects.equals(trim(previous), trim(next))) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1805
                return CHANGED;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1806
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1807
            return SAME;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1808
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1809
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1810
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1811
    /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1812
     * Updates the logging configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1813
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1814
     * If the "java.util.logging.config.file" system property is set,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1815
     * then the property value specifies the properties file to be read
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1816
     * as the new configuration. Otherwise, the LogManager default
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1817
     * configuration is used.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1818
     * <br>The default configuration is typically loaded from the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1819
     * properties file "{@code conf/logging.properties}" in the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1820
     * Java installation directory.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1821
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1822
     * This method reads the new configuration and calls the {@link
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1823
     * #updateConfiguration(java.io.InputStream, java.util.function.Function)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1824
     * updateConfiguration(ins, mapper)} method to
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1825
     * update the configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1826
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1827
     * @apiNote
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1828
     * This method updates the logging configuration from reading
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1829
     * a properties file and ignores the "java.util.logging.config.class"
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1830
     * system property.  The "java.util.logging.config.class" property is
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1831
     * only used by the {@link #readConfiguration()}  method to load a custom
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1832
     * configuration class as an initial configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1833
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1834
     * @param mapper a functional interface that takes a configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1835
     *   key <i>k</i> and returns a function <i>f(o,n)</i> whose returned
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1836
     *   value will be applied to the resulting configuration. The
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1837
     *   function <i>f</i> may return {@code null} to indicate that the property
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1838
     *   <i>k</i> will not be added to the resulting configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1839
     *   <br>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1840
     *   If {@code mapper} is {@code null} then {@code (k) -> ((o, n) -> n)} is
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1841
     *   assumed.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1842
     *   <br>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1843
     *   For each <i>k</i>, the mapped function <i>f</i> will
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1844
     *   be invoked with the value associated with <i>k</i> in the old
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1845
     *   configuration (i.e <i>o</i>) and the value associated with
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1846
     *   <i>k</i> in the new configuration (i.e. <i>n</i>).
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1847
     *   <br>A {@code null} value for <i>o</i> or <i>n</i> indicates that no
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1848
     *   value was present for <i>k</i> in the corresponding configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1849
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1850
     * @throws  SecurityException  if a security manager exists and if
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1851
     *          the caller does not have LoggingPermission("control"), or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1852
     *          does not have the permissions required to set up the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1853
     *          configuration (e.g. open file specified for FileHandlers
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1854
     *          etc...)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1855
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1856
     * @throws  NullPointerException  if {@code mapper} returns a {@code null}
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1857
     *         function when invoked.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1858
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1859
     * @throws  IOException if there are problems reading from the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1860
     *          logging configuration file.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1861
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1862
     * @see #updateConfiguration(java.io.InputStream, java.util.function.Function)
44263
7a9297d467e7 8176563: @since value errors in apis of java.base/java.logging module
mli
parents: 41835
diff changeset
  1863
     * @since 9
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1864
     */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1865
    public void updateConfiguration(Function<String, BiFunction<String,String,String>> mapper)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1866
            throws IOException {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1867
        checkPermission();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1868
        ensureLogManagerInitialized();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1869
        drainLoggerRefQueueBounded();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1870
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1871
        String fname = getConfigurationFileName();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1872
        try (final InputStream in = new FileInputStream(fname)) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1873
            final BufferedInputStream bin = new BufferedInputStream(in);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1874
            updateConfiguration(bin, mapper);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1875
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1876
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1877
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1878
    /**
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1879
     * Updates the logging configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1880
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1881
     * For each configuration key in the {@linkplain
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1882
     * #getProperty(java.lang.String) existing configuration} and
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1883
     * the given input stream configuration, the given {@code mapper} function
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1884
     * is invoked to map from the configuration key to a function,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1885
     * <i>f(o,n)</i>, that takes the old value and new value and returns
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1886
     * the resulting value to be applied in the resulting configuration,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1887
     * as specified in the table below.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1888
     * <p>Let <i>k</i> be a configuration key in the old or new configuration,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1889
     * <i>o</i> be the old value (i.e. the value associated
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1890
     * with <i>k</i> in the old configuration), <i>n</i> be the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1891
     * new value (i.e. the value associated with <i>k</i> in the new
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1892
     * configuration), and <i>f</i> be the function returned
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1893
     * by {@code mapper.apply(}<i>k</i>{@code )}: then <i>v = f(o,n)</i> is the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1894
     * resulting value. If <i>v</i> is not {@code null}, then a property
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1895
     * <i>k</i> with value <i>v</i> will be added to the resulting configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1896
     * Otherwise, it will be omitted.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1897
     * <br>A {@code null} value may be passed to function
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1898
     * <i>f</i> to indicate that the corresponding configuration has no
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1899
     * configuration key <i>k</i>.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1900
     * The function <i>f</i> may return {@code null} to indicate that
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1901
     * there will be no value associated with <i>k</i> in the resulting
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1902
     * configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1903
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1904
     * If {@code mapper} is {@code null}, then <i>v</i> will be set to
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1905
     * <i>n</i>.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1906
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1907
     * LogManager {@linkplain #getProperty(java.lang.String) properties} are
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1908
     * updated with the resulting value in the resulting configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1909
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1910
     * The registered {@linkplain #addConfigurationListener configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1911
     * listeners} will be invoked after the configuration is successfully updated.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1912
     * <br><br>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1913
     * <table class="striped">
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1914
     * <caption style="display:none">Updating configuration properties</caption>
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1915
     * <thead>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1916
     * <tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1917
     * <th scope="col">Property</th>
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1918
     * <th scope="col">Resulting Behavior</th>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1919
     * </tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1920
     * </thead>
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1921
     * <tbody>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1922
     * <tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1923
     * <th scope="row" valign="top">{@code <logger>.level}</th>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1924
     * <td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1925
     * <ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1926
     *   <li>If the resulting configuration defines a level for a logger and
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1927
     *       if the resulting level is different than the level specified in the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1928
     *       the old configuration, or not specified in
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1929
     *       the old configuration, then if the logger exists or if children for
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1930
     *       that logger exist, the level for that logger will be updated,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1931
     *       and the change propagated to any existing logger children.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1932
     *       This may cause the logger to be created, if necessary.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1933
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1934
     *   <li>If the old configuration defined a level for a logger, and the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1935
     *       resulting configuration doesn't, then this change will not be
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1936
     *       propagated to existing loggers, if any.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1937
     *       To completely replace a configuration - the caller should therefore
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1938
     *       call {@link #reset() reset} to empty the current configuration,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1939
     *       before calling {@code updateConfiguration}.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1940
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1941
     * </ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1942
     * </td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1943
     * <tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1944
     * <th scope="row" valign="top">{@code <logger>.useParentHandlers}</th>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1945
     * <td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1946
     * <ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1947
     *   <li>If either the resulting or the old value for the useParentHandlers
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1948
     *       property is not null, then if the logger exists or if children for
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1949
     *       that logger exist, that logger will be updated to the resulting
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1950
     *       value.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1951
     *       The value of the useParentHandlers property is the value specified
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1952
     *       in the configuration; if not specified, the default is true.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1953
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1954
     * </ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1955
     * </td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1956
     * </tr>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1957
     * <tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1958
     * <th scope="row" valign="top">{@code <logger>.handlers}</th>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1959
     * <td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1960
     * <ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1961
     *   <li>If the resulting configuration defines a list of handlers for a
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1962
     *       logger, and if the resulting list is different than the list
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1963
     *       specified in the old configuration for that logger (that could be
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1964
     *       empty), then if the logger exists or its children exist, the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1965
     *       handlers associated with that logger are closed and removed and
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1966
     *       the new handlers will be created per the resulting configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1967
     *       and added to that logger, creating that logger if necessary.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1968
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1969
     *   <li>If the old configuration defined some handlers for a logger, and
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1970
     *       the resulting configuration doesn't, if that logger exists,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1971
     *       its handlers will be removed and closed.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1972
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1973
     *   <li>Changing the list of handlers on an existing logger will cause all
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1974
     *       its previous handlers to be removed and closed, regardless of whether
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1975
     *       they had been created from the configuration or programmatically.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1976
     *       The old handlers will be replaced by new handlers, if any.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1977
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1978
     * </ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1979
     * </td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1980
     * </tr>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1981
     * <tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1982
     * <th scope="row" valign="top">{@code <handler-name>.*}</th>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1983
     * <td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1984
     * <ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1985
     *   <li>Properties configured/changed on handler classes will only affect
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1986
     *       newly created handlers. If a node is configured with the same list
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1987
     *       of handlers in the old and the resulting configuration, then these
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1988
     *       handlers will remain unchanged.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1989
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1990
     * </ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1991
     * </td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1992
     * </tr>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1993
     * <tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  1994
     * <th scope="row" valign="top">{@code config} and any other property</th>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1995
     * <td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1996
     * <ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1997
     *   <li>The resulting value for these property will be stored in the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1998
     *   LogManager properties, but {@code updateConfiguration} will not parse
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  1999
     *   or process their values.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2000
     *   </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2001
     * </ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2002
     * </td>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2003
     * </tr>
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
  2004
     * </tbody>
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2005
     * </table>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2006
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2007
     * <em>Example mapper functions:</em>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2008
     * <br><br>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2009
     * <ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2010
     * <li>Replace all logging properties with the new configuration:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2011
     * <br><br>{@code     (k) -> ((o, n) -> n)}:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2012
     * <br><br>this is equivalent to passing a null {@code mapper} parameter.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2013
     * </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2014
     * <li>Merge the new configuration and old configuration and use the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2015
     * new value if <i>k</i> exists in the new configuration:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2016
     * <br><br>{@code     (k) -> ((o, n) -> n == null ? o : n)}:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2017
     * <br><br>as if merging two collections as follows:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2018
     * {@code result.putAll(oldc); result.putAll(newc)}.<br></li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2019
     * <li>Merge the new configuration and old configuration and use the old
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2020
     * value if <i>k</i> exists in the old configuration:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2021
     * <br><br>{@code     (k) -> ((o, n) -> o == null ? n : o)}:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2022
     * <br><br>as if merging two collections as follows:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2023
     * {@code result.putAll(newc); result.putAll(oldc)}.<br></li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2024
     * <li>Replace all properties with the new configuration except the handler
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2025
     * property to configure Logger's handler that is not root logger:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2026
     * <br>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2027
     * <pre>{@code (k) -> k.endsWith(".handlers")}
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2028
     *      {@code     ? ((o, n) -> (o == null ? n : o))}
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2029
     *      {@code     : ((o, n) -> n)}</pre>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2030
     * </li>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2031
     * </ul>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2032
     * <p>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2033
     * To completely reinitialize a configuration, an application can first call
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2034
     * {@link #reset() reset} to fully remove the old configuration, followed by
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2035
     * {@code updateConfiguration} to initialize the new configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2036
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2037
     * @param ins    a stream to read properties from
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2038
     * @param mapper a functional interface that takes a configuration
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2039
     *   key <i>k</i> and returns a function <i>f(o,n)</i> whose returned
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2040
     *   value will be applied to the resulting configuration. The
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2041
     *   function <i>f</i> may return {@code null} to indicate that the property
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2042
     *   <i>k</i> will not be added to the resulting configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2043
     *   <br>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2044
     *   If {@code mapper} is {@code null} then {@code (k) -> ((o, n) -> n)} is
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2045
     *   assumed.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2046
     *   <br>
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2047
     *   For each <i>k</i>, the mapped function <i>f</i> will
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2048
     *   be invoked with the value associated with <i>k</i> in the old
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2049
     *   configuration (i.e <i>o</i>) and the value associated with
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2050
     *   <i>k</i> in the new configuration (i.e. <i>n</i>).
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2051
     *   <br>A {@code null} value for <i>o</i> or <i>n</i> indicates that no
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2052
     *   value was present for <i>k</i> in the corresponding configuration.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2053
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2054
     * @throws  SecurityException if a security manager exists and if
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2055
     *          the caller does not have LoggingPermission("control"), or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2056
     *          does not have the permissions required to set up the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2057
     *          configuration (e.g. open files specified for FileHandlers)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2058
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2059
     * @throws  NullPointerException if {@code ins} is null or if
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2060
     *          {@code mapper} returns a null function when invoked.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2061
     *
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2062
     * @throws  IOException if there are problems reading from the stream,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2063
     *          or the given stream is not in the
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2064
     *          {@linkplain java.util.Properties properties file} format.
44263
7a9297d467e7 8176563: @since value errors in apis of java.base/java.logging module
mli
parents: 41835
diff changeset
  2065
     * @since 9
32984
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2066
     */
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2067
    public void updateConfiguration(InputStream ins,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2068
            Function<String, BiFunction<String,String,String>> mapper)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2069
            throws IOException {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2070
        checkPermission();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2071
        ensureLogManagerInitialized();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2072
        drainLoggerRefQueueBounded();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2073
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2074
        final Properties previous;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2075
        final Set<String> updatePropertyNames;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2076
        List<LoggerContext> cxs = Collections.emptyList();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2077
        final VisitedLoggers visited = new VisitedLoggers();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2078
        final Properties next = new Properties();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2079
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2080
        try {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2081
            // Load the properties
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2082
            next.load(ins);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2083
        } catch (IllegalArgumentException x) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2084
            // props.load may throw an IllegalArgumentException if the stream
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2085
            // contains malformed Unicode escape sequences.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2086
            // We wrap that in an IOException as updateConfiguration is
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2087
            // specified to throw IOException if there are problems reading
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2088
            // from the stream.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2089
            // Note: new IOException(x.getMessage(), x) allow us to get a more
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2090
            // concise error message than new IOException(x);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2091
            throw new IOException(x.getMessage(), x);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2092
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2093
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2094
        if (globalHandlersState == STATE_SHUTDOWN) return;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2095
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2096
        // exclusive lock: readConfiguration/reset/updateConfiguration can't
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2097
        //           run concurrently.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2098
        // configurationLock.writeLock().lock();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2099
        configurationLock.lock();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2100
        try {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2101
            if (globalHandlersState == STATE_SHUTDOWN) return;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2102
            previous = props;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2103
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2104
            // Builds a TreeSet of all (old and new) property names.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2105
            updatePropertyNames =
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2106
                    Stream.concat(previous.stringPropertyNames().stream(),
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2107
                                  next.stringPropertyNames().stream())
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2108
                        .collect(Collectors.toCollection(TreeSet::new));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2109
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2110
            if (mapper != null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2111
                // mapper will potentially modify the content of
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2112
                // 'next', so we need to call it before affecting props=next.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2113
                // give a chance to the mapper to control all
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2114
                // properties - not just those we will reset.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2115
                updatePropertyNames.stream()
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2116
                        .forEachOrdered(k -> ConfigProperty
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2117
                                .merge(k, previous, next,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2118
                                       Objects.requireNonNull(mapper.apply(k))));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2119
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2120
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2121
            props = next;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2122
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2123
            // allKeys will contain all keys:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2124
            //    - which correspond to a configuration property we are interested in
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2125
            //      (first filter)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2126
            //    - whose value needs to be updated (because it's new, removed, or
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2127
            //      different) in the resulting configuration (second filter)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2128
            final Stream<String> allKeys = updatePropertyNames.stream()
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2129
                    .filter(ConfigProperty::matches)
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2130
                    .filter(k -> ConfigProperty.needsUpdating(k, previous, next));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2131
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2132
            // Group configuration properties by logger name
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2133
            // We use a TreeMap so that parent loggers will be visited before
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2134
            // child loggers.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2135
            final Map<String, TreeSet<String>> loggerConfigs =
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2136
                    allKeys.collect(Collectors.groupingBy(ConfigProperty::getLoggerName,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2137
                                    TreeMap::new,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2138
                                    Collectors.toCollection(TreeSet::new)));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2139
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2140
            if (!loggerConfigs.isEmpty()) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2141
                cxs = contexts();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2142
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2143
            final List<Logger> loggers = cxs.isEmpty()
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2144
                    ? Collections.emptyList() : new ArrayList<>(cxs.size());
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2145
            for (Map.Entry<String, TreeSet<String>> e : loggerConfigs.entrySet()) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2146
                // This can be a logger name, or something else...
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2147
                // The only thing we know is that we found a property
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2148
                //    we are interested in.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2149
                // For instance, if we found x.y.z.level, then x.y.z could be
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2150
                // a logger, but it could also be a handler class...
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2151
                // Anyway...
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2152
                final String name = e.getKey();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2153
                final Set<String> properties = e.getValue();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2154
                loggers.clear();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2155
                for (LoggerContext cx : cxs) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2156
                    Logger l = cx.findLogger(name);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2157
                    if (l != null && !visited.test(l)) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2158
                        loggers.add(l);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2159
                    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2160
                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2161
                if (loggers.isEmpty()) continue;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2162
                for (String pk : properties) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2163
                    ConfigProperty cp = ConfigProperty.find(pk).get();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2164
                    String p = previous.getProperty(pk, null);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2165
                    String n = next.getProperty(pk, null);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2166
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2167
                    // Determines the type of modification.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2168
                    ModType mod = ModType.of(p, n);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2169
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2170
                    // mod == SAME means that the two values are equals, there
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2171
                    // is nothing to do. Usually, this should not happen as such
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2172
                    // properties should have been filtered above.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2173
                    // It could happen however if the properties had
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2174
                    // trailing/leading whitespaces.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2175
                    if (mod == ModType.SAME) continue;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2176
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2177
                    switch (cp) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2178
                        case LEVEL:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2179
                            if (mod == ModType.REMOVED) continue;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2180
                            Level level = Level.findLevel(trim(n));
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2181
                            if (level != null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2182
                                if (name.isEmpty()) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2183
                                    rootLogger.setLevel(level);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2184
                                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2185
                                for (Logger l : loggers) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2186
                                    if (!name.isEmpty() || l != rootLogger) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2187
                                        l.setLevel(level);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2188
                                    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2189
                                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2190
                            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2191
                            break;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2192
                        case USEPARENT:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2193
                            if (!name.isEmpty()) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2194
                                boolean useParent = getBooleanProperty(pk, true);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2195
                                if (n != null || p != null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2196
                                    // reset the flag only if the previous value
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2197
                                    // or the new value are not null.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2198
                                    for (Logger l : loggers) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2199
                                        l.setUseParentHandlers(useParent);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2200
                                    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2201
                                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2202
                            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2203
                            break;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2204
                        case HANDLERS:
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2205
                            List<Handler> hdls = null;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2206
                            if (name.isEmpty()) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2207
                                // special handling for the root logger.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2208
                                globalHandlersState = STATE_READING_CONFIG;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2209
                                try {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2210
                                    closeHandlers(rootLogger);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2211
                                    globalHandlersState = STATE_UNINITIALIZED;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2212
                                } catch (Throwable t) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2213
                                    globalHandlersState = STATE_INITIALIZED;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2214
                                    throw t;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2215
                                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2216
                            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2217
                            for (Logger l : loggers) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2218
                                if (l == rootLogger) continue;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2219
                                closeHandlers(l);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2220
                                if (mod == ModType.REMOVED) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2221
                                    closeOnResetLoggers.removeIf(c -> c.logger == l);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2222
                                    continue;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2223
                                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2224
                                if (hdls == null) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2225
                                    hdls = name.isEmpty()
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2226
                                            ? Arrays.asList(rootLogger.getHandlers())
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2227
                                            : createLoggerHandlers(name, pk);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2228
                                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2229
                                setLoggerHandlers(l, name, pk, hdls);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2230
                            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2231
                            break;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2232
                        default: break;
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2233
                    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2234
                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2235
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2236
        } finally {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2237
            configurationLock.unlock();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2238
            visited.clear();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2239
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2240
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2241
        // Now ensure that if an existing logger has acquired a new parent
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2242
        // in the configuration, this new parent will be created - if needed,
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2243
        // and added to the context of the existing child.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2244
        //
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2245
        drainLoggerRefQueueBounded();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2246
        for (LoggerContext cx : cxs) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2247
            for (Enumeration<String> names = cx.getLoggerNames() ; names.hasMoreElements();) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2248
                String name = names.nextElement();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2249
                if (name.isEmpty()) continue;  // don't need to process parents on root.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2250
                Logger l = cx.findLogger(name);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2251
                if (l != null && !visited.test(l)) {
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2252
                    // should pass visited here to cut the processing when
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2253
                    // reaching a logger already visited.
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2254
                    cx.processParentHandlers(l, name, visited);
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2255
                }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2256
            }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2257
        }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2258
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2259
        // We changed the configuration: invoke configuration listeners
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2260
        invokeConfigurationListeners();
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2261
    }
4f0f4023875a 8033661: readConfiguration does not cleanly reinitialize the logging system
dfuchs
parents: 32834
diff changeset
  2262
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     * Get the value of a logging property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
     * The method returns null if the property is not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
     * @param name      property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
     * @return          property value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    public String getProperty(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        return props.getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    // Package private method to get a String property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    // If the property is not defined we return the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
    // default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
    String getStringProperty(String name, String defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
        String val = getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        return val.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
    // Package private method to get an integer property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
    // If the property is not defined or cannot be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    // we return the given default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
    int getIntProperty(String name, int defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        String val = getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
            return Integer.parseInt(val.trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
27191
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2299
    // 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
  2300
    // 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
  2301
    // we return the given default value.
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2302
    long getLongProperty(String name, long defaultValue) {
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2303
        String val = getProperty(name);
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2304
        if (val == null) {
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2305
            return defaultValue;
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2306
        }
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2307
        try {
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2308
            return Long.parseLong(val.trim());
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2309
        } catch (Exception ex) {
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2310
            return defaultValue;
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2311
        }
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2312
    }
45a3002de56f 8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents: 26859
diff changeset
  2313
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
    // Package private method to get a boolean property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
    // If the property is not defined or cannot be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
    // we return the given default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
    boolean getBooleanProperty(String name, boolean defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
        String val = getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
        val = val.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        if (val.equals("true") || val.equals("1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        } else if (val.equals("false") || val.equals("0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    // Package private method to get a Level property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
    // If the property is not defined or cannot be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
    // we return the given default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    Level getLevelProperty(String name, Level defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        String val = getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        }
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2339
        Level l = Level.findLevel(val.trim());
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2340
        return l != null ? l : defaultValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
    // Package private method to get a filter property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
    // We return an instance of the class named by the "name"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    // property. If the property is not defined or has problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
    // we return the defaultValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
    Filter getFilterProperty(String name, Filter defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        String val = getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            if (val != null) {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  2351
                @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  2352
                Object o = ClassLoader.getSystemClassLoader().loadClass(val).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  2353
                return (Filter) o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            // We got one of a variety of exceptions in creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            // class or creating an instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
            // Drop through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
        // We got an exception.  Return the defaultValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
    // Package private method to get a formatter property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    // We return an instance of the class named by the "name"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
    // property. If the property is not defined or has problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
    // we return the defaultValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    Formatter getFormatterProperty(String name, Formatter defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        String val = getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            if (val != null) {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  2373
                @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  2374
                Object o = ClassLoader.getSystemClassLoader().loadClass(val).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37672
diff changeset
  2375
                return (Formatter) o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            // We got one of a variety of exceptions in creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            // class or creating an instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            // Drop through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        // We got an exception.  Return the defaultValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
    // Private method to load the global handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    // We do the real work lazily, when the global handlers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
    // are first used.
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2389
    private void initializeGlobalHandlers() {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2390
        int state = globalHandlersState;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2391
        if (state == STATE_INITIALIZED ||
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2392
            state == STATE_SHUTDOWN) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2393
            // Nothing to do: return.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
30643
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2397
        // 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
  2398
        // 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
  2399
        // globalHandlersState == STATE_UNINITIALIZED).
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2400
        // 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
  2401
        // 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
  2402
        // globalHandlersState == STATE_INITIALIZING).
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2403
        // 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
  2404
        // 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
  2405
        // is indicated by globalHandlersState == STATE_READING_CONFIG)
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2406
        // 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
  2407
        configurationLock.lock();
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2408
        try {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2409
            if (globalHandlersState != STATE_UNINITIALIZED) {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2410
                return; // recursive call or nothing to do
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2411
            }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2412
            // set globalHandlersState to STATE_INITIALIZING first to avoid
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2413
            // getting an infinite recursion when loadLoggerHandlers(...)
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2414
            // is going to call addHandler(...)
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2415
            globalHandlersState = STATE_INITIALIZING;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2416
            try {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2417
                loadLoggerHandlers(rootLogger, null, "handlers");
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2418
            } finally {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2419
                globalHandlersState = STATE_INITIALIZED;
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2420
            }
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2421
        } finally {
1fcf87dbdc3c 8077846: improve locking strategy for readConfiguration(), reset(), and initializeGlobalHandlers()
plevart
parents: 29919
diff changeset
  2422
            configurationLock.unlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2426
    static final Permission controlPermission =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2427
            new LoggingPermission("control", null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  2429
    void checkPermission() {
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  2430
        SecurityManager sm = System.getSecurityManager();
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  2431
        if (sm != null)
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  2432
            sm.checkPermission(controlPermission);
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  2433
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
     * Check that the current context is trusted to modify the logging
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
     * configuration.  This requires LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
     * If the check fails we throw a SecurityException, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
     * we return normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
    public void checkAccess() throws SecurityException {
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 13578
diff changeset
  2446
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
    // Nested class to represent a node in our tree of named loggers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
    private static class LogNode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        HashMap<String,LogNode> children;
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  2452
        LoggerWeakRef loggerRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        LogNode parent;
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2454
        final LoggerContext context;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2456
        LogNode(LogNode parent, LoggerContext context) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            this.parent = parent;
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2458
            this.context = context;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        // Recursive method to walk the tree below a node and set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        // a new parent logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        void walkAndSetParent(Logger parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
            if (children == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
            }
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 22046
diff changeset
  2467
            for (LogNode node : children.values()) {
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  2468
                LoggerWeakRef ref = node.loggerRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                Logger logger = (ref == null) ? null : ref.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
                if (logger == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                    node.walkAndSetParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
                    doSetParent(logger, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
    // We use a subclass of Logger for the root logger, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
    // that we only instantiate the global handlers when they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
    // are first needed.
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  2482
    private final class RootLogger extends Logger {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        private RootLogger() {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  2484
            // 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
  2485
            // to avoid calling LogManager.getLogManager() from within the
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  2486
            // RootLogger constructor.
23899
a926ecef7eb3 8029740: Enhance handling of loggers
dfuchs
parents: 23342
diff changeset
  2487
            super("", null, null, LogManager.this, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  2490
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
        public void log(LogRecord record) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            // Make sure that the global handlers have been instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
            initializeGlobalHandlers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
            super.log(record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  2497
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        public void addHandler(Handler h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
            initializeGlobalHandlers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
            super.addHandler(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  2503
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
        public void removeHandler(Handler h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
            initializeGlobalHandlers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
            super.removeHandler(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 19809
diff changeset
  2509
        @Override
23899
a926ecef7eb3 8029740: Enhance handling of loggers
dfuchs
parents: 23342
diff changeset
  2510
        Handler[] accessCheckedHandlers() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
            initializeGlobalHandlers();
23899
a926ecef7eb3 8029740: Enhance handling of loggers
dfuchs
parents: 23342
diff changeset
  2512
            return super.accessCheckedHandlers();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
    // Private method to be called when the configuration has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
    // 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
  2519
    private void setLevelsOnExistingLoggers() {
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9700
diff changeset
  2520
        Enumeration<?> enum_ = props.propertyNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
        while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            String key = (String)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
            if (!key.endsWith(".level")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
                // Not a level definition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
            int ix = key.length() - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            String name = key.substring(0, ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            Level level = getLevelProperty(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            if (level == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                System.err.println("Bad level value for property: " + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            }
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2534
            for (LoggerContext cx : contexts()) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2535
                Logger l = cx.findLogger(name);
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2536
                if (l == null) {
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2537
                    continue;
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2538
                }
9001e536ab4e 6664509: Add logging context
mchung
parents: 14216
diff changeset
  2539
                l.setLevel(level);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
     * String representation of the
9013
eedac0b9f552 7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents: 7803
diff changeset
  2546
     * {@link javax.management.ObjectName} for the management interface
eedac0b9f552 7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents: 7803
diff changeset
  2547
     * for the logging facility.
eedac0b9f552 7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents: 7803
diff changeset
  2548
     *
eedac0b9f552 7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents: 7803
diff changeset
  2549
     * @see java.lang.management.PlatformLoggingMXBean
eedac0b9f552 7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents: 7803
diff changeset
  2550
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
    public final static String LOGGING_MXBEAN_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
        = "java.util.logging:type=Logging";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 32035
diff changeset
  2557
     * Returns {@code LoggingMXBean} for managing loggers.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     * @return a {@link LoggingMXBean} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
     *
38370
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2561
     * @deprecated {@code java.util.logging.LoggingMXBean} is deprecated and
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2562
     *      replaced with {@code java.lang.management.PlatformLoggingMXBean}. Use
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2563
     *      {@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2564
     *      ManagementFactory.getPlatformMXBean}(PlatformLoggingMXBean.class)
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2565
     *      instead.
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2566
     *
9013
eedac0b9f552 7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents: 7803
diff changeset
  2567
     * @see java.lang.management.PlatformLoggingMXBean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     */
38370
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2570
    @Deprecated(since="9")
9013
eedac0b9f552 7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents: 7803
diff changeset
  2571
    public static synchronized LoggingMXBean getLoggingMXBean() {
38370
61f46e1e7aee 8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents: 37782
diff changeset
  2572
        return Logging.getInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    }
26859
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2574
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2575
    /**
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2576
     * 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
  2577
     * configuration is read.
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2578
     * 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
  2579
     * <p>
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2580
     * 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
  2581
     * 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
  2582
     * 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
  2583
     * <p>
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2584
     * 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
  2585
     *
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2586
     * 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
  2587
     * 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
  2588
     * {@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
  2589
     * 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
  2590
     *
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2591
     * @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
  2592
     * 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
  2593
     * 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
  2594
     * suppressed exceptions}.
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2595
     *
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2596
     * @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
  2597
     *        configuration changed.
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2598
     * @return This LogManager.
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2599
     * @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
  2600
     * 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
  2601
     * @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
  2602
     *
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 33875
diff changeset
  2603
     * @since 9
26859
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2604
     */
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2605
    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
  2606
        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
  2607
        checkPermission();
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2608
        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
  2609
        final AccessControlContext acc =
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2610
                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
  2611
        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
  2612
                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
  2613
        final Runnable pr =
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2614
                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
  2615
        // 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
  2616
        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
  2617
        return this;
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2618
    }
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2619
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2620
    /**
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2621
     * 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
  2622
     *
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2623
     * 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
  2624
     *
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2625
     * @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
  2626
     * @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
  2627
     * @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
  2628
     * 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
  2629
     *
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 33875
diff changeset
  2630
     * @since 9
26859
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2631
     */
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2632
    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
  2633
        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
  2634
        checkPermission();
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2635
        listeners.remove(key);
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2636
    }
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2637
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2638
    private void invokeConfigurationListeners() {
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2639
        Throwable t = null;
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2640
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2641
        // 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
  2642
        // keys using identity (==).
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2643
        // 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
  2644
        // 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
  2645
        // 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
  2646
        // ConcurrentModificationException while looping.
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2647
        //
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2648
        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
  2649
            try {
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2650
                c.run();
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2651
            } catch (ThreadDeath death) {
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2652
                throw death;
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2653
            } 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
  2654
                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
  2655
                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
  2656
            }
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2657
        }
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2658
        // 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
  2659
        // 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
  2660
        // 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
  2661
        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
  2662
        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
  2663
    }
8df035e321b8 8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents: 25859
diff changeset
  2664
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2665
    /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2666
     * This class allows the {@link LoggingProviderImpl} to demand loggers on
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2667
     * behalf of system and application classes.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2668
     */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2669
    private static final class LoggingProviderAccess
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2670
        implements LoggingProviderImpl.LogManagerAccess,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2671
                   PrivilegedAction<Void> {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2672
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2673
        private LoggingProviderAccess() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2674
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2675
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2676
        /**
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2677
         * Demands a logger on behalf of the given {@code module}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2678
         * <p>
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2679
         * If a named logger suitable for the given module is found
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2680
         * returns it.
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2681
         * Otherwise, creates a new logger suitable for the given module.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2682
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2683
         * @param name   The logger name.
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2684
         * @param module The module on which behalf the logger is created/retrieved.
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2685
         * @return A logger for the given {@code module}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2686
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2687
         * @throws NullPointerException if {@code name} is {@code null}
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2688
         *         or {@code module} is {@code null}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2689
         * @throws IllegalArgumentException if {@code manager} is not the default
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2690
         *         LogManager.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2691
         * @throws SecurityException if a security manager is present and the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2692
         *         calling code doesn't have the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2693
         *        {@link LoggingPermission LoggingPermission("demandLogger", null)}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2694
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2695
        @Override
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2696
        public Logger demandLoggerFor(LogManager manager, String name, Module module) {
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2697
            if (manager != getLogManager()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2698
                // having LogManager as parameter just ensures that the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2699
                // caller will have initialized the LogManager before reaching
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2700
                // here.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2701
                throw new IllegalArgumentException("manager");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2702
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2703
            Objects.requireNonNull(name);
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2704
            Objects.requireNonNull(module);
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2705
            SecurityManager sm = System.getSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2706
            if (sm != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2707
                sm.checkPermission(controlPermission);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2708
            }
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2709
            if (isSystem(module)) {
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2710
                return manager.demandSystemLogger(name,
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2711
                    Logger.SYSTEM_LOGGER_RB_NAME, module);
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2712
            } else {
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37520
diff changeset
  2713
                return manager.demandLogger(name, null, module);
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2714
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2715
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2716
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2717
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2718
        public Void run() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2719
            LoggingProviderImpl.setLogManagerAccess(INSTANCE);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2720
            return null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2721
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2722
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2723
        static final LoggingProviderAccess INSTANCE = new LoggingProviderAccess();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2724
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2725
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2726
    static {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2727
        AccessController.doPrivileged(LoggingProviderAccess.INSTANCE, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2728
                                      controlPermission);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2729
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32984
diff changeset
  2730
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
}