A MemoryHandler stores LogRecord
objects in a fixed-sized buffer in memory. When the buffer fills up,
it discards the oldest record one each time a new record arrives. It
maintains a reference to another Handler object,
and whenever the push( ) method is called, or
whenver a LogRecord arrives with a level at or
higher than the pushLevel threshold, it
"pushes" all of buffered
LogRecord objects to that other
Handler object, which typically formats and
outputs them to some appropriate destination. Because
MemoryHandler never outputs log records itself, it
does not use the formatter or
encoding properties inherited from its superclass.
When you create a MemoryHandler, you can specify
the target Handler object, the size of the
in-memory buffer, and the value of the pushLevel
property, or you can omit these constructor arguments and rely on
system-wide defaults obtained with LogManager.getProperty(
). MemoryHandler also uses
LogManager.getProperty( ) to obtain initial values
for the level and filter
properties inherited from Handler. The table below
lists these properties, as well as the
target, size,
and pushLevel constructor arguments, the
value passed to getProperty( ), and the default
value used if getProperty( ) returns
null. See Handler for further
details.
Property or argument |
LogManager property name |
Default |
---|
level |
java.util.logging.MemoryHandler.level |
Level.ALL |
filter |
java.util.logging.MemoryHandler.filter |
null |
target |
java.util.logging.MemoryHandler.target |
no default |
size |
java.util.logging.MemoryHandler.size |
1000 log records |
pushLevel |
java.util.logging.MemoryHandler.push |
Level.SEVERE |
Figure 16-119. java.util.logging.MemoryHandler
public class
MemoryHandler extends Handler {
// Public Constructors
public
MemoryHandler ( );
public
MemoryHandler (Handler
target , int
size , Level
pushLevel );
// Public Instance Methods
public Level
getPushLevel ( ); synchronized
public void
push ( ); synchronized
public void
setPushLevel (Level
newLevel ) throws SecurityException;
// Public Methods Overriding Handler
public void
close ( ) throws SecurityException;
public void
flush ( );
public boolean
isLoggable (LogRecord
record );
public void
publish (LogRecord
record ); synchronized
}