rt/emul/compact/src/main/java/java/util/logging/Logger.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 10 Sep 2013 15:39:33 +0200
changeset 1277 853245102164
parent 1260 fe3567c7b522
child 1355 ae20214a816c
permissions -rw-r--r--
Convert the Level names to names of methods on console object
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@1277
   452
        
jaroslav@1277
   453
        String method;
jaroslav@1277
   454
        switch (record.getLevel().toString()) {
jaroslav@1277
   455
            case "INFO": method = "info";  break;
jaroslav@1277
   456
            case "SEVERE": method = "error"; break;
jaroslav@1277
   457
            case "WARNING": method = "warn"; break;
jaroslav@1277
   458
            default: method = "log"; break;
jaroslav@1277
   459
        }
jaroslav@1258
   460
jaroslav@1260
   461
        consoleLog(
jaroslav@1277
   462
            method, 
jaroslav@1260
   463
            record.getLoggerName(),
jaroslav@1260
   464
            record.getMessage()
jaroslav@1260
   465
        );
jaroslav@1258
   466
    }
jaroslav@1260
   467
    
jaroslav@1260
   468
    @JavaScriptBody(args = { "method", "logger", "msg" }, body = 
jaroslav@1260
   469
        "window.console[method]('[' + logger + ']: ' + msg);"
jaroslav@1260
   470
    )
jaroslav@1260
   471
    private static native void consoleLog(
jaroslav@1260
   472
        String method, String logger, String msg
jaroslav@1260
   473
    );
jaroslav@1258
   474
jaroslav@1258
   475
    // private support method for logging.
jaroslav@1258
   476
    // We fill in the logger name, resource bundle name, and
jaroslav@1258
   477
    // resource bundle and then call "void log(LogRecord)".
jaroslav@1258
   478
    private void doLog(LogRecord lr) {
jaroslav@1260
   479
        doLog(lr, lr.getResourceBundleName());
jaroslav@1260
   480
    }
jaroslav@1260
   481
    private void doLog(LogRecord lr, String bundleName) {
jaroslav@1258
   482
        lr.setLoggerName(name);
jaroslav@1258
   483
        log(lr);
jaroslav@1258
   484
    }
jaroslav@1258
   485
jaroslav@1258
   486
jaroslav@1258
   487
    //================================================================
jaroslav@1258
   488
    // Start of convenience methods WITHOUT className and methodName
jaroslav@1258
   489
    //================================================================
jaroslav@1258
   490
jaroslav@1258
   491
    /**
jaroslav@1258
   492
     * Log a message, with no arguments.
jaroslav@1258
   493
     * <p>
jaroslav@1258
   494
     * If the logger is currently enabled for the given message
jaroslav@1258
   495
     * level then the given message is forwarded to all the
jaroslav@1258
   496
     * registered output Handler objects.
jaroslav@1258
   497
     * <p>
jaroslav@1258
   498
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   499
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   500
     */
jaroslav@1258
   501
    public void log(Level level, String msg) {
jaroslav@1258
   502
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   503
            return;
jaroslav@1258
   504
        }
jaroslav@1258
   505
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   506
        doLog(lr);
jaroslav@1258
   507
    }
jaroslav@1258
   508
jaroslav@1258
   509
    /**
jaroslav@1258
   510
     * Log a message, with one object parameter.
jaroslav@1258
   511
     * <p>
jaroslav@1258
   512
     * If the logger is currently enabled for the given message
jaroslav@1258
   513
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   514
     * to all the registered output Handler objects.
jaroslav@1258
   515
     * <p>
jaroslav@1258
   516
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   517
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   518
     * @param   param1  parameter to the message
jaroslav@1258
   519
     */
jaroslav@1258
   520
    public void log(Level level, String msg, Object param1) {
jaroslav@1258
   521
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   522
            return;
jaroslav@1258
   523
        }
jaroslav@1258
   524
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   525
        Object params[] = { param1 };
jaroslav@1258
   526
        lr.setParameters(params);
jaroslav@1258
   527
        doLog(lr);
jaroslav@1258
   528
    }
jaroslav@1258
   529
jaroslav@1258
   530
    /**
jaroslav@1258
   531
     * Log a message, with an array of object arguments.
jaroslav@1258
   532
     * <p>
jaroslav@1258
   533
     * If the logger is currently enabled for the given message
jaroslav@1258
   534
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   535
     * to all the registered output Handler objects.
jaroslav@1258
   536
     * <p>
jaroslav@1258
   537
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   538
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   539
     * @param   params  array of parameters to the message
jaroslav@1258
   540
     */
jaroslav@1258
   541
    public void log(Level level, String msg, Object params[]) {
jaroslav@1258
   542
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   543
            return;
jaroslav@1258
   544
        }
jaroslav@1258
   545
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   546
        lr.setParameters(params);
jaroslav@1258
   547
        doLog(lr);
jaroslav@1258
   548
    }
jaroslav@1258
   549
jaroslav@1258
   550
    /**
jaroslav@1258
   551
     * Log a message, with associated Throwable information.
jaroslav@1258
   552
     * <p>
jaroslav@1258
   553
     * If the logger is currently enabled for the given message
jaroslav@1258
   554
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   555
     * which is forwarded to all registered output handlers.
jaroslav@1258
   556
     * <p>
jaroslav@1258
   557
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   558
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   559
     * processed specially by output Formatters and is not treated
jaroslav@1258
   560
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   561
     * <p>
jaroslav@1258
   562
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   563
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   564
     * @param   thrown  Throwable associated with log message.
jaroslav@1258
   565
     */
jaroslav@1258
   566
    public void log(Level level, String msg, Throwable thrown) {
jaroslav@1258
   567
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   568
            return;
jaroslav@1258
   569
        }
jaroslav@1258
   570
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   571
        lr.setThrown(thrown);
jaroslav@1258
   572
        doLog(lr);
jaroslav@1258
   573
    }
jaroslav@1258
   574
jaroslav@1258
   575
    //================================================================
jaroslav@1258
   576
    // Start of convenience methods WITH className and methodName
jaroslav@1258
   577
    //================================================================
jaroslav@1258
   578
jaroslav@1258
   579
    /**
jaroslav@1258
   580
     * Log a message, specifying source class and method,
jaroslav@1258
   581
     * with no arguments.
jaroslav@1258
   582
     * <p>
jaroslav@1258
   583
     * If the logger is currently enabled for the given message
jaroslav@1258
   584
     * level then the given message is forwarded to all the
jaroslav@1258
   585
     * registered output Handler objects.
jaroslav@1258
   586
     * <p>
jaroslav@1258
   587
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   588
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   589
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   590
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   591
     */
jaroslav@1258
   592
    public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
jaroslav@1258
   593
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   594
            return;
jaroslav@1258
   595
        }
jaroslav@1258
   596
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   597
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   598
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   599
        doLog(lr);
jaroslav@1258
   600
    }
jaroslav@1258
   601
jaroslav@1258
   602
    /**
jaroslav@1258
   603
     * Log a message, specifying source class and method,
jaroslav@1258
   604
     * with a single object parameter to the log message.
jaroslav@1258
   605
     * <p>
jaroslav@1258
   606
     * If the logger is currently enabled for the given message
jaroslav@1258
   607
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   608
     * to all the registered output Handler objects.
jaroslav@1258
   609
     * <p>
jaroslav@1258
   610
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   611
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   612
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   613
     * @param   msg      The string message (or a key in the message catalog)
jaroslav@1258
   614
     * @param   param1    Parameter to the log message.
jaroslav@1258
   615
     */
jaroslav@1258
   616
    public void logp(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   617
                                                String msg, Object param1) {
jaroslav@1258
   618
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   619
            return;
jaroslav@1258
   620
        }
jaroslav@1258
   621
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   622
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   623
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   624
        Object params[] = { param1 };
jaroslav@1258
   625
        lr.setParameters(params);
jaroslav@1258
   626
        doLog(lr);
jaroslav@1258
   627
    }
jaroslav@1258
   628
jaroslav@1258
   629
    /**
jaroslav@1258
   630
     * Log a message, specifying source class and method,
jaroslav@1258
   631
     * with an array of object arguments.
jaroslav@1258
   632
     * <p>
jaroslav@1258
   633
     * If the logger is currently enabled for the given message
jaroslav@1258
   634
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   635
     * to all the registered output Handler objects.
jaroslav@1258
   636
     * <p>
jaroslav@1258
   637
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   638
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   639
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   640
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   641
     * @param   params  Array of parameters to the message
jaroslav@1258
   642
     */
jaroslav@1258
   643
    public void logp(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   644
                                                String msg, Object params[]) {
jaroslav@1258
   645
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   646
            return;
jaroslav@1258
   647
        }
jaroslav@1258
   648
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   649
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   650
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   651
        lr.setParameters(params);
jaroslav@1258
   652
        doLog(lr);
jaroslav@1258
   653
    }
jaroslav@1258
   654
jaroslav@1258
   655
    /**
jaroslav@1258
   656
     * Log a message, specifying source class and method,
jaroslav@1258
   657
     * with associated Throwable information.
jaroslav@1258
   658
     * <p>
jaroslav@1258
   659
     * If the logger is currently enabled for the given message
jaroslav@1258
   660
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   661
     * which is forwarded to all registered output handlers.
jaroslav@1258
   662
     * <p>
jaroslav@1258
   663
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   664
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   665
     * processed specially by output Formatters and is not treated
jaroslav@1258
   666
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   667
     * <p>
jaroslav@1258
   668
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   669
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   670
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   671
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   672
     * @param   thrown  Throwable associated with log message.
jaroslav@1258
   673
     */
jaroslav@1258
   674
    public void logp(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   675
                                                        String msg, Throwable thrown) {
jaroslav@1258
   676
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   677
            return;
jaroslav@1258
   678
        }
jaroslav@1258
   679
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   680
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   681
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   682
        lr.setThrown(thrown);
jaroslav@1258
   683
        doLog(lr);
jaroslav@1258
   684
    }
jaroslav@1258
   685
jaroslav@1258
   686
jaroslav@1258
   687
    //=========================================================================
jaroslav@1258
   688
    // Start of convenience methods WITH className, methodName and bundle name.
jaroslav@1258
   689
    //=========================================================================
jaroslav@1258
   690
jaroslav@1258
   691
jaroslav@1258
   692
    /**
jaroslav@1258
   693
     * Log a message, specifying source class, method, and resource bundle name
jaroslav@1258
   694
     * with no arguments.
jaroslav@1258
   695
     * <p>
jaroslav@1258
   696
     * If the logger is currently enabled for the given message
jaroslav@1258
   697
     * level then the given message is forwarded to all the
jaroslav@1258
   698
     * registered output Handler objects.
jaroslav@1258
   699
     * <p>
jaroslav@1258
   700
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   701
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   702
     * then the msg string is not localized.
jaroslav@1258
   703
     * <p>
jaroslav@1258
   704
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   705
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   706
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   707
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   708
     *                         can be null
jaroslav@1258
   709
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   710
     */
jaroslav@1258
   711
jaroslav@1258
   712
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   713
                                String bundleName, String msg) {
jaroslav@1258
   714
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   715
            return;
jaroslav@1258
   716
        }
jaroslav@1258
   717
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   718
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   719
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   720
        doLog(lr, bundleName);
jaroslav@1258
   721
    }
jaroslav@1258
   722
jaroslav@1258
   723
    /**
jaroslav@1258
   724
     * Log a message, specifying source class, method, and resource bundle name,
jaroslav@1258
   725
     * with a single object parameter to the log message.
jaroslav@1258
   726
     * <p>
jaroslav@1258
   727
     * If the logger is currently enabled for the given message
jaroslav@1258
   728
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   729
     * to all the registered output Handler objects.
jaroslav@1258
   730
     * <p>
jaroslav@1258
   731
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   732
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   733
     * then the msg string is not localized.
jaroslav@1258
   734
     * <p>
jaroslav@1258
   735
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   736
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   737
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   738
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   739
     *                         can be null
jaroslav@1258
   740
     * @param   msg      The string message (or a key in the message catalog)
jaroslav@1258
   741
     * @param   param1    Parameter to the log message.
jaroslav@1258
   742
     */
jaroslav@1258
   743
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   744
                                String bundleName, String msg, Object param1) {
jaroslav@1258
   745
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   746
            return;
jaroslav@1258
   747
        }
jaroslav@1258
   748
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   749
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   750
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   751
        Object params[] = { param1 };
jaroslav@1258
   752
        lr.setParameters(params);
jaroslav@1258
   753
        doLog(lr, bundleName);
jaroslav@1258
   754
    }
jaroslav@1258
   755
jaroslav@1258
   756
    /**
jaroslav@1258
   757
     * Log a message, specifying source class, method, and resource bundle name,
jaroslav@1258
   758
     * with an array of object arguments.
jaroslav@1258
   759
     * <p>
jaroslav@1258
   760
     * If the logger is currently enabled for the given message
jaroslav@1258
   761
     * level then a corresponding LogRecord is created and forwarded
jaroslav@1258
   762
     * to all the registered output Handler objects.
jaroslav@1258
   763
     * <p>
jaroslav@1258
   764
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   765
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   766
     * then the msg string is not localized.
jaroslav@1258
   767
     * <p>
jaroslav@1258
   768
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   769
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   770
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   771
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   772
     *                         can be null.
jaroslav@1258
   773
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   774
     * @param   params  Array of parameters to the message
jaroslav@1258
   775
     */
jaroslav@1258
   776
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   777
                                String bundleName, String msg, Object params[]) {
jaroslav@1258
   778
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   779
            return;
jaroslav@1258
   780
        }
jaroslav@1258
   781
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   782
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   783
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   784
        lr.setParameters(params);
jaroslav@1258
   785
        doLog(lr, bundleName);
jaroslav@1258
   786
    }
jaroslav@1258
   787
jaroslav@1258
   788
    /**
jaroslav@1258
   789
     * Log a message, specifying source class, method, and resource bundle name,
jaroslav@1258
   790
     * with associated Throwable information.
jaroslav@1258
   791
     * <p>
jaroslav@1258
   792
     * If the logger is currently enabled for the given message
jaroslav@1258
   793
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   794
     * which is forwarded to all registered output handlers.
jaroslav@1258
   795
     * <p>
jaroslav@1258
   796
     * The msg string is localized using the named resource bundle.  If the
jaroslav@1258
   797
     * resource bundle name is null, or an empty String or invalid
jaroslav@1258
   798
     * then the msg string is not localized.
jaroslav@1258
   799
     * <p>
jaroslav@1258
   800
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   801
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   802
     * processed specially by output Formatters and is not treated
jaroslav@1258
   803
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   804
     * <p>
jaroslav@1258
   805
     * @param   level   One of the message level identifiers, e.g., SEVERE
jaroslav@1258
   806
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   807
     * @param   sourceMethod   name of method that issued the logging request
jaroslav@1258
   808
     * @param   bundleName     name of resource bundle to localize msg,
jaroslav@1258
   809
     *                         can be null
jaroslav@1258
   810
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   811
     * @param   thrown  Throwable associated with log message.
jaroslav@1258
   812
     */
jaroslav@1258
   813
    public void logrb(Level level, String sourceClass, String sourceMethod,
jaroslav@1258
   814
                                        String bundleName, String msg, Throwable thrown) {
jaroslav@1258
   815
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
   816
            return;
jaroslav@1258
   817
        }
jaroslav@1258
   818
        LogRecord lr = new LogRecord(level, msg);
jaroslav@1258
   819
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   820
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   821
        lr.setThrown(thrown);
jaroslav@1258
   822
        doLog(lr, bundleName);
jaroslav@1258
   823
    }
jaroslav@1258
   824
jaroslav@1258
   825
jaroslav@1258
   826
    //======================================================================
jaroslav@1258
   827
    // Start of convenience methods for logging method entries and returns.
jaroslav@1258
   828
    //======================================================================
jaroslav@1258
   829
jaroslav@1258
   830
    /**
jaroslav@1258
   831
     * Log a method entry.
jaroslav@1258
   832
     * <p>
jaroslav@1258
   833
     * This is a convenience method that can be used to log entry
jaroslav@1258
   834
     * to a method.  A LogRecord with message "ENTRY", log level
jaroslav@1258
   835
     * FINER, and the given sourceMethod and sourceClass is logged.
jaroslav@1258
   836
     * <p>
jaroslav@1258
   837
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   838
     * @param   sourceMethod   name of method that is being entered
jaroslav@1258
   839
     */
jaroslav@1258
   840
    public void entering(String sourceClass, String sourceMethod) {
jaroslav@1258
   841
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   842
            return;
jaroslav@1258
   843
        }
jaroslav@1258
   844
        logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
jaroslav@1258
   845
    }
jaroslav@1258
   846
jaroslav@1258
   847
    /**
jaroslav@1258
   848
     * Log a method entry, with one parameter.
jaroslav@1258
   849
     * <p>
jaroslav@1258
   850
     * This is a convenience method that can be used to log entry
jaroslav@1258
   851
     * to a method.  A LogRecord with message "ENTRY {0}", log level
jaroslav@1258
   852
     * FINER, and the given sourceMethod, sourceClass, and parameter
jaroslav@1258
   853
     * is logged.
jaroslav@1258
   854
     * <p>
jaroslav@1258
   855
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   856
     * @param   sourceMethod   name of method that is being entered
jaroslav@1258
   857
     * @param   param1         parameter to the method being entered
jaroslav@1258
   858
     */
jaroslav@1258
   859
    public void entering(String sourceClass, String sourceMethod, Object param1) {
jaroslav@1258
   860
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   861
            return;
jaroslav@1258
   862
        }
jaroslav@1258
   863
        Object params[] = { param1 };
jaroslav@1258
   864
        logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
jaroslav@1258
   865
    }
jaroslav@1258
   866
jaroslav@1258
   867
    /**
jaroslav@1258
   868
     * Log a method entry, with an array of parameters.
jaroslav@1258
   869
     * <p>
jaroslav@1258
   870
     * This is a convenience method that can be used to log entry
jaroslav@1258
   871
     * to a method.  A LogRecord with message "ENTRY" (followed by a
jaroslav@1258
   872
     * format {N} indicator for each entry in the parameter array),
jaroslav@1258
   873
     * log level FINER, and the given sourceMethod, sourceClass, and
jaroslav@1258
   874
     * parameters is logged.
jaroslav@1258
   875
     * <p>
jaroslav@1258
   876
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   877
     * @param   sourceMethod   name of method that is being entered
jaroslav@1258
   878
     * @param   params         array of parameters to the method being entered
jaroslav@1258
   879
     */
jaroslav@1258
   880
    public void entering(String sourceClass, String sourceMethod, Object params[]) {
jaroslav@1258
   881
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   882
            return;
jaroslav@1258
   883
        }
jaroslav@1258
   884
        String msg = "ENTRY";
jaroslav@1258
   885
        if (params == null ) {
jaroslav@1258
   886
           logp(Level.FINER, sourceClass, sourceMethod, msg);
jaroslav@1258
   887
           return;
jaroslav@1258
   888
        }
jaroslav@1258
   889
        for (int i = 0; i < params.length; i++) {
jaroslav@1258
   890
            msg = msg + " {" + i + "}";
jaroslav@1258
   891
        }
jaroslav@1258
   892
        logp(Level.FINER, sourceClass, sourceMethod, msg, params);
jaroslav@1258
   893
    }
jaroslav@1258
   894
jaroslav@1258
   895
    /**
jaroslav@1258
   896
     * Log a method return.
jaroslav@1258
   897
     * <p>
jaroslav@1258
   898
     * This is a convenience method that can be used to log returning
jaroslav@1258
   899
     * from a method.  A LogRecord with message "RETURN", log level
jaroslav@1258
   900
     * FINER, and the given sourceMethod and sourceClass is logged.
jaroslav@1258
   901
     * <p>
jaroslav@1258
   902
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   903
     * @param   sourceMethod   name of the method
jaroslav@1258
   904
     */
jaroslav@1258
   905
    public void exiting(String sourceClass, String sourceMethod) {
jaroslav@1258
   906
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   907
            return;
jaroslav@1258
   908
        }
jaroslav@1258
   909
        logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
jaroslav@1258
   910
    }
jaroslav@1258
   911
jaroslav@1258
   912
jaroslav@1258
   913
    /**
jaroslav@1258
   914
     * Log a method return, with result object.
jaroslav@1258
   915
     * <p>
jaroslav@1258
   916
     * This is a convenience method that can be used to log returning
jaroslav@1258
   917
     * from a method.  A LogRecord with message "RETURN {0}", log level
jaroslav@1258
   918
     * FINER, and the gives sourceMethod, sourceClass, and result
jaroslav@1258
   919
     * object is logged.
jaroslav@1258
   920
     * <p>
jaroslav@1258
   921
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   922
     * @param   sourceMethod   name of the method
jaroslav@1258
   923
     * @param   result  Object that is being returned
jaroslav@1258
   924
     */
jaroslav@1258
   925
    public void exiting(String sourceClass, String sourceMethod, Object result) {
jaroslav@1258
   926
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
   927
            return;
jaroslav@1258
   928
        }
jaroslav@1258
   929
        Object params[] = { result };
jaroslav@1258
   930
        logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result);
jaroslav@1258
   931
    }
jaroslav@1258
   932
jaroslav@1258
   933
    /**
jaroslav@1258
   934
     * Log throwing an exception.
jaroslav@1258
   935
     * <p>
jaroslav@1258
   936
     * This is a convenience method to log that a method is
jaroslav@1258
   937
     * terminating by throwing an exception.  The logging is done
jaroslav@1258
   938
     * using the FINER level.
jaroslav@1258
   939
     * <p>
jaroslav@1258
   940
     * If the logger is currently enabled for the given message
jaroslav@1258
   941
     * level then the given arguments are stored in a LogRecord
jaroslav@1258
   942
     * which is forwarded to all registered output handlers.  The
jaroslav@1258
   943
     * LogRecord's message is set to "THROW".
jaroslav@1258
   944
     * <p>
jaroslav@1258
   945
     * Note that the thrown argument is stored in the LogRecord thrown
jaroslav@1258
   946
     * property, rather than the LogRecord parameters property.  Thus is it
jaroslav@1258
   947
     * processed specially by output Formatters and is not treated
jaroslav@1258
   948
     * as a formatting parameter to the LogRecord message property.
jaroslav@1258
   949
     * <p>
jaroslav@1258
   950
     * @param   sourceClass    name of class that issued the logging request
jaroslav@1258
   951
     * @param   sourceMethod  name of the method.
jaroslav@1258
   952
     * @param   thrown  The Throwable that is being thrown.
jaroslav@1258
   953
     */
jaroslav@1258
   954
    public void throwing(String sourceClass, String sourceMethod, Throwable thrown) {
jaroslav@1258
   955
        if (Level.FINER.intValue() < levelValue || levelValue == offValue ) {
jaroslav@1258
   956
            return;
jaroslav@1258
   957
        }
jaroslav@1258
   958
        LogRecord lr = new LogRecord(Level.FINER, "THROW");
jaroslav@1258
   959
        lr.setSourceClassName(sourceClass);
jaroslav@1258
   960
        lr.setSourceMethodName(sourceMethod);
jaroslav@1258
   961
        lr.setThrown(thrown);
jaroslav@1258
   962
        doLog(lr);
jaroslav@1258
   963
    }
jaroslav@1258
   964
jaroslav@1258
   965
    //=======================================================================
jaroslav@1258
   966
    // Start of simple convenience methods using level names as method names
jaroslav@1258
   967
    //=======================================================================
jaroslav@1258
   968
jaroslav@1258
   969
    /**
jaroslav@1258
   970
     * Log a SEVERE message.
jaroslav@1258
   971
     * <p>
jaroslav@1258
   972
     * If the logger is currently enabled for the SEVERE message
jaroslav@1258
   973
     * level then the given message is forwarded to all the
jaroslav@1258
   974
     * registered output Handler objects.
jaroslav@1258
   975
     * <p>
jaroslav@1258
   976
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   977
     */
jaroslav@1258
   978
    public void severe(String msg) {
jaroslav@1258
   979
        if (Level.SEVERE.intValue() < levelValue) {
jaroslav@1258
   980
            return;
jaroslav@1258
   981
        }
jaroslav@1258
   982
        log(Level.SEVERE, msg);
jaroslav@1258
   983
    }
jaroslav@1258
   984
jaroslav@1258
   985
    /**
jaroslav@1258
   986
     * Log a WARNING message.
jaroslav@1258
   987
     * <p>
jaroslav@1258
   988
     * If the logger is currently enabled for the WARNING message
jaroslav@1258
   989
     * level then the given message is forwarded to all the
jaroslav@1258
   990
     * registered output Handler objects.
jaroslav@1258
   991
     * <p>
jaroslav@1258
   992
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
   993
     */
jaroslav@1258
   994
    public void warning(String msg) {
jaroslav@1258
   995
        if (Level.WARNING.intValue() < levelValue) {
jaroslav@1258
   996
            return;
jaroslav@1258
   997
        }
jaroslav@1258
   998
        log(Level.WARNING, msg);
jaroslav@1258
   999
    }
jaroslav@1258
  1000
jaroslav@1258
  1001
    /**
jaroslav@1258
  1002
     * Log an INFO message.
jaroslav@1258
  1003
     * <p>
jaroslav@1258
  1004
     * If the logger is currently enabled for the INFO message
jaroslav@1258
  1005
     * level then the given message is forwarded to all the
jaroslav@1258
  1006
     * registered output Handler objects.
jaroslav@1258
  1007
     * <p>
jaroslav@1258
  1008
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1009
     */
jaroslav@1258
  1010
    public void info(String msg) {
jaroslav@1258
  1011
        if (Level.INFO.intValue() < levelValue) {
jaroslav@1258
  1012
            return;
jaroslav@1258
  1013
        }
jaroslav@1258
  1014
        log(Level.INFO, msg);
jaroslav@1258
  1015
    }
jaroslav@1258
  1016
jaroslav@1258
  1017
    /**
jaroslav@1258
  1018
     * Log a CONFIG message.
jaroslav@1258
  1019
     * <p>
jaroslav@1258
  1020
     * If the logger is currently enabled for the CONFIG message
jaroslav@1258
  1021
     * level then the given message is forwarded to all the
jaroslav@1258
  1022
     * registered output Handler objects.
jaroslav@1258
  1023
     * <p>
jaroslav@1258
  1024
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1025
     */
jaroslav@1258
  1026
    public void config(String msg) {
jaroslav@1258
  1027
        if (Level.CONFIG.intValue() < levelValue) {
jaroslav@1258
  1028
            return;
jaroslav@1258
  1029
        }
jaroslav@1258
  1030
        log(Level.CONFIG, msg);
jaroslav@1258
  1031
    }
jaroslav@1258
  1032
jaroslav@1258
  1033
    /**
jaroslav@1258
  1034
     * Log a FINE message.
jaroslav@1258
  1035
     * <p>
jaroslav@1258
  1036
     * If the logger is currently enabled for the FINE message
jaroslav@1258
  1037
     * level then the given message is forwarded to all the
jaroslav@1258
  1038
     * registered output Handler objects.
jaroslav@1258
  1039
     * <p>
jaroslav@1258
  1040
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1041
     */
jaroslav@1258
  1042
    public void fine(String msg) {
jaroslav@1258
  1043
        if (Level.FINE.intValue() < levelValue) {
jaroslav@1258
  1044
            return;
jaroslav@1258
  1045
        }
jaroslav@1258
  1046
        log(Level.FINE, msg);
jaroslav@1258
  1047
    }
jaroslav@1258
  1048
jaroslav@1258
  1049
    /**
jaroslav@1258
  1050
     * Log a FINER message.
jaroslav@1258
  1051
     * <p>
jaroslav@1258
  1052
     * If the logger is currently enabled for the FINER message
jaroslav@1258
  1053
     * level then the given message is forwarded to all the
jaroslav@1258
  1054
     * registered output Handler objects.
jaroslav@1258
  1055
     * <p>
jaroslav@1258
  1056
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1057
     */
jaroslav@1258
  1058
    public void finer(String msg) {
jaroslav@1258
  1059
        if (Level.FINER.intValue() < levelValue) {
jaroslav@1258
  1060
            return;
jaroslav@1258
  1061
        }
jaroslav@1258
  1062
        log(Level.FINER, msg);
jaroslav@1258
  1063
    }
jaroslav@1258
  1064
jaroslav@1258
  1065
    /**
jaroslav@1258
  1066
     * Log a FINEST message.
jaroslav@1258
  1067
     * <p>
jaroslav@1258
  1068
     * If the logger is currently enabled for the FINEST message
jaroslav@1258
  1069
     * level then the given message is forwarded to all the
jaroslav@1258
  1070
     * registered output Handler objects.
jaroslav@1258
  1071
     * <p>
jaroslav@1258
  1072
     * @param   msg     The string message (or a key in the message catalog)
jaroslav@1258
  1073
     */
jaroslav@1258
  1074
    public void finest(String msg) {
jaroslav@1258
  1075
        if (Level.FINEST.intValue() < levelValue) {
jaroslav@1258
  1076
            return;
jaroslav@1258
  1077
        }
jaroslav@1258
  1078
        log(Level.FINEST, msg);
jaroslav@1258
  1079
    }
jaroslav@1258
  1080
jaroslav@1258
  1081
    //================================================================
jaroslav@1258
  1082
    // End of convenience methods
jaroslav@1258
  1083
    //================================================================
jaroslav@1258
  1084
jaroslav@1258
  1085
    /**
jaroslav@1258
  1086
     * Set the log level specifying which message levels will be
jaroslav@1258
  1087
     * logged by this logger.  Message levels lower than this
jaroslav@1258
  1088
     * value will be discarded.  The level value Level.OFF
jaroslav@1258
  1089
     * can be used to turn off logging.
jaroslav@1258
  1090
     * <p>
jaroslav@1258
  1091
     * If the new level is null, it means that this node should
jaroslav@1258
  1092
     * inherit its level from its nearest ancestor with a specific
jaroslav@1258
  1093
     * (non-null) level value.
jaroslav@1258
  1094
     *
jaroslav@1258
  1095
     * @param newLevel   the new value for the log level (may be null)
jaroslav@1258
  1096
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1097
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1098
     */
jaroslav@1258
  1099
    public void setLevel(Level newLevel) throws SecurityException {
jaroslav@1260
  1100
        levelValue = newLevel.intValue();
jaroslav@1260
  1101
        levelObject = newLevel;
jaroslav@1258
  1102
    }
jaroslav@1258
  1103
jaroslav@1258
  1104
    /**
jaroslav@1258
  1105
     * Get the log Level that has been specified for this Logger.
jaroslav@1258
  1106
     * The result may be null, which means that this logger's
jaroslav@1258
  1107
     * effective level will be inherited from its parent.
jaroslav@1258
  1108
     *
jaroslav@1258
  1109
     * @return  this Logger's level
jaroslav@1258
  1110
     */
jaroslav@1258
  1111
    public Level getLevel() {
jaroslav@1258
  1112
        return levelObject;
jaroslav@1258
  1113
    }
jaroslav@1258
  1114
jaroslav@1258
  1115
    /**
jaroslav@1258
  1116
     * Check if a message of the given level would actually be logged
jaroslav@1258
  1117
     * by this logger.  This check is based on the Loggers effective level,
jaroslav@1258
  1118
     * which may be inherited from its parent.
jaroslav@1258
  1119
     *
jaroslav@1258
  1120
     * @param   level   a message logging level
jaroslav@1258
  1121
     * @return  true if the given message level is currently being logged.
jaroslav@1258
  1122
     */
jaroslav@1258
  1123
    public boolean isLoggable(Level level) {
jaroslav@1258
  1124
        if (level.intValue() < levelValue || levelValue == offValue) {
jaroslav@1258
  1125
            return false;
jaroslav@1258
  1126
        }
jaroslav@1258
  1127
        return true;
jaroslav@1258
  1128
    }
jaroslav@1258
  1129
jaroslav@1258
  1130
    /**
jaroslav@1258
  1131
     * Get the name for this logger.
jaroslav@1258
  1132
     * @return logger name.  Will be null for anonymous Loggers.
jaroslav@1258
  1133
     */
jaroslav@1258
  1134
    public String getName() {
jaroslav@1258
  1135
        return name;
jaroslav@1258
  1136
    }
jaroslav@1258
  1137
jaroslav@1258
  1138
    /**
jaroslav@1258
  1139
     * Add a log Handler to receive logging messages.
jaroslav@1258
  1140
     * <p>
jaroslav@1258
  1141
     * By default, Loggers also send their output to their parent logger.
jaroslav@1258
  1142
     * Typically the root Logger is configured with a set of Handlers
jaroslav@1258
  1143
     * that essentially act as default handlers for all loggers.
jaroslav@1258
  1144
     *
jaroslav@1258
  1145
     * @param   handler a logging Handler
jaroslav@1258
  1146
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1147
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1148
     */
jaroslav@1260
  1149
//    public void addHandler(Handler handler) throws SecurityException {
jaroslav@1260
  1150
//        // Check for null handler
jaroslav@1260
  1151
//        handler.getClass();
jaroslav@1260
  1152
//        checkAccess();
jaroslav@1260
  1153
//        handlers.add(handler);
jaroslav@1260
  1154
//    }
jaroslav@1258
  1155
jaroslav@1258
  1156
    /**
jaroslav@1258
  1157
     * Remove a log Handler.
jaroslav@1258
  1158
     * <P>
jaroslav@1258
  1159
     * Returns silently if the given Handler is not found or is null
jaroslav@1258
  1160
     *
jaroslav@1258
  1161
     * @param   handler a logging Handler
jaroslav@1258
  1162
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1163
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1164
     */
jaroslav@1260
  1165
//    public void removeHandler(Handler handler) throws SecurityException {
jaroslav@1260
  1166
//        checkAccess();
jaroslav@1260
  1167
//        if (handler == null) {
jaroslav@1260
  1168
//            return;
jaroslav@1260
  1169
//        }
jaroslav@1260
  1170
//        handlers.remove(handler);
jaroslav@1260
  1171
//    }
jaroslav@1258
  1172
jaroslav@1258
  1173
    /**
jaroslav@1258
  1174
     * Get the Handlers associated with this logger.
jaroslav@1258
  1175
     * <p>
jaroslav@1258
  1176
     * @return  an array of all registered Handlers
jaroslav@1258
  1177
     */
jaroslav@1260
  1178
//    public Handler[] getHandlers() {
jaroslav@1260
  1179
//        return handlers.toArray(emptyHandlers);
jaroslav@1260
  1180
//    }
jaroslav@1258
  1181
jaroslav@1258
  1182
    /**
jaroslav@1258
  1183
     * Specify whether or not this logger should send its output
jaroslav@1258
  1184
     * to its parent Logger.  This means that any LogRecords will
jaroslav@1258
  1185
     * also be written to the parent's Handlers, and potentially
jaroslav@1258
  1186
     * to its parent, recursively up the namespace.
jaroslav@1258
  1187
     *
jaroslav@1258
  1188
     * @param useParentHandlers   true if output is to be sent to the
jaroslav@1258
  1189
     *          logger's parent.
jaroslav@1258
  1190
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1191
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1192
     */
jaroslav@1258
  1193
    public void setUseParentHandlers(boolean useParentHandlers) {
jaroslav@1258
  1194
        checkAccess();
jaroslav@1258
  1195
    }
jaroslav@1258
  1196
jaroslav@1258
  1197
    /**
jaroslav@1258
  1198
     * Discover whether or not this logger is sending its output
jaroslav@1258
  1199
     * to its parent logger.
jaroslav@1258
  1200
     *
jaroslav@1258
  1201
     * @return  true if output is to be sent to the logger's parent
jaroslav@1258
  1202
     */
jaroslav@1258
  1203
    public boolean getUseParentHandlers() {
jaroslav@1260
  1204
        return true;
jaroslav@1258
  1205
    }
jaroslav@1258
  1206
jaroslav@1258
  1207
    /**
jaroslav@1258
  1208
     * Return the parent for this Logger.
jaroslav@1258
  1209
     * <p>
jaroslav@1258
  1210
     * This method returns the nearest extant parent in the namespace.
jaroslav@1258
  1211
     * Thus if a Logger is called "a.b.c.d", and a Logger called "a.b"
jaroslav@1258
  1212
     * has been created but no logger "a.b.c" exists, then a call of
jaroslav@1258
  1213
     * getParent on the Logger "a.b.c.d" will return the Logger "a.b".
jaroslav@1258
  1214
     * <p>
jaroslav@1258
  1215
     * The result will be null if it is called on the root Logger
jaroslav@1258
  1216
     * in the namespace.
jaroslav@1258
  1217
     *
jaroslav@1258
  1218
     * @return nearest existing parent Logger
jaroslav@1258
  1219
     */
jaroslav@1258
  1220
    public Logger getParent() {
jaroslav@1258
  1221
        // Note: this used to be synchronized on treeLock.  However, this only
jaroslav@1258
  1222
        // provided memory semantics, as there was no guarantee that the caller
jaroslav@1258
  1223
        // would synchronize on treeLock (in fact, there is no way for external
jaroslav@1258
  1224
        // callers to so synchronize).  Therefore, we have made parent volatile
jaroslav@1258
  1225
        // instead.
jaroslav@1260
  1226
        String n = getName();
jaroslav@1260
  1227
        int at = n.length();
jaroslav@1260
  1228
        for (;;) {
jaroslav@1260
  1229
            int last = n.lastIndexOf('.', at - 1);
jaroslav@1260
  1230
            if (last == -1) {
jaroslav@1260
  1231
                return getGlobal();
jaroslav@1260
  1232
            }
jaroslav@1260
  1233
            Logger p = ALL.get(n.substring(0, last));
jaroslav@1260
  1234
            if (p != null) {
jaroslav@1260
  1235
                return p;
jaroslav@1260
  1236
            }
jaroslav@1260
  1237
            at = last;
jaroslav@1260
  1238
        }
jaroslav@1258
  1239
    }
jaroslav@1258
  1240
jaroslav@1258
  1241
    /**
jaroslav@1258
  1242
     * Set the parent for this Logger.  This method is used by
jaroslav@1258
  1243
     * the LogManager to update a Logger when the namespace changes.
jaroslav@1258
  1244
     * <p>
jaroslav@1258
  1245
     * It should not be called from application code.
jaroslav@1258
  1246
     * <p>
jaroslav@1258
  1247
     * @param  parent   the new parent logger
jaroslav@1258
  1248
     * @exception  SecurityException  if a security manager exists and if
jaroslav@1258
  1249
     *             the caller does not have LoggingPermission("control").
jaroslav@1258
  1250
     */
jaroslav@1258
  1251
    public void setParent(Logger parent) {
jaroslav@1258
  1252
        if (parent == null) {
jaroslav@1258
  1253
            throw new NullPointerException();
jaroslav@1258
  1254
        }
jaroslav@1260
  1255
        checkAccess();
jaroslav@1258
  1256
    }
jaroslav@1258
  1257
jaroslav@1258
  1258
}