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