Most visited

Recently visited

Added in API level 1

MemoryHandler

public class MemoryHandler
extends Handler

java.lang.Object
   ↳ java.util.logging.Handler
     ↳ java.util.logging.MemoryHandler


Handler that buffers requests in a circular buffer in memory.

Normally this Handler simply stores incoming LogRecords into its memory buffer and discards earlier records. This buffering is very cheap and avoids formatting costs. On certain trigger conditions, the MemoryHandler will push out its current buffer contents to a target Handler, which will typically publish them to the outside world.

There are three main models for triggering a push of the buffer:

Configuration: By default each MemoryHandler is initialized using the following LogManager configuration properties. If properties are not defined (or have invalid values) then the specified default values are used. If no default value is defined then a RuntimeException is thrown.

Summary

Public constructors

MemoryHandler()

Create a MemoryHandler and configure it based on LogManager configuration properties.

MemoryHandler(Handler target, int size, Level pushLevel)

Create a MemoryHandler.

Public methods

void close()

Close the Handler and free all associated resources.

void flush()

Causes a flush on the target Handler.

Level getPushLevel()

Get the pushLevel.

boolean isLoggable(LogRecord record)

Check if this Handler would actually log a given LogRecord into its internal buffer.

void publish(LogRecord record)

Store a LogRecord in an internal buffer.

void push()

Push any buffered output to the target Handler.

void setPushLevel(Level newLevel)

Set the pushLevel.

Inherited methods

From class java.util.logging.Handler
From class java.lang.Object

Public constructors

MemoryHandler

Added in API level 1
MemoryHandler ()

Create a MemoryHandler and configure it based on LogManager configuration properties.

MemoryHandler

Added in API level 1
MemoryHandler (Handler target, 
                int size, 
                Level pushLevel)

Create a MemoryHandler.

The MemoryHandler is configured based on LogManager properties (or their default values) except that the given pushLevel argument and buffer size argument are used.

Parameters
target Handler: the Handler to which to publish output.
size int: the number of log records to buffer (must be greater than zero)
pushLevel Level: message level to push on
Throws
IllegalArgumentException if size is <= 0

Public methods

close

Added in API level 1
void close ()

Close the Handler and free all associated resources. This will also close the target Handler.

Throws
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

flush

Added in API level 1
void flush ()

Causes a flush on the target Handler.

Note that the current contents of the MemoryHandler buffer are not written out. That requires a "push".

getPushLevel

Added in API level 1
Level getPushLevel ()

Get the pushLevel.

Returns
Level the value of the pushLevel

isLoggable

Added in API level 1
boolean isLoggable (LogRecord record)

Check if this Handler would actually log a given LogRecord into its internal buffer.

This method checks if the LogRecord has an appropriate level and whether it satisfies any Filter. However it does not check whether the LogRecord would result in a "push" of the buffer contents. It will return false if the LogRecord is null.

Parameters
record LogRecord: a LogRecord
Returns
boolean true if the LogRecord would be logged.

publish

Added in API level 1
void publish (LogRecord record)

Store a LogRecord in an internal buffer.

If there is a Filter, its isLoggable method is called to check if the given log record is loggable. If not we return. Otherwise the given record is copied into an internal circular buffer. Then the record's level property is compared with the pushLevel. If the given level is greater than or equal to the pushLevel then push is called to write all buffered records to the target output Handler.

Parameters
record LogRecord: description of the log event. A null record is silently ignored and is not published

push

Added in API level 1
void push ()

Push any buffered output to the target Handler.

The buffer is then cleared.

setPushLevel

Added in API level 1
void setPushLevel (Level newLevel)

Set the pushLevel. After a LogRecord is copied into our internal buffer, if its level is greater than or equal to the pushLevel, then push will be called.

Parameters
newLevel Level: the new value of the pushLevel
Throws
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

Hooray!