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