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