rt/emul/compact/src/main/java/java/util/logging/Logger.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 07 Sep 2013 13:56:22 +0200
changeset 1260 fe3567c7b522
parent 1259 d257b7a37635
child 1277 853245102164
permissions -rw-r--r--
Re-implementation of the JDK APIs to fit into the browser
jaroslav@1258
     1
/*
jaroslav@1258
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
jaroslav@1258
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@1258
     4
 *
jaroslav@1258
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@1258
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@1258
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@1258
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@1258
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@1258
    10
 *
jaroslav@1258
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@1258
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@1258
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@1258
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@1258
    15
 * accompanied this code).
jaroslav@1258
    16
 *
jaroslav@1258
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@1258
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@1258
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@1258
    20
 *
jaroslav@1258
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@1258
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@1258
    23
 * questions.
jaroslav@1258
    24
 */
jaroslav@1258
    25
jaroslav@1258
    26
jaroslav@1258
    27
package java.util.logging;
jaroslav@1258
    28
jaroslav@1260
    29
import java.util.HashMap;
jaroslav@1260
    30
import java.util.Map;
jaroslav@1260
    31
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@1258
    32
jaroslav@1258
    33
/**
jaroslav@1258
    34
 * A Logger object is used to log messages for a specific
jaroslav@1258
    35
 * system or application component.  Loggers are normally named,
jaroslav@1258
    36
 * using a hierarchical dot-separated namespace.  Logger names
jaroslav@1258
    37
 * can be arbitrary strings, but they should normally be based on
jaroslav@1258
    38
 * the package name or class name of the logged component, such
jaroslav@1258
    39
 * as java.net or javax.swing.  In addition it is possible to create
jaroslav@1258
    40
 * "anonymous" Loggers that are not stored in the Logger namespace.
jaroslav@1258
    41
 * <p>
jaroslav@1258
    42
 * Logger objects may be obtained by calls on one of the getLogger
jaroslav@1258
    43
 * factory methods.  These will either create a new Logger or
jaroslav@1258
    44
 * return a suitable existing Logger. It is important to note that
jaroslav@1258
    45
 * the Logger returned by one of the {@code getLogger} factory methods
jaroslav@1258
    46
 * may be garbage collected at any time if a strong reference to the
jaroslav@1258
    47
 * Logger is not kept.
jaroslav@1258
    48
 * <p>
jaroslav@1258
    49
 * Logging messages will be forwarded to registered Handler
jaroslav@1258
    50
 * objects, which can forward the messages to a variety of
jaroslav@1258
    51
 * destinations, including consoles, files, OS logs, etc.
jaroslav@1258
    52
 * <p>
jaroslav@1258
    53
 * Each Logger keeps track of a "parent" Logger, which is its
jaroslav@1258
    54
 * nearest existing ancestor in the Logger namespace.
jaroslav@1258
    55
 * <p>
jaroslav@1258
    56
 * Each Logger has a "Level" associated with it.  This reflects
jaroslav@1258
    57
 * a minimum Level that this logger cares about.  If a Logger's
jaroslav@1258
    58
 * level is set to <tt>null</tt>, then its effective level is inherited
jaroslav@1258
    59
 * from its parent, which may in turn obtain it recursively from its
jaroslav@1258
    60
 * parent, and so on up the tree.
jaroslav@1258
    61
 * <p>
jaroslav@1258
    62
 * The log level can be configured based on the properties from the
jaroslav@1258
    63
 * logging configuration file, as described in the description
jaroslav@1258
    64
 * of the LogManager class.  However it may also be dynamically changed
jaroslav@1258
    65
 * by calls on the Logger.setLevel method.  If a logger's level is
jaroslav@1258
    66
 * changed the change may also affect child loggers, since any child
jaroslav@1258
    67
 * logger that has <tt>null</tt> as its level will inherit its
jaroslav@1258
    68
 * effective level from its parent.
jaroslav@1258
    69
 * <p>
jaroslav@1258
    70
 * On each logging call the Logger initially performs a cheap
jaroslav@1258
    71
 * check of the request level (e.g., SEVERE or FINE) against the
jaroslav@1258
    72
 * effective log level of the logger.  If the request level is
jaroslav@1258
    73
 * lower than the log level, the logging call returns immediately.
jaroslav@1258
    74
 * <p>
jaroslav@1258
    75
 * After passing this initial (cheap) test, the Logger will allocate
jaroslav@1258
    76
 * a LogRecord to describe the logging message.  It will then call a
jaroslav@1258
    77
 * Filter (if present) to do a more detailed check on whether the
jaroslav@1258
    78
 * record should be published.  If that passes it will then publish
jaroslav@1258
    79
 * the LogRecord to its output Handlers.  By default, loggers also
jaroslav@1258
    80
 * publish to their parent's Handlers, recursively up the tree.
jaroslav@1258
    81
 * <p>
jaroslav@1258
    82
 * Each Logger may have a ResourceBundle name associated with it.
jaroslav@1258
    83
 * The named bundle will be used for localizing logging messages.
jaroslav@1258
    84
 * If a Logger does not have its own ResourceBundle name, then
jaroslav@1258
    85
 * it will inherit the ResourceBundle name from its parent,
jaroslav@1258
    86
 * recursively up the tree.
jaroslav@1258
    87
 * <p>
jaroslav@1258
    88
 * Most of the logger output methods take a "msg" argument.  This
jaroslav@1258
    89
 * msg argument may be either a raw value or a localization key.
jaroslav@1258
    90
 * During formatting, if the logger has (or inherits) a localization
jaroslav@1258
    91
 * ResourceBundle and if the ResourceBundle has a mapping for the msg
jaroslav@1258
    92
 * string, then the msg string is replaced by the localized value.
jaroslav@1258
    93
 * Otherwise the original msg string is used.  Typically, formatters use
jaroslav@1258
    94
 * java.text.MessageFormat style formatting to format parameters, so
jaroslav@1258
    95
 * for example a format string "{0} {1}" would format two parameters
jaroslav@1258
    96
 * as strings.
jaroslav@1258
    97
 * <p>
jaroslav@1258
    98
 * When mapping ResourceBundle names to ResourceBundles, the Logger
jaroslav@1258
    99
 * will first try to use the Thread's ContextClassLoader.  If that
jaroslav@1258
   100
 * is null it will try the SystemClassLoader instead.  As a temporary
jaroslav@1258
   101
 * transition feature in the initial implementation, if the Logger is
jaroslav@1258
   102
 * unable to locate a ResourceBundle from the ContextClassLoader or
jaroslav@1258
   103
 * SystemClassLoader the Logger will also search up the class stack
jaroslav@1258
   104
 * and use successive calling ClassLoaders to try to locate a ResourceBundle.
jaroslav@1258
   105
 * (This call stack search is to allow containers to transition to
jaroslav@1258
   106
 * using ContextClassLoaders and is likely to be removed in future
jaroslav@1258
   107
 * versions.)
jaroslav@1258
   108
 * <p>
jaroslav@1258
   109
 * Formatting (including localization) is the responsibility of
jaroslav@1258
   110
 * the output Handler, which will typically call a Formatter.
jaroslav@1258
   111
 * <p>
jaroslav@1258
   112
 * Note that formatting need not occur synchronously.  It may be delayed
jaroslav@1258
   113
 * until a LogRecord is actually written to an external sink.
jaroslav@1258
   114
 * <p>
jaroslav@1258
   115
 * The logging methods are grouped in five main categories:
jaroslav@1258
   116
 * <ul>
jaroslav@1258
   117
 * <li><p>
jaroslav@1258
   118
 *     There are a set of "log" methods that take a log level, a message
jaroslav@1258
   119
 *     string, and optionally some parameters to the message string.
jaroslav@1258
   120
 * <li><p>
jaroslav@1258
   121
 *     There are a set of "logp" methods (for "log precise") that are
jaroslav@1258
   122
 *     like the "log" methods, but also take an explicit source class name
jaroslav@1258
   123
 *     and method name.
jaroslav@1258
   124
 * <li><p>
jaroslav@1258
   125
 *     There are a set of "logrb" method (for "log with resource bundle")
jaroslav@1258
   126
 *     that are like the "logp" method, but also take an explicit resource
jaroslav@1258
   127
 *     bundle name for use in localizing the log message.
jaroslav@1258
   128
 * <li><p>
jaroslav@1258
   129
 *     There are convenience methods for tracing method entries (the
jaroslav@1258
   130
 *     "entering" methods), method returns (the "exiting" methods) and
jaroslav@1258
   131
 *     throwing exceptions (the "throwing" methods).
jaroslav@1258
   132
 * <li><p>
jaroslav@1258
   133
 *     Finally, there are a set of convenience methods for use in the
jaroslav@1258
   134
 *     very simplest cases, when a developer simply wants to log a
jaroslav@1258
   135
 *     simple string at a given log level.  These methods are named
jaroslav@1258
   136
 *     after the standard Level names ("severe", "warning", "info", etc.)
jaroslav@1258
   137
 *     and take a single argument, a message string.
jaroslav@1258
   138
 * </ul>
jaroslav@1258
   139
 * <p>
jaroslav@1258
   140
 * For the methods that do not take an explicit source name and
jaroslav@1258
   141
 * method name, the Logging framework will make a "best effort"
jaroslav@1258
   142
 * to determine which class and method called into the logging method.
jaroslav@1258
   143
 * However, it is important to realize that this automatically inferred
jaroslav@1258
   144
 * information may only be approximate (or may even be quite wrong!).
jaroslav@1258
   145
 * Virtual machines are allowed to do extensive optimizations when
jaroslav@1258
   146
 * JITing and may entirely remove stack frames, making it impossible
jaroslav@1258
   147
 * to reliably locate the calling class and method.
jaroslav@1258
   148
 * <P>
jaroslav@1258
   149
 * All methods on Logger are multi-thread safe.
jaroslav@1258
   150
 * <p>
jaroslav@1258
   151
 * <b>Subclassing Information:</b> Note that a LogManager class may
jaroslav@1258
   152
 * provide its own implementation of named Loggers for any point in
jaroslav@1258
   153
 * the namespace.  Therefore, any subclasses of Logger (unless they
jaroslav@1258
   154
 * are implemented in conjunction with a new LogManager class) should
jaroslav@1258
   155
 * take care to obtain a Logger instance from the LogManager class and
jaroslav@1258
   156
 * should delegate operations such as "isLoggable" and "log(LogRecord)"
jaroslav@1258
   157
 * to that instance.  Note that in order to intercept all logging
jaroslav@1258
   158
 * output, subclasses need only override the log(LogRecord) method.
jaroslav@1258
   159
 * All the other logging methods are implemented as calls on this
jaroslav@1258
   160
 * log(LogRecord) method.
jaroslav@1258
   161
 *
jaroslav@1258
   162
 * @since 1.4
jaroslav@1258
   163
 */
jaroslav@1258
   164
jaroslav@1258
   165
jaroslav@1258
   166
public class Logger {
jaroslav@1260
   167
    private static int offValue = Level.OFF.intValue();
jaroslav@1260
   168
    private static final Map<String,Logger> ALL = new HashMap<>();
jaroslav@1258
   169
    private String name;
jaroslav@1258
   170
jaroslav@1258
   171
    private volatile int levelValue;  // current effective level value
jaroslav@1260
   172
    private Level levelObject;
jaroslav@1260
   173
    
jaroslav@1258
   174
    /**
jaroslav@1258
   175
     * GLOBAL_LOGGER_NAME is a name for the global logger.
jaroslav@1258
   176
     *
jaroslav@1258
   177
     * @since 1.6
jaroslav@1258
   178
     */
jaroslav@1258
   179
    public static final String GLOBAL_LOGGER_NAME = "global";
jaroslav@1258
   180
jaroslav@1258
   181
    /**
jaroslav@1258
   182
     * Return global logger object with the name Logger.GLOBAL_LOGGER_NAME.
jaroslav@1258
   183
     *
jaroslav@1258
   184
     * @return global logger object
jaroslav@1258
   185
     * @since 1.7
jaroslav@1258
   186
     */
jaroslav@1258
   187
    public static final Logger getGlobal() {
jaroslav@1258
   188
        return global;
jaroslav@1258
   189
    }
jaroslav@1258
   190
jaroslav@1258
   191
    /**
jaroslav@1258
   192
     * The "global" Logger object is provided as a convenience to developers
jaroslav@1258
   193
     * who are making casual use of the Logging package.  Developers
jaroslav@1258
   194
     * who are making serious use of the logging package (for example
jaroslav@1258
   195
     * in products) should create and use their own Logger objects,
jaroslav@1258
   196
     * with appropriate names, so that logging can be controlled on a
jaroslav@1258
   197
     * suitable per-Logger granularity. Developers also need to keep a
jaroslav@1258
   198
     * strong reference to their Logger objects to prevent them from
jaroslav@1258
   199
     * being garbage collected.
jaroslav@1258
   200
     * <p>
jaroslav@1258
   201
     * @deprecated Initialization of this field is prone to deadlocks.
jaroslav@1258
   202
     * The field must be initialized by the Logger class initialization
jaroslav@1258
   203
     * which may cause deadlocks with the LogManager class initialization.
jaroslav@1258
   204
     * In such cases two class initialization wait for each other to complete.
jaroslav@1258
   205
     * The preferred way to get the global logger object is via the call
jaroslav@1258
   206
     * <code>Logger.getGlobal()</code>.
jaroslav@1258
   207
     * For compatibility with old JDK versions where the
jaroslav@1258
   208
     * <code>Logger.getGlobal()</code> is not available use the call
jaroslav@1258
   209
     * <code>Logger.getLogger(Logger.GLOBAL_LOGGER_NAME)</code>
jaroslav@1258
   210
     * or <code>Logger.getLogger("global")</code>.
jaroslav@1258
   211
     */
jaroslav@1258
   212
    @Deprecated
jaroslav@1258
   213
    public static final Logger global = new Logger(GLOBAL_LOGGER_NAME);
jaroslav@1258
   214
jaroslav@1258
   215
    /**
jaroslav@1258
   216
     * Protected method to construct a logger for a named subsystem.
jaroslav@1258
   217
     * <p>
jaroslav@1258
   218
     * The logger will be initially configured with a null Level
jaroslav@1258
   219
     * and with useParentHandlers set to true.
jaroslav@1258
   220
     *
jaroslav@1258
   221
     * @param   name    A name for the logger.  This should
jaroslav@1258
   222
     *                          be a dot-separated name and should normally
jaroslav@1258
   223
     *                          be based on the package name or class name
jaroslav@1258
   224
     *                          of the subsystem, such as java.net
jaroslav@1258
   225
     *                          or javax.swing.  It may be null for anonymous Loggers.
jaroslav@1258
   226
     * @param   resourceBundleName  name of ResourceBundle to be used for localizing
jaroslav@1258
   227
     *                          messages for this logger.  May be null if none
jaroslav@1258
   228
     *                          of the messages require localization.
jaroslav@1258
   229
     * @throws MissingResourceException if the resourceBundleName is non-null and
jaroslav@1258
   230
     *             no corresponding resource can be found.
jaroslav@1258
   231
     */
jaroslav@1258
   232
    protected Logger(String name, String resourceBundleName) {
jaroslav@1258
   233
        this.name = name;
jaroslav@1258
   234
        levelValue = Level.INFO.intValue();
jaroslav@1258
   235
    }
jaroslav@1258
   236
jaroslav@1258
   237
    // This constructor is used only to create the global Logger.
jaroslav@1258
   238
    // It is needed to break a cyclic dependence between the LogManager
jaroslav@1258
   239
    // and Logger static initializers causing deadlocks.
jaroslav@1258
   240
    private Logger(String name) {
jaroslav@1258
   241
        // The manager field is not initialized here.
jaroslav@1258
   242
        this.name = name;
jaroslav@1258
   243
        levelValue = Level.INFO.intValue();
jaroslav@1258
   244
    }
jaroslav@1258
   245
jaroslav@1258
   246
    private void checkAccess() throws SecurityException {
jaroslav@1260
   247
        throw new SecurityException();
jaroslav@1258
   248
    }
jaroslav@1258
   249
jaroslav@1258
   250
    /**
jaroslav@1258
   251
     * Find or create a logger for a named subsystem.  If a logger has
jaroslav@1258
   252
     * already been created with the given name it is returned.  Otherwise
jaroslav@1258
   253
     * a new logger is created.
jaroslav@1258
   254
     * <p>
jaroslav@1258
   255
     * If a new logger is created its log level will be configured
jaroslav@1258
   256
     * based on the LogManager configuration and it will configured
jaroslav@1258
   257
     * to also send logging output to its parent's Handlers.  It will
jaroslav@1258
   258
     * be registered in the LogManager global namespace.
jaroslav@1258
   259
     * <p>
jaroslav@1258
   260
     * Note: The LogManager may only retain a weak reference to the newly
jaroslav@1258
   261
     * created Logger. It is important to understand that a previously
jaroslav@1258
   262
     * created Logger with the given name may be garbage collected at any
jaroslav@1258
   263
     * time if there is no strong reference to the Logger. In particular,
jaroslav@1258
   264
     * this means that two back-to-back calls like
jaroslav@1258
   265
     * {@code getLogger("MyLogger").log(...)} may use different Logger
jaroslav@1258
   266
     * objects named "MyLogger" if there is no strong reference to the
jaroslav@1258
   267
     * Logger named "MyLogger" elsewhere in the program.
jaroslav@1258
   268
     *
jaroslav@1258
   269
     * @param   name            A name for the logger.  This should
jaroslav@1258
   270
     *                          be a dot-separated name and should normally
jaroslav@1258
   271
     *                          be based on the package name or class name
jaroslav@1258
   272
     *                          of the subsystem, such as java.net
jaroslav@1258
   273
     *                          or javax.swing
jaroslav@1258
   274
     * @return a suitable Logger
jaroslav@1258
   275
     * @throws NullPointerException if the name is null.
jaroslav@1258
   276
     */
jaroslav@1258
   277
jaroslav@1258
   278
    // Synchronization is not required here. All synchronization for
jaroslav@1258
   279
    // adding a new Logger object is handled by LogManager.addLogger().
jaroslav@1258
   280
    public static Logger getLogger(String name) {
jaroslav@1260
   281
        return getLogger(name, null);
jaroslav@1258
   282
    }
jaroslav@1258
   283
jaroslav@1258
   284
    /**
jaroslav@1258
   285
     * Find or create a logger for a named subsystem.  If a logger has
jaroslav@1258
   286
     * already been created with the given name it is returned.  Otherwise
jaroslav@1258
   287
     * a new logger is created.
jaroslav@1258
   288
     * <p>
jaroslav@1258
   289
     * If a new logger is created its log level will be configured
jaroslav@1258
   290
     * based on the LogManager and it will configured to also send logging
jaroslav@1258
   291
     * output to its parent's Handlers.  It will be registered in
jaroslav@1258
   292
     * the LogManager global namespace.
jaroslav@1258
   293
     * <p>
jaroslav@1258
   294
     * Note: The LogManager may only retain a weak reference to the newly
jaroslav@1258
   295
     * created Logger. It is important to understand that a previously
jaroslav@1258
   296
     * created Logger with the given name may be garbage collected at any
jaroslav@1258
   297
     * time if there is no strong reference to the Logger. In particular,
jaroslav@1258
   298
     * this means that two back-to-back calls like
jaroslav@1258
   299
     * {@code getLogger("MyLogger", ...).log(...)} may use different Logger
jaroslav@1258
   300
     * objects named "MyLogger" if there is no strong reference to the
jaroslav@1258
   301
     * Logger named "MyLogger" elsewhere in the program.
jaroslav@1258
   302
     * <p>
jaroslav@1258
   303
     * If the named Logger already exists and does not yet have a
jaroslav@1258
   304
     * localization resource bundle then the given resource bundle
jaroslav@1258
   305
     * name is used.  If the named Logger already exists and has
jaroslav@1258
   306
     * a different resource bundle name then an IllegalArgumentException
jaroslav@1258
   307
     * is thrown.
jaroslav@1258
   308
     * <p>
jaroslav@1258
   309
     * @param   name    A name for the logger.  This should
jaroslav@1258
   310
     *                          be a dot-separated name and should normally
jaroslav@1258
   311
     *                          be based on the package name or class name
jaroslav@1258
   312
     *                          of the subsystem, such as java.net
jaroslav@1258
   313
     *                          or javax.swing
jaroslav@1258
   314
     * @param   resourceBundleName  name of ResourceBundle to be used for localizing
jaroslav@1258
   315
     *                          messages for this logger. May be <CODE>null</CODE> if none of
jaroslav@1258
   316
     *                          the messages require localization.
jaroslav@1258
   317
     * @return a suitable Logger
jaroslav@1258
   318
     * @throws MissingResourceException if the resourceBundleName is non-null and
jaroslav@1258
   319
     *             no corresponding resource can be found.
jaroslav@1258
   320
     * @throws IllegalArgumentException if the Logger already exists and uses
jaroslav@1258
   321
     *             a different resource bundle name.
jaroslav@1258
   322
     * @throws NullPointerException if the name is null.
jaroslav@1258
   323
     */
jaroslav@1258
   324
jaroslav@1258
   325
    // Synchronization is not required here. All synchronization for
jaroslav@1258
   326
    // adding a new Logger object is handled by LogManager.addLogger().
jaroslav@1258
   327
    public static Logger getLogger(String name, String resourceBundleName) {
jaroslav@1260
   328
        Logger l = ALL.get(name);
jaroslav@1260
   329
        if (l == null) {
jaroslav@1260
   330
            l = new Logger(name, resourceBundleName);
jaroslav@1260
   331
            ALL.put(name, l);
jaroslav@1258
   332
        }
jaroslav@1260
   333
        return l;
jaroslav@1258
   334
    }
jaroslav@1258
   335
jaroslav@1258
   336
jaroslav@1258
   337
    /**
jaroslav@1258
   338
     * Create an anonymous Logger.  The newly created Logger is not
jaroslav@1258
   339
     * registered in the LogManager namespace.  There will be no
jaroslav@1258
   340
     * access checks on updates to the logger.
jaroslav@1258
   341
     * <p>
jaroslav@1258
   342
     * This factory method is primarily intended for use from applets.
jaroslav@1258
   343
     * Because the resulting Logger is anonymous it can be kept private
jaroslav@1258
   344
     * by the creating class.  This removes the need for normal security
jaroslav@1258
   345
     * checks, which in turn allows untrusted applet code to update
jaroslav@1258
   346
     * the control state of the Logger.  For example an applet can do
jaroslav@1258
   347
     * a setLevel or an addHandler on an anonymous Logger.
jaroslav@1258
   348
     * <p>
jaroslav@1258
   349
     * Even although the new logger is anonymous, it is configured
jaroslav@1258
   350
     * to have the root logger ("") as its parent.  This means that
jaroslav@1258
   351
     * by default it inherits its effective level and handlers
jaroslav@1258
   352
     * from the root logger.
jaroslav@1258
   353
     * <p>
jaroslav@1258
   354
     *
jaroslav@1258
   355
     * @return a newly created private Logger
jaroslav@1258
   356
     */
jaroslav@1258
   357
    public static Logger getAnonymousLogger() {
jaroslav@1258
   358
        return getAnonymousLogger(null);
jaroslav@1258
   359
    }
jaroslav@1258
   360
jaroslav@1258
   361
    /**
jaroslav@1258
   362
     * Create an anonymous Logger.  The newly created Logger is not
jaroslav@1258
   363
     * registered in the LogManager namespace.  There will be no
jaroslav@1258
   364
     * access checks on updates to the logger.
jaroslav@1258
   365
     * <p>
jaroslav@1258
   366
     * This factory method is primarily intended for use from applets.
jaroslav@1258
   367
     * Because the resulting Logger is anonymous it can be kept private
jaroslav@1258
   368
     * by the creating class.  This removes the need for normal security
jaroslav@1258
   369
     * checks, which in turn allows untrusted applet code to update
jaroslav@1258
   370
     * the control state of the Logger.  For example an applet can do
jaroslav@1258
   371
     * a setLevel or an addHandler on an anonymous Logger.
jaroslav@1258
   372
     * <p>
jaroslav@1258
   373
     * Even although the new logger is anonymous, it is configured
jaroslav@1258
   374
     * to have the root logger ("") as its parent.  This means that
jaroslav@1258
   375
     * by default it inherits its effective level and handlers
jaroslav@1258
   376
     * from the root logger.
jaroslav@1258
   377
     * <p>
jaroslav@1258
   378
     * @param   resourceBundleName  name of ResourceBundle to be used for localizing
jaroslav@1258
   379
     *                          messages for this logger.
jaroslav@1258
   380
     *          May be null if none of the messages require localization.
jaroslav@1258
   381
     * @return a newly created private Logger
jaroslav@1258
   382
     * @throws MissingResourceException if the resourceBundleName is non-null and
jaroslav@1258
   383
     *             no corresponding resource can be found.
jaroslav@1258
   384
     */
jaroslav@1258
   385
jaroslav@1258
   386
    // Synchronization is not required here. All synchronization for
jaroslav@1258
   387
    // adding a new anonymous Logger object is handled by doSetParent().
jaroslav@1258
   388
    public static Logger getAnonymousLogger(String resourceBundleName) {
jaroslav@1260
   389
        return new Logger(null, resourceBundleName);
jaroslav@1258
   390
    }
jaroslav@1258
   391
jaroslav@1258
   392
    /**
jaroslav@1258
   393
     * Retrieve the localization resource bundle for this
jaroslav@1258
   394
     * logger for the current default locale.  Note that if
jaroslav@1258
   395
     * the result is null, then the Logger will use a resource
jaroslav@1258
   396
     * bundle inherited from its parent.
jaroslav@1258
   397
     *
jaroslav@1258
   398
     * @return localization bundle (may be null)
jaroslav@1258
   399
     */
jaroslav@1260
   400
//    public ResourceBundle getResourceBundle() {
jaroslav@1260
   401
//        return findResourceBundle(getResourceBundleName());
jaroslav@1260
   402
//    }
jaroslav@1258
   403
jaroslav@1258
   404
    /**
jaroslav@1258
   405
     * Retrieve the localization resource bundle name for this
jaroslav@1258
   406
     * logger.  Note that if the result is null, then the Logger
jaroslav@1258
   407
     * will use a resource bundle name inherited from its parent.
jaroslav@1258
   408
     *
jaroslav@1258
   409
     * @return localization bundle name (may be null)
jaroslav@1258
   410
     */
jaroslav@1258
   411
    public String getResourceBundleName() {
jaroslav@1260
   412
        return null;
jaroslav@1258
   413
    }
jaroslav@1258
   414
jaroslav@1258
   415
    /**
jaroslav@1258
   416
     * Set a filter to control output on this Logger.
jaroslav@1258
   417
     * <P>
jaroslav@1258
   418
     * After passing the initial "level" check, the Logger will
jaroslav@1258
   419
     * call this Filter to check if a log record should really
jaroslav@1258
   420
     * be published.
jaroslav@1258
   421
     *
jaroslav@1258
   422
     * @param   newFilter  a filter object (may be null)
jaroslav@1258
   423
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
   424
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
   425
     */
jaroslav@1260
   426
//    public void setFilter(Filter newFilter) throws SecurityException {
jaroslav@1260
   427
//        checkAccess();
jaroslav@1260
   428
//    }
jaroslav@1258
   429
jaroslav@1258
   430
    /**
jaroslav@1258
   431
     * Get the current filter for this Logger.
jaroslav@1258
   432
     *
jaroslav@1258
   433
     * @return  a filter object (may be null)
jaroslav@1258
   434
     */
jaroslav@1260
   435
//    public Filter getFilter() {
jaroslav@1260
   436
//        return filter;
jaroslav@1260
   437
//    }
jaroslav@1258
   438
jaroslav@1258
   439
    /**
jaroslav@1258
   440
     * Log a LogRecord.
jaroslav@1258
   441
     * <p>
jaroslav@1258
   442
     * All the other logging methods in this class call through
jaroslav@1258
   443
     * this method to actually perform any logging.  Subclasses can
jaroslav@1258
   444
     * override this single method to capture all log activity.
jaroslav@1258
   445
     *
jaroslav@1258
   446
     * @param record the LogRecord to be published
jaroslav@1258
   447
     */
jaroslav@1258
   448
    public void log(LogRecord record) {
jaroslav@1260
   449
        if (record.getLevel().intValue() < levelValue) {
jaroslav@1258
   450
            return;
jaroslav@1258
   451
        }
jaroslav@1258
   452
jaroslav@1260
   453
        consoleLog(
jaroslav@1260
   454
            record.getLevel().toString(), 
jaroslav@1260
   455
            record.getLoggerName(),
jaroslav@1260
   456
            record.getMessage()
jaroslav@1260
   457
        );
jaroslav@1258
   458
    }
jaroslav@1260
   459
    
jaroslav@1260
   460
    @JavaScriptBody(args = { "method", "logger", "msg" }, body = 
jaroslav@1260
   461
        "window.console[method]('[' + logger + ']: ' + msg);"
jaroslav@1260
   462
    )
jaroslav@1260
   463
    private static native void consoleLog(
jaroslav@1260
   464
        String method, String logger, String msg
jaroslav@1260
   465
    );
jaroslav@1258
   466
jaroslav@1258
   467
    // private support method for logging.
jaroslav@1258
   468
    // We fill in the logger name, resource bundle name, and
jaroslav@1258
   469
    // resource bundle and then call "void log(LogRecord)".
jaroslav@1258
   470
    private void doLog(LogRecord lr) {
jaroslav@1260
   471
        doLog(lr, lr.getResourceBundleName());
jaroslav@1260
   472
    }
jaroslav@1260
   473
    private void doLog(LogRecord lr, String bundleName) {
jaroslav@1258
   474
        lr.setLoggerName(name);
jaroslav@1258
   475
        log(lr);
jaroslav@1258
   476
    }
jaroslav@1258
   477
jaroslav@1258
   478
jaroslav@1258
   479
    //================================================================
jaroslav@1258
   480
    // Start of convenience methods WITHOUT className and methodName
jaroslav@1258
   481
    //================================================================
jaroslav@1258
   482
jaroslav@1258
   483
    /**
jaroslav@1258
   484
     * Log a message, with no arguments.
jaroslav@1258
   485
     * <p>
jaroslav@1258
   486
     * If the logger is currently enabled for the given message
jaroslav@1258
   487
     * level then the given message is forwarded to all the
jaroslav@1258
   488
     * registered output Handler objects.
jaroslav@1258
   489
     * <p>
jaroslav@1258
   490
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   491
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   492
     */
jaroslav@1258
   493
    public void log(Level level, String msg) {
jaroslav@1258
   494
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   495
            return;
jaroslav@1258
   496
        }
jaroslav@1258
   497
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   498
        doLog(lr);
jaroslav@1258
   499
    }
jaroslav@1258
   500
jaroslav@1258
   501
    /**
jaroslav@1258
   502
     * Log a message, with one object parameter.
jaroslav@1258
   503
     * <p>
jaroslav@1258
   504
     * If the logger is currently enabled for the given message
jaroslav@1258
   505
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   506
     * to all the registered output Handler objects.
jaroslav@1258
   507
     * <p>
jaroslav@1258
   508
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   509
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   510
     * @param   param1  parameter to the message
jaroslav@1258
   511
     */
jaroslav@1258
   512
    public void log(Level level, String msg, Object param1) {
jaroslav@1258
   513
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   514
            return;
jaroslav@1258
   515
        }
jaroslav@1258
   516
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   517
        Object params[] = { param1 };
jaroslav@1258
   518
        lr.setParameters(params);
jaroslav@1258
   519
        doLog(lr);
jaroslav@1258
   520
    }
jaroslav@1258
   521
jaroslav@1258
   522
    /**
jaroslav@1258
   523
     * Log a message, with an array of object arguments.
jaroslav@1258
   524
     * <p>
jaroslav@1258
   525
     * If the logger is currently enabled for the given message
jaroslav@1258
   526
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   527
     * to all the registered output Handler objects.
jaroslav@1258
   528
     * <p>
jaroslav@1258
   529
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   530
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   531
     * @param   params  array of parameters to the message
jaroslav@1258
   532
     */
jaroslav@1258
   533
    public void log(Level level, String msg, Object params[]) {
jaroslav@1258
   534
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   535
            return;
jaroslav@1258
   536
        }
jaroslav@1258
   537
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   538
        lr.setParameters(params);
jaroslav@1258
   539
        doLog(lr);
jaroslav@1258
   540
    }
jaroslav@1258
   541
jaroslav@1258
   542
    /**
jaroslav@1258
   543
     * Log a message, with associated Throwable information.
jaroslav@1258
   544
     * <p>
jaroslav@1258
   545
     * If the logger is currently enabled for the given message
jaroslav@1258
   546
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   547
     * which is forwarded to all registered output handlers.
jaroslav@1258
   548
     * <p>
jaroslav@1258
   549
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   550
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   551
     * processed specially by output Formatters and is not treated
jaroslav@1258
   552
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   553
     * <p>
jaroslav@1258
   554
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   555
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   556
     * @param   thrown  Throwable associated with log message.
jaroslav@1258
   557
     */
jaroslav@1258
   558
    public void log(Level level, String msg, Throwable thrown) {
jaroslav@1258
   559
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   560
            return;
jaroslav@1258
   561
        }
jaroslav@1258
   562
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   563
        lr.setThrown(thrown);
jaroslav@1258
   564
        doLog(lr);
jaroslav@1258
   565
    }
jaroslav@1258
   566
jaroslav@1258
   567
    //================================================================
jaroslav@1258
   568
    // Start of convenience methods WITH className and methodName
jaroslav@1258
   569
    //================================================================
jaroslav@1258
   570
jaroslav@1258
   571
    /**
jaroslav@1258
   572
     * Log a message, specifying source class and method,
jaroslav@1258
   573
     * with no arguments.
jaroslav@1258
   574
     * <p>
jaroslav@1258
   575
     * If the logger is currently enabled for the given message
jaroslav@1258
   576
     * level then the given message is forwarded to all the
jaroslav@1258
   577
     * registered output Handler objects.
jaroslav@1258
   578
     * <p>
jaroslav@1258
   579
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   580
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   581
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   582
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   583
     */
jaroslav@1258
   584
    public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
jaroslav@1258
   585
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   586
            return;
jaroslav@1258
   587
        }
jaroslav@1258
   588
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   589
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   590
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   591
        doLog(lr);
jaroslav@1258
   592
    }
jaroslav@1258
   593
jaroslav@1258
   594
    /**
jaroslav@1258
   595
     * Log a message, specifying source class and method,
jaroslav@1258
   596
     * with a single object parameter to the log message.
jaroslav@1258
   597
     * <p>
jaroslav@1258
   598
     * If the logger is currently enabled for the given message
jaroslav@1258
   599
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   600
     * to all the registered output Handler objects.
jaroslav@1258
   601
     * <p>
jaroslav@1258
   602
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   603
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   604
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   605
     * @param   msg      The string message (or a key in the message catalog)
jaroslav@1258
   606
     * @param   param1    Parameter to the log message.
jaroslav@1258
   607
     */
jaroslav@1258
   608
    public void logp(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   609
                                                String msg, Object param1) {
jaroslav@1258
   610
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   611
            return;
jaroslav@1258
   612
        }
jaroslav@1258
   613
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   614
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   615
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   616
        Object params[] = { param1 };
jaroslav@1258
   617
        lr.setParameters(params);
jaroslav@1258
   618
        doLog(lr);
jaroslav@1258
   619
    }
jaroslav@1258
   620
jaroslav@1258
   621
    /**
jaroslav@1258
   622
     * Log a message, specifying source class and method,
jaroslav@1258
   623
     * with an array of object arguments.
jaroslav@1258
   624
     * <p>
jaroslav@1258
   625
     * If the logger is currently enabled for the given message
jaroslav@1258
   626
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   627
     * to all the registered output Handler objects.
jaroslav@1258
   628
     * <p>
jaroslav@1258
   629
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   630
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   631
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   632
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   633
     * @param   params  Array of parameters to the message
jaroslav@1258
   634
     */
jaroslav@1258
   635
    public void logp(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   636
                                                String msg, Object params[]) {
jaroslav@1258
   637
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   638
            return;
jaroslav@1258
   639
        }
jaroslav@1258
   640
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   641
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   642
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   643
        lr.setParameters(params);
jaroslav@1258
   644
        doLog(lr);
jaroslav@1258
   645
    }
jaroslav@1258
   646
jaroslav@1258
   647
    /**
jaroslav@1258
   648
     * Log a message, specifying source class and method,
jaroslav@1258
   649
     * with associated Throwable information.
jaroslav@1258
   650
     * <p>
jaroslav@1258
   651
     * If the logger is currently enabled for the given message
jaroslav@1258
   652
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   653
     * which is forwarded to all registered output handlers.
jaroslav@1258
   654
     * <p>
jaroslav@1258
   655
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   656
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   657
     * processed specially by output Formatters and is not treated
jaroslav@1258
   658
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   659
     * <p>
jaroslav@1258
   660
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   661
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   662
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   663
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   664
     * @param   thrown  Throwable associated with log message.
jaroslav@1258
   665
     */
jaroslav@1258
   666
    public void logp(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   667
                                                        String msg, Throwable thrown) {
jaroslav@1258
   668
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   669
            return;
jaroslav@1258
   670
        }
jaroslav@1258
   671
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   672
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   673
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   674
        lr.setThrown(thrown);
jaroslav@1258
   675
        doLog(lr);
jaroslav@1258
   676
    }
jaroslav@1258
   677
jaroslav@1258
   678
jaroslav@1258
   679
    //=========================================================================
jaroslav@1258
   680
    // Start of convenience methods WITH className, methodName and bundle name.
jaroslav@1258
   681
    //=========================================================================
jaroslav@1258
   682
jaroslav@1258
   683
jaroslav@1258
   684
    /**
jaroslav@1258
   685
     * Log a message, specifying source class, method, and resource bundle name
jaroslav@1258
   686
     * with no arguments.
jaroslav@1258
   687
     * <p>
jaroslav@1258
   688
     * If the logger is currently enabled for the given message
jaroslav@1258
   689
     * level then the given message is forwarded to all the
jaroslav@1258
   690
     * registered output Handler objects.
jaroslav@1258
   691
     * <p>
jaroslav@1258
   692
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   693
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   694
     * then the msg string is not localized.
jaroslav@1258
   695
     * <p>
jaroslav@1258
   696
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   697
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   698
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   699
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   700
     *                         can be null
jaroslav@1258
   701
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   702
     */
jaroslav@1258
   703
jaroslav@1258
   704
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   705
                                String bundleName, String msg) {
jaroslav@1258
   706
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   707
            return;
jaroslav@1258
   708
        }
jaroslav@1258
   709
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   710
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   711
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   712
        doLog(lr, bundleName);
jaroslav@1258
   713
    }
jaroslav@1258
   714
jaroslav@1258
   715
    /**
jaroslav@1258
   716
     * Log a message, specifying source class, method, and resource bundle name,
jaroslav@1258
   717
     * with a single object parameter to the log message.
jaroslav@1258
   718
     * <p>
jaroslav@1258
   719
     * If the logger is currently enabled for the given message
jaroslav@1258
   720
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   721
     * to all the registered output Handler objects.
jaroslav@1258
   722
     * <p>
jaroslav@1258
   723
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   724
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   725
     * then the msg string is not localized.
jaroslav@1258
   726
     * <p>
jaroslav@1258
   727
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   728
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   729
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   730
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   731
     *                         can be null
jaroslav@1258
   732
     * @param   msg      The string message (or a key in the message catalog)
jaroslav@1258
   733
     * @param   param1    Parameter to the log message.
jaroslav@1258
   734
     */
jaroslav@1258
   735
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   736
                                String bundleName, String msg, Object param1) {
jaroslav@1258
   737
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   738
            return;
jaroslav@1258
   739
        }
jaroslav@1258
   740
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   741
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   742
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   743
        Object params[] = { param1 };
jaroslav@1258
   744
        lr.setParameters(params);
jaroslav@1258
   745
        doLog(lr, bundleName);
jaroslav@1258
   746
    }
jaroslav@1258
   747
jaroslav@1258
   748
    /**
jaroslav@1258
   749
     * Log a message, specifying source class, method, and resource bundle name,
jaroslav@1258
   750
     * with an array of object arguments.
jaroslav@1258
   751
     * <p>
jaroslav@1258
   752
     * If the logger is currently enabled for the given message
jaroslav@1258
   753
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   754
     * to all the registered output Handler objects.
jaroslav@1258
   755
     * <p>
jaroslav@1258
   756
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   757
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   758
     * then the msg string is not localized.
jaroslav@1258
   759
     * <p>
jaroslav@1258
   760
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   761
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   762
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   763
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   764
     *                         can be null.
jaroslav@1258
   765
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   766
     * @param   params  Array of parameters to the message
jaroslav@1258
   767
     */
jaroslav@1258
   768
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   769
                                String bundleName, String msg, Object params[]) {
jaroslav@1258
   770
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   771
            return;
jaroslav@1258
   772
        }
jaroslav@1258
   773
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   774
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   775
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   776
        lr.setParameters(params);
jaroslav@1258
   777
        doLog(lr, bundleName);
jaroslav@1258
   778
    }
jaroslav@1258
   779
jaroslav@1258
   780
    /**
jaroslav@1258
   781
     * Log a message, specifying source class, method, and resource bundle name,
jaroslav@1258
   782
     * with associated Throwable information.
jaroslav@1258
   783
     * <p>
jaroslav@1258
   784
     * If the logger is currently enabled for the given message
jaroslav@1258
   785
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   786
     * which is forwarded to all registered output handlers.
jaroslav@1258
   787
     * <p>
jaroslav@1258
   788
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   789
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   790
     * then the msg string is not localized.
jaroslav@1258
   791
     * <p>
jaroslav@1258
   792
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   793
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   794
     * processed specially by output Formatters and is not treated
jaroslav@1258
   795
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   796
     * <p>
jaroslav@1258
   797
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   798
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   799
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   800
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   801
     *                         can be null
jaroslav@1258
   802
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   803
     * @param   thrown  Throwable associated with log message.
jaroslav@1258
   804
     */
jaroslav@1258
   805
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   806
                                        String bundleName, String msg, Throwable thrown) {
jaroslav@1258
   807
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   808
            return;
jaroslav@1258
   809
        }
jaroslav@1258
   810
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   811
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   812
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   813
        lr.setThrown(thrown);
jaroslav@1258
   814
        doLog(lr, bundleName);
jaroslav@1258
   815
    }
jaroslav@1258
   816
jaroslav@1258
   817
jaroslav@1258
   818
    //======================================================================
jaroslav@1258
   819
    // Start of convenience methods for logging method entries and returns.
jaroslav@1258
   820
    //======================================================================
jaroslav@1258
   821
jaroslav@1258
   822
    /**
jaroslav@1258
   823
     * Log a method entry.
jaroslav@1258
   824
     * <p>
jaroslav@1258
   825
     * This is a convenience method that can be used to log entry
jaroslav@1258
   826
     * to a method.  A LogRecord with message "ENTRY", log level
jaroslav@1258
   827
     * FINER, and the given sourceMethod and sourceClass is logged.
jaroslav@1258
   828
     * <p>
jaroslav@1258
   829
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   830
     * @param   sourceMethod   name of method that is being entered
jaroslav@1258
   831
     */
jaroslav@1258
   832
    public void entering(String sourceClass, String sourceMethod) {
jaroslav@1258
   833
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   834
            return;
jaroslav@1258
   835
        }
jaroslav@1258
   836
        logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
jaroslav@1258
   837
    }
jaroslav@1258
   838
jaroslav@1258
   839
    /**
jaroslav@1258
   840
     * Log a method entry, with one parameter.
jaroslav@1258
   841
     * <p>
jaroslav@1258
   842
     * This is a convenience method that can be used to log entry
jaroslav@1258
   843
     * to a method.  A LogRecord with message "ENTRY {0}", log level
jaroslav@1258
   844
     * FINER, and the given sourceMethod, sourceClass, and parameter
jaroslav@1258
   845
     * is logged.
jaroslav@1258
   846
     * <p>
jaroslav@1258
   847
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   848
     * @param   sourceMethod   name of method that is being entered
jaroslav@1258
   849
     * @param   param1         parameter to the method being entered
jaroslav@1258
   850
     */
jaroslav@1258
   851
    public void entering(String sourceClass, String sourceMethod, Object param1) {
jaroslav@1258
   852
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   853
            return;
jaroslav@1258
   854
        }
jaroslav@1258
   855
        Object params[] = { param1 };
jaroslav@1258
   856
        logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
jaroslav@1258
   857
    }
jaroslav@1258
   858
jaroslav@1258
   859
    /**
jaroslav@1258
   860
     * Log a method entry, with an array of parameters.
jaroslav@1258
   861
     * <p>
jaroslav@1258
   862
     * This is a convenience method that can be used to log entry
jaroslav@1258
   863
     * to a method.  A LogRecord with message "ENTRY" (followed by a
jaroslav@1258
   864
     * format {N} indicator for each entry in the parameter array),
jaroslav@1258
   865
     * log level FINER, and the given sourceMethod, sourceClass, and
jaroslav@1258
   866
     * parameters is logged.
jaroslav@1258
   867
     * <p>
jaroslav@1258
   868
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   869
     * @param   sourceMethod   name of method that is being entered
jaroslav@1258
   870
     * @param   params         array of parameters to the method being entered
jaroslav@1258
   871
     */
jaroslav@1258
   872
    public void entering(String sourceClass, String sourceMethod, Object params[]) {
jaroslav@1258
   873
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   874
            return;
jaroslav@1258
   875
        }
jaroslav@1258
   876
        String msg = "ENTRY";
jaroslav@1258
   877
        if (params == null ) {
jaroslav@1258
   878
           logp(Level.FINER, sourceClass, sourceMethod, msg);
jaroslav@1258
   879
           return;
jaroslav@1258
   880
        }
jaroslav@1258
   881
        for (int i = 0; i < params.length; i++) {
jaroslav@1258
   882
            msg = msg + " {" + i + "}";
jaroslav@1258
   883
        }
jaroslav@1258
   884
        logp(Level.FINER, sourceClass, sourceMethod, msg, params);
jaroslav@1258
   885
    }
jaroslav@1258
   886
jaroslav@1258
   887
    /**
jaroslav@1258
   888
     * Log a method return.
jaroslav@1258
   889
     * <p>
jaroslav@1258
   890
     * This is a convenience method that can be used to log returning
jaroslav@1258
   891
     * from a method.  A LogRecord with message "RETURN", log level
jaroslav@1258
   892
     * FINER, and the given sourceMethod and sourceClass is logged.
jaroslav@1258
   893
     * <p>
jaroslav@1258
   894
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   895
     * @param   sourceMethod   name of the method
jaroslav@1258
   896
     */
jaroslav@1258
   897
    public void exiting(String sourceClass, String sourceMethod) {
jaroslav@1258
   898
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   899
            return;
jaroslav@1258
   900
        }
jaroslav@1258
   901
        logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
jaroslav@1258
   902
    }
jaroslav@1258
   903
jaroslav@1258
   904
jaroslav@1258
   905
    /**
jaroslav@1258
   906
     * Log a method return, with result object.
jaroslav@1258
   907
     * <p>
jaroslav@1258
   908
     * This is a convenience method that can be used to log returning
jaroslav@1258
   909
     * from a method.  A LogRecord with message "RETURN {0}", log level
jaroslav@1258
   910
     * FINER, and the gives sourceMethod, sourceClass, and result
jaroslav@1258
   911
     * object is logged.
jaroslav@1258
   912
     * <p>
jaroslav@1258
   913
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   914
     * @param   sourceMethod   name of the method
jaroslav@1258
   915
     * @param   result  Object that is being returned
jaroslav@1258
   916
     */
jaroslav@1258
   917
    public void exiting(String sourceClass, String sourceMethod, Object result) {
jaroslav@1258
   918
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   919
            return;
jaroslav@1258
   920
        }
jaroslav@1258
   921
        Object params[] = { result };
jaroslav@1258
   922
        logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result);
jaroslav@1258
   923
    }
jaroslav@1258
   924
jaroslav@1258
   925
    /**
jaroslav@1258
   926
     * Log throwing an exception.
jaroslav@1258
   927
     * <p>
jaroslav@1258
   928
     * This is a convenience method to log that a method is
jaroslav@1258
   929
     * terminating by throwing an exception.  The logging is done
jaroslav@1258
   930
     * using the FINER level.
jaroslav@1258
   931
     * <p>
jaroslav@1258
   932
     * If the logger is currently enabled for the given message
jaroslav@1258
   933
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   934
     * which is forwarded to all registered output handlers.  The
jaroslav@1258
   935
     * LogRecord's message is set to "THROW".
jaroslav@1258
   936
     * <p>
jaroslav@1258
   937
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   938
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   939
     * processed specially by output Formatters and is not treated
jaroslav@1258
   940
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   941
     * <p>
jaroslav@1258
   942
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   943
     * @param   sourceMethod  name of the method.
jaroslav@1258
   944
     * @param   thrown  The Throwable that is being thrown.
jaroslav@1258
   945
     */
jaroslav@1258
   946
    public void throwing(String sourceClass, String sourceMethod, Throwable thrown) {
jaroslav@1258
   947
        if (Level.FINER.intValue() < levelValue || levelValue == offValue ) {
jaroslav@1258
   948
            return;
jaroslav@1258
   949
        }
jaroslav@1258
   950
        LogRecord lr = new LogRecord(Level.FINER, "THROW");
jaroslav@1258
   951
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   952
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   953
        lr.setThrown(thrown);
jaroslav@1258
   954
        doLog(lr);
jaroslav@1258
   955
    }
jaroslav@1258
   956
jaroslav@1258
   957
    //=======================================================================
jaroslav@1258
   958
    // Start of simple convenience methods using level names as method names
jaroslav@1258
   959
    //=======================================================================
jaroslav@1258
   960
jaroslav@1258
   961
    /**
jaroslav@1258
   962
     * Log a SEVERE message.
jaroslav@1258
   963
     * <p>
jaroslav@1258
   964
     * If the logger is currently enabled for the SEVERE message
jaroslav@1258
   965
     * level then the given message is forwarded to all the
jaroslav@1258
   966
     * registered output Handler objects.
jaroslav@1258
   967
     * <p>
jaroslav@1258
   968
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   969
     */
jaroslav@1258
   970
    public void severe(String msg) {
jaroslav@1258
   971
        if (Level.SEVERE.intValue() < levelValue) {
jaroslav@1258
   972
            return;
jaroslav@1258
   973
        }
jaroslav@1258
   974
        log(Level.SEVERE, msg);
jaroslav@1258
   975
    }
jaroslav@1258
   976
jaroslav@1258
   977
    /**
jaroslav@1258
   978
     * Log a WARNING message.
jaroslav@1258
   979
     * <p>
jaroslav@1258
   980
     * If the logger is currently enabled for the WARNING message
jaroslav@1258
   981
     * level then the given message is forwarded to all the
jaroslav@1258
   982
     * registered output Handler objects.
jaroslav@1258
   983
     * <p>
jaroslav@1258
   984
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   985
     */
jaroslav@1258
   986
    public void warning(String msg) {
jaroslav@1258
   987
        if (Level.WARNING.intValue() < levelValue) {
jaroslav@1258
   988
            return;
jaroslav@1258
   989
        }
jaroslav@1258
   990
        log(Level.WARNING, msg);
jaroslav@1258
   991
    }
jaroslav@1258
   992
jaroslav@1258
   993
    /**
jaroslav@1258
   994
     * Log an INFO message.
jaroslav@1258
   995
     * <p>
jaroslav@1258
   996
     * If the logger is currently enabled for the INFO message
jaroslav@1258
   997
     * level then the given message is forwarded to all the
jaroslav@1258
   998
     * registered output Handler objects.
jaroslav@1258
   999
     * <p>
jaroslav@1258
  1000
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1001
     */
jaroslav@1258
  1002
    public void info(String msg) {
jaroslav@1258
  1003
        if (Level.INFO.intValue() < levelValue) {
jaroslav@1258
  1004
            return;
jaroslav@1258
  1005
        }
jaroslav@1258
  1006
        log(Level.INFO, msg);
jaroslav@1258
  1007
    }
jaroslav@1258
  1008
jaroslav@1258
  1009
    /**
jaroslav@1258
  1010
     * Log a CONFIG message.
jaroslav@1258
  1011
     * <p>
jaroslav@1258
  1012
     * If the logger is currently enabled for the CONFIG message
jaroslav@1258
  1013
     * level then the given message is forwarded to all the
jaroslav@1258
  1014
     * registered output Handler objects.
jaroslav@1258
  1015
     * <p>
jaroslav@1258
  1016
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1017
     */
jaroslav@1258
  1018
    public void config(String msg) {
jaroslav@1258
  1019
        if (Level.CONFIG.intValue() < levelValue) {
jaroslav@1258
  1020
            return;
jaroslav@1258
  1021
        }
jaroslav@1258
  1022
        log(Level.CONFIG, msg);
jaroslav@1258
  1023
    }
jaroslav@1258
  1024
jaroslav@1258
  1025
    /**
jaroslav@1258
  1026
     * Log a FINE message.
jaroslav@1258
  1027
     * <p>
jaroslav@1258
  1028
     * If the logger is currently enabled for the FINE message
jaroslav@1258
  1029
     * level then the given message is forwarded to all the
jaroslav@1258
  1030
     * registered output Handler objects.
jaroslav@1258
  1031
     * <p>
jaroslav@1258
  1032
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1033
     */
jaroslav@1258
  1034
    public void fine(String msg) {
jaroslav@1258
  1035
        if (Level.FINE.intValue() < levelValue) {
jaroslav@1258
  1036
            return;
jaroslav@1258
  1037
        }
jaroslav@1258
  1038
        log(Level.FINE, msg);
jaroslav@1258
  1039
    }
jaroslav@1258
  1040
jaroslav@1258
  1041
    /**
jaroslav@1258
  1042
     * Log a FINER message.
jaroslav@1258
  1043
     * <p>
jaroslav@1258
  1044
     * If the logger is currently enabled for the FINER message
jaroslav@1258
  1045
     * level then the given message is forwarded to all the
jaroslav@1258
  1046
     * registered output Handler objects.
jaroslav@1258
  1047
     * <p>
jaroslav@1258
  1048
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1049
     */
jaroslav@1258
  1050
    public void finer(String msg) {
jaroslav@1258
  1051
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
  1052
            return;
jaroslav@1258
  1053
        }
jaroslav@1258
  1054
        log(Level.FINER, msg);
jaroslav@1258
  1055
    }
jaroslav@1258
  1056
jaroslav@1258
  1057
    /**
jaroslav@1258
  1058
     * Log a FINEST message.
jaroslav@1258
  1059
     * <p>
jaroslav@1258
  1060
     * If the logger is currently enabled for the FINEST message
jaroslav@1258
  1061
     * level then the given message is forwarded to all the
jaroslav@1258
  1062
     * registered output Handler objects.
jaroslav@1258
  1063
     * <p>
jaroslav@1258
  1064
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1065
     */
jaroslav@1258
  1066
    public void finest(String msg) {
jaroslav@1258
  1067
        if (Level.FINEST.intValue() < levelValue) {
jaroslav@1258
  1068
            return;
jaroslav@1258
  1069
        }
jaroslav@1258
  1070
        log(Level.FINEST, msg);
jaroslav@1258
  1071
    }
jaroslav@1258
  1072
jaroslav@1258
  1073
    //================================================================
jaroslav@1258
  1074
    // End of convenience methods
jaroslav@1258
  1075
    //================================================================
jaroslav@1258
  1076
jaroslav@1258
  1077
    /**
jaroslav@1258
  1078
     * Set the log level specifying which message levels will be
jaroslav@1258
  1079
     * logged by this logger.  Message levels lower than this
jaroslav@1258
  1080
     * value will be discarded.  The level value Level.OFF
jaroslav@1258
  1081
     * can be used to turn off logging.
jaroslav@1258
  1082
     * <p>
jaroslav@1258
  1083
     * If the new level is null, it means that this node should
jaroslav@1258
  1084
     * inherit its level from its nearest ancestor with a specific
jaroslav@1258
  1085
     * (non-null) level value.
jaroslav@1258
  1086
     *
jaroslav@1258
  1087
     * @param newLevel   the new value for the log level (may be null)
jaroslav@1258
  1088
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1089
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1090
     */
jaroslav@1258
  1091
    public void setLevel(Level newLevel) throws SecurityException {
jaroslav@1260
  1092
        levelValue = newLevel.intValue();
jaroslav@1260
  1093
        levelObject = newLevel;
jaroslav@1258
  1094
    }
jaroslav@1258
  1095
jaroslav@1258
  1096
    /**
jaroslav@1258
  1097
     * Get the log Level that has been specified for this Logger.
jaroslav@1258
  1098
     * The result may be null, which means that this logger's
jaroslav@1258
  1099
     * effective level will be inherited from its parent.
jaroslav@1258
  1100
     *
jaroslav@1258
  1101
     * @return  this Logger's level
jaroslav@1258
  1102
     */
jaroslav@1258
  1103
    public Level getLevel() {
jaroslav@1258
  1104
        return levelObject;
jaroslav@1258
  1105
    }
jaroslav@1258
  1106
jaroslav@1258
  1107
    /**
jaroslav@1258
  1108
     * Check if a message of the given level would actually be logged
jaroslav@1258
  1109
     * by this logger.  This check is based on the Loggers effective level,
jaroslav@1258
  1110
     * which may be inherited from its parent.
jaroslav@1258
  1111
     *
jaroslav@1258
  1112
     * @param   level   a message logging level
jaroslav@1258
  1113
     * @return  true if the given message level is currently being logged.
jaroslav@1258
  1114
     */
jaroslav@1258
  1115
    public boolean isLoggable(Level level) {
jaroslav@1258
  1116
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
  1117
            return false;
jaroslav@1258
  1118
        }
jaroslav@1258
  1119
        return true;
jaroslav@1258
  1120
    }
jaroslav@1258
  1121
jaroslav@1258
  1122
    /**
jaroslav@1258
  1123
     * Get the name for this logger.
jaroslav@1258
  1124
     * @return logger name.  Will be null for anonymous Loggers.
jaroslav@1258
  1125
     */
jaroslav@1258
  1126
    public String getName() {
jaroslav@1258
  1127
        return name;
jaroslav@1258
  1128
    }
jaroslav@1258
  1129
jaroslav@1258
  1130
    /**
jaroslav@1258
  1131
     * Add a log Handler to receive logging messages.
jaroslav@1258
  1132
     * <p>
jaroslav@1258
  1133
     * By default, Loggers also send their output to their parent logger.
jaroslav@1258
  1134
     * Typically the root Logger is configured with a set of Handlers
jaroslav@1258
  1135
     * that essentially act as default handlers for all loggers.
jaroslav@1258
  1136
     *
jaroslav@1258
  1137
     * @param   handler a logging Handler
jaroslav@1258
  1138
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1139
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1140
     */
jaroslav@1260
  1141
//    public void addHandler(Handler handler) throws SecurityException {
jaroslav@1260
  1142
//        // Check for null handler
jaroslav@1260
  1143
//        handler.getClass();
jaroslav@1260
  1144
//        checkAccess();
jaroslav@1260
  1145
//        handlers.add(handler);
jaroslav@1260
  1146
//    }
jaroslav@1258
  1147
jaroslav@1258
  1148
    /**
jaroslav@1258
  1149
     * Remove a log Handler.
jaroslav@1258
  1150
     * <P>
jaroslav@1258
  1151
     * Returns silently if the given Handler is not found or is null
jaroslav@1258
  1152
     *
jaroslav@1258
  1153
     * @param   handler a logging Handler
jaroslav@1258
  1154
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1155
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1156
     */
jaroslav@1260
  1157
//    public void removeHandler(Handler handler) throws SecurityException {
jaroslav@1260
  1158
//        checkAccess();
jaroslav@1260
  1159
//        if (handler == null) {
jaroslav@1260
  1160
//            return;
jaroslav@1260
  1161
//        }
jaroslav@1260
  1162
//        handlers.remove(handler);
jaroslav@1260
  1163
//    }
jaroslav@1258
  1164
jaroslav@1258
  1165
    /**
jaroslav@1258
  1166
     * Get the Handlers associated with this logger.
jaroslav@1258
  1167
     * <p>
jaroslav@1258
  1168
     * @return  an array of all registered Handlers
jaroslav@1258
  1169
     */
jaroslav@1260
  1170
//    public Handler[] getHandlers() {
jaroslav@1260
  1171
//        return handlers.toArray(emptyHandlers);
jaroslav@1260
  1172
//    }
jaroslav@1258
  1173
jaroslav@1258
  1174
    /**
jaroslav@1258
  1175
     * Specify whether or not this logger should send its output
jaroslav@1258
  1176
     * to its parent Logger.  This means that any LogRecords will
jaroslav@1258
  1177
     * also be written to the parent's Handlers, and potentially
jaroslav@1258
  1178
     * to its parent, recursively up the namespace.
jaroslav@1258
  1179
     *
jaroslav@1258
  1180
     * @param useParentHandlers   true if output is to be sent to the
jaroslav@1258
  1181
     *          logger's parent.
jaroslav@1258
  1182
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1183
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1184
     */
jaroslav@1258
  1185
    public void setUseParentHandlers(boolean useParentHandlers) {
jaroslav@1258
  1186
        checkAccess();
jaroslav@1258
  1187
    }
jaroslav@1258
  1188
jaroslav@1258
  1189
    /**
jaroslav@1258
  1190
     * Discover whether or not this logger is sending its output
jaroslav@1258
  1191
     * to its parent logger.
jaroslav@1258
  1192
     *
jaroslav@1258
  1193
     * @return  true if output is to be sent to the logger's parent
jaroslav@1258
  1194
     */
jaroslav@1258
  1195
    public boolean getUseParentHandlers() {
jaroslav@1260
  1196
        return true;
jaroslav@1258
  1197
    }
jaroslav@1258
  1198
jaroslav@1258
  1199
    /**
jaroslav@1258
  1200
     * Return the parent for this Logger.
jaroslav@1258
  1201
     * <p>
jaroslav@1258
  1202
     * This method returns the nearest extant parent in the namespace.
jaroslav@1258
  1203
     * Thus if a Logger is called "a.b.c.d", and a Logger called "a.b"
jaroslav@1258
  1204
     * has been created but no logger "a.b.c" exists, then a call of
jaroslav@1258
  1205
     * getParent on the Logger "a.b.c.d" will return the Logger "a.b".
jaroslav@1258
  1206
     * <p>
jaroslav@1258
  1207
     * The result will be null if it is called on the root Logger
jaroslav@1258
  1208
     * in the namespace.
jaroslav@1258
  1209
     *
jaroslav@1258
  1210
     * @return nearest existing parent Logger
jaroslav@1258
  1211
     */
jaroslav@1258
  1212
    public Logger getParent() {
jaroslav@1258
  1213
        // Note: this used to be synchronized on treeLock.  However, this only
jaroslav@1258
  1214
        // provided memory semantics, as there was no guarantee that the caller
jaroslav@1258
  1215
        // would synchronize on treeLock (in fact, there is no way for external
jaroslav@1258
  1216
        // callers to so synchronize).  Therefore, we have made parent volatile
jaroslav@1258
  1217
        // instead.
jaroslav@1260
  1218
        String n = getName();
jaroslav@1260
  1219
        int at = n.length();
jaroslav@1260
  1220
        for (;;) {
jaroslav@1260
  1221
            int last = n.lastIndexOf('.', at - 1);
jaroslav@1260
  1222
            if (last == -1) {
jaroslav@1260
  1223
                return getGlobal();
jaroslav@1260
  1224
            }
jaroslav@1260
  1225
            Logger p = ALL.get(n.substring(0, last));
jaroslav@1260
  1226
            if (p != null) {
jaroslav@1260
  1227
                return p;
jaroslav@1260
  1228
            }
jaroslav@1260
  1229
            at = last;
jaroslav@1260
  1230
        }
jaroslav@1258
  1231
    }
jaroslav@1258
  1232
jaroslav@1258
  1233
    /**
jaroslav@1258
  1234
     * Set the parent for this Logger.  This method is used by
jaroslav@1258
  1235
     * the LogManager to update a Logger when the namespace changes.
jaroslav@1258
  1236
     * <p>
jaroslav@1258
  1237
     * It should not be called from application code.
jaroslav@1258
  1238
     * <p>
jaroslav@1258
  1239
     * @param  parent   the new parent logger
jaroslav@1258
  1240
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1241
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1242
     */
jaroslav@1258
  1243
    public void setParent(Logger parent) {
jaroslav@1258
  1244
        if (parent == null) {
jaroslav@1258
  1245
            throw new NullPointerException();
jaroslav@1258
  1246
        }
jaroslav@1260
  1247
        checkAccess();
jaroslav@1258
  1248
    }
jaroslav@1258
  1249
jaroslav@1258
  1250
}