2362N/A * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * <tt>Handler</tt> that buffers requests in a circular buffer in memory. 0N/A * Normally this <tt>Handler</tt> simply stores incoming <tt>LogRecords</tt> 0N/A * into its memory buffer and discards earlier records. This buffering 0N/A * is very cheap and avoids formatting costs. On certain trigger 0N/A * conditions, the <tt>MemoryHandler</tt> will push out its current buffer 0N/A * contents to a target <tt>Handler</tt>, which will typically publish 0N/A * them to the outside world. 0N/A * There are three main models for triggering a push of the buffer: 0N/A * An incoming <tt>LogRecord</tt> has a type that is greater than 0N/A * a pre-defined level, the <tt>pushLevel</tt>. 0N/A * An external class calls the <tt>push</tt> method explicitly. 0N/A * A subclass overrides the <tt>log</tt> method and scans each incoming 0N/A * <tt>LogRecord</tt> and calls <tt>push</tt> if a record matches some 0N/A * <b>Configuration:</b> 0N/A * By default each <tt>MemoryHandler</tt> is initialized using the following 0N/A * LogManager configuration properties. If properties are not defined 0N/A * (or have invalid values) then the specified default values are used. 0N/A * If no default value is defined then a RuntimeException is thrown. 0N/A * <li> java.util.logging.MemoryHandler.level 0N/A * specifies the level for the <tt>Handler</tt> 0N/A * (defaults to <tt>Level.ALL</tt>). 0N/A * <li> java.util.logging.MemoryHandler.filter 0N/A * specifies the name of a <tt>Filter</tt> class to use 0N/A * (defaults to no <tt>Filter</tt>). 0N/A * <li> java.util.logging.MemoryHandler.size 0N/A * defines the buffer size (defaults to 1000). 0N/A * <li> java.util.logging.MemoryHandler.push 0N/A * defines the <tt>pushLevel</tt> (defaults to <tt>level.SEVERE</tt>). 0N/A * <li> java.util.logging.MemoryHandler.target 0N/A * specifies the name of the target <tt>Handler </tt> class. 0N/A // Private method to configure a ConsoleHandler from LogManager 0N/A // properties and/or default values as specified in the class 0N/A * Create a <tt>MemoryHandler</tt> and configure it based on 0N/A * <tt>LogManager</tt> configuration properties. 0N/A // Initialize. Size is a count of LogRecords. 0N/A * Create a <tt>MemoryHandler</tt>. 0N/A * The <tt>MemoryHandler</tt> is configured based on <tt>LogManager</tt> 0N/A * properties (or their default values) except that the given <tt>pushLevel</tt> 0N/A * argument and buffer size argument are used. 0N/A * @param target the Handler to which to publish output. 0N/A * @param size the number of log records to buffer (must be greater than zero) 0N/A * @param pushLevel message level to push on 1664N/A * @throws IllegalArgumentException if size is <= 0 0N/A * Store a <tt>LogRecord</tt> in an internal buffer. 0N/A * If there is a <tt>Filter</tt>, its <tt>isLoggable</tt> 0N/A * method is called to check if the given log record is loggable. 0N/A * If not we return. Otherwise the given record is copied into 0N/A * an internal circular buffer. Then the record's level property is 0N/A * compared with the <tt>pushLevel</tt>. If the given level is 0N/A * greater than or equal to the <tt>pushLevel</tt> then <tt>push</tt> 0N/A * is called to write all buffered records to the target output 0N/A * @param record description of the log event. A null record is 0N/A * silently ignored and is not published 0N/A * Push any buffered output to the target <tt>Handler</tt>. 0N/A * The buffer is then cleared. 0N/A // Empty the buffer. 0N/A * Causes a flush on the target <tt>Handler</tt>. 0N/A * Note that the current contents of the <tt>MemoryHandler</tt> 0N/A * buffer are <b>not</b> written out. That requires a "push". 0N/A * Close the <tt>Handler</tt> and free all associated resources. 0N/A * This will also close the target <tt>Handler</tt>. 0N/A * @exception SecurityException if a security manager exists and if 0N/A * the caller does not have <tt>LoggingPermission("control")</tt>. 0N/A * Set the <tt>pushLevel</tt>. After a <tt>LogRecord</tt> is copied 0N/A * into our internal buffer, if its level is greater than or equal to 0N/A * the <tt>pushLevel</tt>, then <tt>push</tt> will be called. 0N/A * @param newLevel the new value of the <tt>pushLevel</tt> 0N/A * @exception SecurityException if a security manager exists and if 0N/A * the caller does not have <tt>LoggingPermission("control")</tt>. 0N/A * Get the <tt>pushLevel</tt>. 0N/A * @return the value of the <tt>pushLevel</tt> 0N/A * Check if this <tt>Handler</tt> would actually log a given 0N/A * <tt>LogRecord</tt> into its internal buffer. 0N/A * This method checks if the <tt>LogRecord</tt> has an appropriate level and 0N/A * whether it satisfies any <tt>Filter</tt>. However it does <b>not</b> 0N/A * check whether the <tt>LogRecord</tt> would result in a "push" of the 1664N/A * buffer contents. It will return false if the <tt>LogRecord</tt> is null. 0N/A * @param record a <tt>LogRecord</tt> 0N/A * @return true if the <tt>LogRecord</tt> would be logged.