jdk/src/share/classes/java/util/logging/MemoryHandler.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3853 9d2382b74894
child 14216 23714b376286
child 14321 7f9f265ac11e
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
diff changeset
     2
 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.logging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * <tt>Handler</tt> that buffers requests in a circular buffer in memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Normally this <tt>Handler</tt> simply stores incoming <tt>LogRecords</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * into its memory buffer and discards earlier records.  This buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * is very cheap and avoids formatting costs.  On certain trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * conditions, the <tt>MemoryHandler</tt> will push out its current buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * contents to a target <tt>Handler</tt>, which will typically publish
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * them to the outside world.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * There are three main models for triggering a push of the buffer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * An incoming <tt>LogRecord</tt> has a type that is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * a pre-defined level, the <tt>pushLevel</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * An external class calls the <tt>push</tt> method explicitly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * A subclass overrides the <tt>log</tt> method and scans each incoming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <tt>LogRecord</tt> and calls <tt>push</tt> if a record matches some
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * desired criteria.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <b>Configuration:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * By default each <tt>MemoryHandler</tt> is initialized using the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * LogManager configuration properties.  If properties are not defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * (or have invalid values) then the specified default values are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * If no default value is defined then a RuntimeException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <li>   java.util.logging.MemoryHandler.level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *        specifies the level for the <tt>Handler</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *        (defaults to <tt>Level.ALL</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <li>   java.util.logging.MemoryHandler.filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *        specifies the name of a <tt>Filter</tt> class to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *        (defaults to no <tt>Filter</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <li>   java.util.logging.MemoryHandler.size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *        defines the buffer size (defaults to 1000).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <li>   java.util.logging.MemoryHandler.push
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *        defines the <tt>pushLevel</tt> (defaults to <tt>level.SEVERE</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <li>   java.util.logging.MemoryHandler.target
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *        specifies the name of the target <tt>Handler </tt> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *        (no default).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public class MemoryHandler extends Handler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private final static int DEFAULT_SIZE = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private Level pushLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private Handler target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private LogRecord buffer[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    int start, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // Private method to configure a ConsoleHandler from LogManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // properties and/or default values as specified in the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // javadoc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private void configure() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        LogManager manager = LogManager.getLogManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        String cname = getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        pushLevel = manager.getLevelProperty(cname +".push", Level.SEVERE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        size = manager.getIntProperty(cname + ".size", DEFAULT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (size <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            size = DEFAULT_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        setLevel(manager.getLevelProperty(cname +".level", Level.ALL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        setFilter(manager.getFilterProperty(cname +".filter", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Create a <tt>MemoryHandler</tt> and configure it based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <tt>LogManager</tt> configuration properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public MemoryHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        sealed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        configure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        sealed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        String name = "???";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            LogManager manager = LogManager.getLogManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            name = manager.getProperty("java.util.logging.MemoryHandler.target");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            Class clz = ClassLoader.getSystemClassLoader().loadClass(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            target = (Handler) clz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new RuntimeException("MemoryHandler can't load handler \"" + name + "\"" , ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // Initialize.  Size is a count of LogRecords.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        buffer = new LogRecord[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Create a <tt>MemoryHandler</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The <tt>MemoryHandler</tt> is configured based on <tt>LogManager</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * properties (or their default values) except that the given <tt>pushLevel</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * argument and buffer size argument are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param target  the Handler to which to publish output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param size    the number of log records to buffer (must be greater than zero)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param pushLevel  message level to push on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2
diff changeset
   139
     * @throws IllegalArgumentException if size is <= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public MemoryHandler(Handler target, int size, Level pushLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (target == null || pushLevel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (size <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        sealed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        configure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        sealed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        this.pushLevel = pushLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        this.size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Store a <tt>LogRecord</tt> in an internal buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * If there is a <tt>Filter</tt>, its <tt>isLoggable</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * method is called to check if the given log record is loggable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * If not we return.  Otherwise the given record is copied into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * an internal circular buffer.  Then the record's level property is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * compared with the <tt>pushLevel</tt>. If the given level is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * greater than or equal to the <tt>pushLevel</tt> then <tt>push</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * is called to write all buffered records to the target output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <tt>Handler</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param  record  description of the log event. A null record is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *                 silently ignored and is not published
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public synchronized void publish(LogRecord record) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (!isLoggable(record)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        int ix = (start+count)%buffer.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        buffer[ix] = record;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (count < buffer.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            start++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            start %= buffer.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (record.getLevel().intValue() >= pushLevel.intValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            push();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Push any buffered output to the target <tt>Handler</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * The buffer is then cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public synchronized void push() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            int ix = (start+i)%buffer.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            LogRecord record = buffer[ix];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            target.publish(record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // Empty the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Causes a flush on the target <tt>Handler</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Note that the current contents of the <tt>MemoryHandler</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * buffer are <b>not</b> written out.  That requires a "push".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        target.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Close the <tt>Handler</tt> and free all associated resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * This will also close the target <tt>Handler</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *             the caller does not have <tt>LoggingPermission("control")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public void close() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        target.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        setLevel(Level.OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Set the <tt>pushLevel</tt>.  After a <tt>LogRecord</tt> is copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * into our internal buffer, if its level is greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * the <tt>pushLevel</tt>, then <tt>push</tt> will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param newLevel the new value of the <tt>pushLevel</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *             the caller does not have <tt>LoggingPermission("control")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public void setPushLevel(Level newLevel) throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (newLevel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        LogManager manager = LogManager.getLogManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        checkAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        pushLevel = newLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Get the <tt>pushLevel</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return the value of the <tt>pushLevel</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public synchronized Level getPushLevel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return pushLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Check if this <tt>Handler</tt> would actually log a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <tt>LogRecord</tt> into its internal buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * This method checks if the <tt>LogRecord</tt> has an appropriate level and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * whether it satisfies any <tt>Filter</tt>.  However it does <b>not</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * check whether the <tt>LogRecord</tt> would result in a "push" of the
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2
diff changeset
   261
     * buffer contents. It will return false if the <tt>LogRecord</tt> is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param record  a <tt>LogRecord</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return true if the <tt>LogRecord</tt> would be logged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public boolean isLoggable(LogRecord record) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return super.isLoggable(record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}