jdk/src/share/classes/java/util/logging/Logger.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7975 f0de2d05f34c
child 9699 5dfc211872f4
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
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) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // Note: we may get a MissingResourceException here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            setupResourceInfo(resourceBundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        levelValue = Level.INFO.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    // This constructor is used only to create the global Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    // It is needed to break a cyclic dependence between the LogManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // and Logger static initializers causing deadlocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private Logger(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // The manager field is not initialized here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        levelValue = Level.INFO.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    // It is called from the LogManager.<clinit> to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    // initialization of the global Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    void setLogManager(LogManager manager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        this.manager = manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private void checkAccess() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (!anonymous) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (manager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                // Complete initialization of the global Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                manager = LogManager.getLogManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            manager.checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Find or create a logger for a named subsystem.  If a logger has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * already been created with the given name it is returned.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * a new logger is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * If a new logger is created its log level will be configured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * 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
   293
     * to also send logging output to its parent's Handlers.  It will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * 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
   295
     * <p>
c86763d8f1c7 6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents: 5964
diff changeset
   296
     * 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
   297
     * 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
   298
     * 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
   299
     * 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
   300
     * 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
   301
     * {@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
   302
     * 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
   303
     * Logger named "MyLogger" elsewhere in the program.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param   name            A name for the logger.  This should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *                          be a dot-separated name and should normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *                          be based on the package name or class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *                          of the subsystem, such as java.net
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *                          or javax.swing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return a suitable Logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public static synchronized Logger getLogger(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        LogManager manager = LogManager.getLogManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return manager.demandLogger(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Find or create a logger for a named subsystem.  If a logger has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * already been created with the given name it is returned.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * a new logger is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * If a new logger is created its log level will be configured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * 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
   325
     * output to its parent's Handlers.  It will be registered in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * the LogManager global namespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <p>
6675
c86763d8f1c7 6949710: 3/3 the GC'able nature of Logging objects needs to be made brutally clear
dcubed
parents: 5964
diff changeset
   328
     * 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
   329
     * 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
   330
     * 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
   331
     * 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
   332
     * 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
   333
     * {@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
   334
     * 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
   335
     * 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
   336
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * If the named Logger already exists and does not yet have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * localization resource bundle then the given resource bundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * name is used.  If the named Logger already exists and has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * a different resource bundle name then an IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @param   name    A name for the logger.  This should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *                          be a dot-separated name and should normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *                          be based on the package name or class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *                          of the subsystem, such as java.net
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *                          or javax.swing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @param   resourceBundleName  name of ResourceBundle to be used for localizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *                          messages for this logger. May be <CODE>null</CODE> if none of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *                          the messages require localization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @return a suitable Logger
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   352
     * @throws MissingResourceException if the resourceBundleName is non-null and
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   353
     *             no corresponding resource can be found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @throws IllegalArgumentException if the Logger already exists and uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *             a different resource bundle name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public static synchronized Logger getLogger(String name, String resourceBundleName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        LogManager manager = LogManager.getLogManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        Logger result = manager.demandLogger(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (result.resourceBundleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // Note: we may get a MissingResourceException here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            result.setupResourceInfo(resourceBundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        } else if (!result.resourceBundleName.equals(resourceBundleName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            throw new IllegalArgumentException(result.resourceBundleName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                " != " + resourceBundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Create an anonymous Logger.  The newly created Logger is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * registered in the LogManager namespace.  There will be no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * access checks on updates to the logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * This factory method is primarily intended for use from applets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Because the resulting Logger is anonymous it can be kept private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * by the creating class.  This removes the need for normal security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * checks, which in turn allows untrusted applet code to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * the control state of the Logger.  For example an applet can do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * a setLevel or an addHandler on an anonymous Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Even although the new logger is anonymous, it is configured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * to have the root logger ("") as its parent.  This means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * by default it inherits its effective level and handlers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * from the root logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @return a newly created private Logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
   392
    public static Logger getAnonymousLogger() {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
   393
        return getAnonymousLogger(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Create an anonymous Logger.  The newly created Logger is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * registered in the LogManager namespace.  There will be no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * access checks on updates to the logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * This factory method is primarily intended for use from applets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Because the resulting Logger is anonymous it can be kept private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * by the creating class.  This removes the need for normal security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * checks, which in turn allows untrusted applet code to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * the control state of the Logger.  For example an applet can do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * a setLevel or an addHandler on an anonymous Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Even although the new logger is anonymous, it is configured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * to have the root logger ("") as its parent.  This means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * by default it inherits its effective level and handlers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * from the root logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param   resourceBundleName  name of ResourceBundle to be used for localizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *                          messages for this logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *          May be null if none of the messages require localization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return a newly created private Logger
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   417
     * @throws MissingResourceException if the resourceBundleName is non-null and
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   418
     *             no corresponding resource can be found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public static synchronized Logger getAnonymousLogger(String resourceBundleName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        LogManager manager = LogManager.getLogManager();
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
   422
        // 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
   423
        manager.drainLoggerRefQueueBounded();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        Logger result = new Logger(null, resourceBundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        result.anonymous = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        Logger root = manager.getLogger("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        result.doSetParent(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Retrieve the localization resource bundle for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * logger for the current default locale.  Note that if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * the result is null, then the Logger will use a resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * bundle inherited from its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @return localization bundle (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public ResourceBundle getResourceBundle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return findResourceBundle(getResourceBundleName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Retrieve the localization resource bundle name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * logger.  Note that if the result is null, then the Logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * will use a resource bundle name inherited from its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @return localization bundle name (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public String getResourceBundleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return resourceBundleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Set a filter to control output on this Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * After passing the initial "level" check, the Logger will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * call this Filter to check if a log record should really
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * be published.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @param   newFilter  a filter object (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
   465
    public void setFilter(Filter newFilter) throws SecurityException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        filter = newFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Get the current filter for this Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @return  a filter object (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
   475
    public Filter getFilter() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        return filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * Log a LogRecord.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * All the other logging methods in this class call through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * this method to actually perform any logging.  Subclasses can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * override this single method to capture all log activity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @param record the LogRecord to be published
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public void log(LogRecord record) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (record.getLevel().intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
   492
        Filter theFilter = filter;
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
   493
        if (theFilter != null && !theFilter.isLoggable(record)) {
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
   494
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // Post the LogRecord to all our Handlers, and then to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        // our parents' handlers, all the way up the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        Logger logger = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        while (logger != null) {
2630
1088f346d108 6830220: Logging issues due to regression from bug fix 6797480
martin
parents: 1933
diff changeset
   502
            for (Handler handler : logger.getHandlers()) {
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
   503
                handler.publish(record);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if (!logger.getUseParentHandlers()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            logger = logger.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    // private support method for logging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    // We fill in the logger name, resource bundle name, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    // resource bundle and then call "void log(LogRecord)".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    private void doLog(LogRecord lr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        lr.setLoggerName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        String ebname = getEffectiveResourceBundleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (ebname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            lr.setResourceBundleName(ebname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            lr.setResourceBundle(findResourceBundle(ebname));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        log(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    //================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    // Start of convenience methods WITHOUT className and methodName
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
     * Log a message, with no arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   539
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public void log(Level level, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Log a message, with one object parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * level then a corresponding LogRecord is created and forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * to all the registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   557
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @param   param1  parameter to the message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    public void log(Level level, String msg, Object param1) {
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
        Object params[] = { param1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        lr.setParameters(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Log a message, with an array of object arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * level then a corresponding LogRecord is created and forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * to all the registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   578
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @param   params  array of parameters to the message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    public void log(Level level, String msg, Object params[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        lr.setParameters(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Log a message, with associated Throwable information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * level then the given arguments are stored in a LogRecord
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * which is forwarded to all registered output handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * Note that the thrown argument is stored in the LogRecord thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * property, rather than the LogRecord parameters property.  Thus is it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * processed specially by output Formatters and is not treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * as a formatting parameter to the LogRecord message property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   603
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @param   thrown  Throwable associated with log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public void log(Level level, String msg, Throwable thrown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        lr.setThrown(thrown);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    //================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    // Start of convenience methods WITH className and methodName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    //================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * Log a message, specifying source class and method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * with no arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   628
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Log a message, specifying source class and method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * with a single object parameter to the log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * level then a corresponding LogRecord is created and forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * to all the registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   651
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @param   msg      The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @param   param1    Parameter to the log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    public void logp(Level level, String sourceClass, String sourceMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                                String msg, Object param1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        Object params[] = { param1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        lr.setParameters(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * Log a message, specifying source class and method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * with an array of object arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * level then a corresponding LogRecord is created and forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * to all the registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   678
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @param   params  Array of parameters to the message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public void logp(Level level, String sourceClass, String sourceMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                                String msg, Object params[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        lr.setParameters(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Log a message, specifying source class and method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * with associated Throwable information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * level then the given arguments are stored in a LogRecord
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * which is forwarded to all registered output handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * Note that the thrown argument is stored in the LogRecord thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * property, rather than the LogRecord parameters property.  Thus is it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * processed specially by output Formatters and is not treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * as a formatting parameter to the LogRecord message property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   709
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @param   thrown  Throwable associated with log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    public void logp(Level level, String sourceClass, String sourceMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                                                        String msg, Throwable thrown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        lr.setThrown(thrown);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    //=========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    // Start of convenience methods WITH className, methodName and bundle name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    //=========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    // Private support method for logging for "logrb" methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    // We fill in the logger name, resource bundle name, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    // resource bundle and then call "void log(LogRecord)".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    private void doLog(LogRecord lr, String rbname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        lr.setLoggerName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        if (rbname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            lr.setResourceBundleName(rbname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            lr.setResourceBundle(findResourceBundle(rbname));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        log(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * Log a message, specifying source class, method, and resource bundle name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * with no arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * The msg string is localized using the named resource bundle.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * resource bundle name is null, or an empty String or invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * then the msg string is not localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   756
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @param   bundleName     name of resource bundle to localize msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     *                         can be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public void logrb(Level level, String sourceClass, String sourceMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                String bundleName, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        doLog(lr, bundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Log a message, specifying source class, method, and resource bundle name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * with a single object parameter to the log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * level then a corresponding LogRecord is created and forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * to all the registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * The msg string is localized using the named resource bundle.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * resource bundle name is null, or an empty String or invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * then the msg string is not localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   787
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @param   bundleName     name of resource bundle to localize msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *                         can be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @param   msg      The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @param   param1    Parameter to the log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    public void logrb(Level level, String sourceClass, String sourceMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                String bundleName, String msg, Object param1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        Object params[] = { param1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        lr.setParameters(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        doLog(lr, bundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * Log a message, specifying source class, method, and resource bundle name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * with an array of object arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * level then a corresponding LogRecord is created and forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * to all the registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * The msg string is localized using the named resource bundle.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * resource bundle name is null, or an empty String or invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * then the msg string is not localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   820
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @param   bundleName     name of resource bundle to localize msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *                         can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * @param   params  Array of parameters to the message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    public void logrb(Level level, String sourceClass, String sourceMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                                String bundleName, String msg, Object params[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        lr.setParameters(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        doLog(lr, bundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * Log a message, specifying source class, method, and resource bundle name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * with associated Throwable information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * level then the given arguments are stored in a LogRecord
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * which is forwarded to all registered output handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * The msg string is localized using the named resource bundle.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * resource bundle name is null, or an empty String or invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * then the msg string is not localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * Note that the thrown argument is stored in the LogRecord thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * property, rather than the LogRecord parameters property.  Thus is it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * processed specially by output Formatters and is not treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * as a formatting parameter to the LogRecord message property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * <p>
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2630
diff changeset
   857
     * @param   level   One of the message level identifiers, e.g., SEVERE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @param   sourceMethod   name of method that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @param   bundleName     name of resource bundle to localize msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *                         can be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @param   thrown  Throwable associated with log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    public void logrb(Level level, String sourceClass, String sourceMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                                        String bundleName, String msg, Throwable thrown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        LogRecord lr = new LogRecord(level, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        lr.setThrown(thrown);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        doLog(lr, bundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    // Start of convenience methods for logging method entries and returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * Log a method entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * This is a convenience method that can be used to log entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * to a method.  A LogRecord with message "ENTRY", log level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * FINER, and the given sourceMethod and sourceClass is logged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @param   sourceMethod   name of method that is being entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public void entering(String sourceClass, String sourceMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        if (Level.FINER.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * Log a method entry, with one parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * This is a convenience method that can be used to log entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * to a method.  A LogRecord with message "ENTRY {0}", log level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * FINER, and the given sourceMethod, sourceClass, and parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * is logged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @param   sourceMethod   name of method that is being entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @param   param1         parameter to the method 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, Object param1) {
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
        Object params[] = { param1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Log a method entry, with an array of parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * This is a convenience method that can be used to log entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * to a method.  A LogRecord with message "ENTRY" (followed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * format {N} indicator for each entry in the parameter array),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * log level FINER, and the given sourceMethod, sourceClass, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * parameters is logged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @param   sourceMethod   name of method that is being entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @param   params         array of parameters to the method being entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    public void entering(String sourceClass, String sourceMethod, Object params[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (Level.FINER.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        String msg = "ENTRY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if (params == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
           logp(Level.FINER, sourceClass, sourceMethod, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
           return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        for (int i = 0; i < params.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            msg = msg + " {" + i + "}";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        logp(Level.FINER, sourceClass, sourceMethod, msg, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Log a method return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * This is a convenience method that can be used to log returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * from a method.  A LogRecord with message "RETURN", log level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * FINER, and the given sourceMethod and sourceClass is logged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * @param   sourceMethod   name of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    public void exiting(String sourceClass, String sourceMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        if (Level.FINER.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * Log a method return, with result object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * This is a convenience method that can be used to log returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * from a method.  A LogRecord with message "RETURN {0}", log level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * FINER, and the gives sourceMethod, sourceClass, and result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * object 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
     * @param   result  Object that is being returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    public void exiting(String sourceClass, String sourceMethod, Object result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        if (Level.FINER.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        Object params[] = { result };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * Log throwing an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * This is a convenience method to log that a method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * terminating by throwing an exception.  The logging is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * using the FINER level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * If the logger is currently enabled for the given message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * level then the given arguments are stored in a LogRecord
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * which is forwarded to all registered output handlers.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * LogRecord's message is set to "THROW".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * Note that the thrown argument is stored in the LogRecord thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * property, rather than the LogRecord parameters property.  Thus is it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * processed specially by output Formatters and is not treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * as a formatting parameter to the LogRecord message property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @param   sourceClass    name of class that issued the logging request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @param   sourceMethod  name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @param   thrown  The Throwable that is being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    public void throwing(String sourceClass, String sourceMethod, Throwable thrown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        if (Level.FINER.intValue() < levelValue || levelValue == offValue ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        LogRecord lr = new LogRecord(Level.FINER, "THROW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        lr.setSourceClassName(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        lr.setSourceMethodName(sourceMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        lr.setThrown(thrown);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        doLog(lr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    //=======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    // Start of simple convenience methods using level names as method names
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    //=======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * Log a SEVERE message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * If the logger is currently enabled for the SEVERE message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public void severe(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (Level.SEVERE.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        log(Level.SEVERE, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Log a WARNING message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * If the logger is currently enabled for the WARNING message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    public void warning(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        if (Level.WARNING.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        log(Level.WARNING, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * Log an INFO message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * If the logger is currently enabled for the INFO message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    public void info(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        if (Level.INFO.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        log(Level.INFO, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * Log a CONFIG message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * If the logger is currently enabled for the CONFIG message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    public void config(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        if (Level.CONFIG.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        log(Level.CONFIG, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * Log a FINE message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * If the logger is currently enabled for the FINE message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    public void fine(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        if (Level.FINE.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        log(Level.FINE, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * Log a FINER message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * If the logger is currently enabled for the FINER message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    public void finer(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        if (Level.FINER.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        log(Level.FINER, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * Log a FINEST message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * If the logger is currently enabled for the FINEST message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * level then the given message is forwarded to all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * registered output Handler objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * @param   msg     The string message (or a key in the message catalog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    public void finest(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (Level.FINEST.intValue() < levelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        log(Level.FINEST, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    //================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    // End of convenience methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    //================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * Set the log level specifying which message levels will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * logged by this logger.  Message levels lower than this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * value will be discarded.  The level value Level.OFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * can be used to turn off logging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * If the new level is null, it means that this node should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * inherit its level from its nearest ancestor with a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * (non-null) level value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @param newLevel   the new value for the log level (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    public void setLevel(Level newLevel) throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        synchronized (treeLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            levelObject = newLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            updateEffectiveLevel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * Get the log Level that has been specified for this Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * The result may be null, which means that this logger's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * effective level will be inherited from its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @return  this Logger's level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    public Level getLevel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        return levelObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * Check if a message of the given level would actually be logged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * by this logger.  This check is based on the Loggers effective level,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * which may be inherited from its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @param   level   a message logging level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * @return  true if the given message level is currently being logged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    public boolean isLoggable(Level level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        if (level.intValue() < levelValue || levelValue == offValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * Get the name for this logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @return logger name.  Will be null for anonymous Loggers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * Add a log Handler to receive logging messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * By default, Loggers also send their output to their parent logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * Typically the root Logger is configured with a set of Handlers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * that essentially act as default handlers for all loggers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * @param   handler a logging Handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     */
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1204
    public void addHandler(Handler handler) throws SecurityException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        // Check for null handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        handler.getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        handlers.add(handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * Remove a log Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * Returns silently if the given Handler is not found or is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * @param   handler a logging Handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     */
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1220
    public void removeHandler(Handler handler) throws SecurityException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        handlers.remove(handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * Get the Handlers associated with this logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * @return  an array of all registered Handlers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     */
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1233
    public Handler[] getHandlers() {
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1234
        return handlers.toArray(emptyHandlers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * 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
  1239
     * to its parent Logger.  This means that any LogRecords will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * also be written to the parent's Handlers, and potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * to its parent, recursively up the namespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @param useParentHandlers   true if output is to be sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     *          logger's parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     */
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1248
    public void setUseParentHandlers(boolean useParentHandlers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        this.useParentHandlers = useParentHandlers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * Discover whether or not this logger is sending its output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * to its parent logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * @return  true if output is to be sent to the logger's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     */
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1259
    public boolean getUseParentHandlers() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        return useParentHandlers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    // Private utility method to map a resource bundle name to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    // actual resource bundle, using a simple one-entry cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    // Returns null for a null name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    // May also return null if we can't find the resource bundle and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    // there is no suitable previous cached value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    private synchronized ResourceBundle findResourceBundle(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        // Return a null bundle for a null name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        Locale currentLocale = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        // Normally we should hit on our simple one entry cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        if (catalog != null && currentLocale == catalogLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                                        && name == catalogName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            return catalog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        // Use the thread's context ClassLoader.  If there isn't one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        // use the SystemClassloader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        if (cl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            cl = ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            catalog = ResourceBundle.getBundle(name, currentLocale, cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            catalogName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            catalogLocale = currentLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            return catalog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        } catch (MissingResourceException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            // Woops.  We can't find the ResourceBundle in the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            // ClassLoader.  Drop through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        // Fall back to searching up the call stack and trying each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        // calling ClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        for (int ix = 0; ; ix++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            Class clz = sun.reflect.Reflection.getCallerClass(ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            if (clz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            ClassLoader cl2 = clz.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            if (cl2 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                cl2 = ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            if (cl == cl2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                // We've already checked this classloader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            cl = cl2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                catalog = ResourceBundle.getBundle(name, currentLocale, cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                catalogName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                catalogLocale = currentLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                return catalog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            } catch (MissingResourceException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                // Ok, this one didn't work either.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                // Drop through, and try the next one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        if (name.equals(catalogName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            // Return the previous cached value for that name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            // This may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            return catalog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        // Sorry, we're out of luck.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    // Private utility method to initialize our one entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    // resource bundle cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    // Note: for consistency reasons, we are careful to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    // that a suitable ResourceBundle exists before setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    // ResourceBundleName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    private synchronized void setupResourceInfo(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        ResourceBundle rb = findResourceBundle(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        if (rb == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            // We've failed to find an expected ResourceBundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            throw new MissingResourceException("Can't find " + name + " bundle", name, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        resourceBundleName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * Return the parent for this Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * This method returns the nearest extant parent in the namespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * Thus if a Logger is called "a.b.c.d", and a Logger called "a.b"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * has been created but no logger "a.b.c" exists, then a call of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * getParent on the Logger "a.b.c.d" will return the Logger "a.b".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * The result will be null if it is called on the root Logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * in the namespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * @return nearest existing parent Logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    public Logger getParent() {
1933
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1367
        // Note: this used to be synchronized on treeLock.  However, this only
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1368
        // provided memory semantics, as there was no guarantee that the caller
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1369
        // would synchronize on treeLock (in fact, there is no way for external
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1370
        // callers to so synchronize).  Therefore, we have made parent volatile
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1371
        // instead.
1210d93b6ee7 6797480: Remove synchronization bottleneck in logger
martin
parents: 2
diff changeset
  1372
        return parent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * Set the parent for this Logger.  This method is used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * the LogManager to update a Logger when the namespace changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * It should not be called from application code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * @param  parent   the new parent logger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     *             the caller does not have LoggingPermission("control").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    public void setParent(Logger parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        manager.checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        doSetParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    // Private method to do the work for parenting a child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    // Logger onto a parent logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    private void doSetParent(Logger newParent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        // System.err.println("doSetParent \"" + getName() + "\" \""
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        //                              + newParent.getName() + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        synchronized (treeLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            // Remove ourself from any previous parent.
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1403
            LogManager.LoggerWeakRef ref = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                // assert parent.kids != null;
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1406
                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
  1407
                    ref = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                    Logger kid =  ref.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    if (kid == this) {
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1410
                        // ref is used down below to complete the reparenting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                        iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                        break;
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1413
                    } else {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1414
                        ref = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                // We have now removed ourself from our parents' kids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
            // Set our new parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            parent = newParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            if (parent.kids == null) {
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 6675
diff changeset
  1423
                parent.kids = new ArrayList<>(2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            }
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1425
            if (ref == null) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1426
                // we didn't have a previous parent
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1427
                ref = manager.new LoggerWeakRef(this);
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1428
            }
7975
f0de2d05f34c 7011095: revert diamond changes from 6880112 that occur in method args
smarks
parents: 7803
diff changeset
  1429
            ref.setParentRef(new WeakReference<Logger>(parent));
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1430
            parent.kids.add(ref);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            // As a result of the reparenting, the effective level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            // may have changed for us and our children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            updateEffectiveLevel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
5964
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1439
    // Package-level method.
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1440
    // 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
  1441
    // 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
  1442
    final void removeChildLogger(LogManager.LoggerWeakRef child) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1443
        synchronized (treeLock) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1444
            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
  1445
                LogManager.LoggerWeakRef ref = iter.next();
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1446
                if (ref == child) {
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1447
                    iter.remove();
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1448
                    return;
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1449
                }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1450
            }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1451
        }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1452
    }
0496aa46ae9f 6942989: 2/2 Memory leak of java.lang.ref.WeakReference objects
dcubed
parents: 5506
diff changeset
  1453
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    // Recalculate the effective level for this node and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    // recursively for our children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    private void updateEffectiveLevel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        // assert Thread.holdsLock(treeLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        // Figure out our current effective level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        int newLevelValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        if (levelObject != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            newLevelValue = levelObject.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                newLevelValue = parent.levelValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                // This may happen during initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                newLevelValue = Level.INFO.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        // If our effective value hasn't changed, we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        if (levelValue == newLevelValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        levelValue = newLevelValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        // System.err.println("effective level: \"" + getName() + "\" := " + level);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        // Recursively update the level on each of our kids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        if (kids != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            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
  1485
                LogManager.LoggerWeakRef ref = kids.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                Logger kid =  ref.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                if (kid != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                    kid.updateEffectiveLevel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    // Private method to get the potentially inherited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    // resource bundle name for this Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    // May return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    private String getEffectiveResourceBundleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        Logger target = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        while (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            String rbn = target.getResourceBundleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            if (rbn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                return rbn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            target = target.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
}