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