APIdia Launch Partner
Top Description Fields Constructors Methods
java.util.logging

public Class MemoryHandler

extends Handler
Class Inheritance

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 where <handler-name> refers to the fully-qualified class name of the handler. 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.

For example, the properties for MemoryHandler would be:

For a custom handler, e.g. com.foo.MyHandler, the properties would be:

Since
1.4

Field Summary

Modifier and TypeField and Description
private LogRecord[]
pack-priv int
private static final int
private volatile Level
private int
pack-priv int
private Handler

Constructor Summary

AccessConstructor and Description
public
MemoryHandler()

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

public
MemoryHandler(Handler
the Handler to which to publish output.
target
,
int
the number of log records to buffer (must be greater than zero)
size
,
Level
message level to push on
pushLevel
)

Create a MemoryHandler.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.util.logging.Handler.close.

Close the Handler and free all associated resources.

public void
flush()

Implements abstract java.util.logging.Handler.flush.

Causes a flush on the target Handler.

public Level

Returns:

the value of the pushLevel
getPushLevel
()

Get the pushLevel.

private void
init()

public boolean

Returns:

true if the LogRecord would be logged.
isLoggable
(LogRecord
a LogRecord (may be null).
record
)

Overrides java.util.logging.Handler.isLoggable.

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

public synchronized void
publish(LogRecord
description of the log event. A null record is silently ignored and is not published
record
)

Implements abstract java.util.logging.Handler.publish.

Store a LogRecord in an internal buffer.

public synchronized void
push()

Push any buffered output to the target Handler.

public synchronized void
setPushLevel(Level
the new value of the pushLevel
newLevel
)

Set the pushLevel.

Inherited from java.util.logging.Handler:
getEncodinggetErrorManagergetFiltergetFormattergetLevelreportErrorsetEncodingsetErrorManagersetFiltersetFormattersetLevel

Field Detail

bufferback to summary
private LogRecord[] buffer
countback to summary
pack-priv int count
DEFAULT_SIZEback to summary
private static final int DEFAULT_SIZE
pushLevelback to summary
private volatile Level pushLevel
sizeback to summary
private int size
startback to summary
pack-priv int start
targetback to summary
private Handler target

Constructor Detail

MemoryHandlerback to summary
public MemoryHandler()

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

MemoryHandlerback to summary
public 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

Exceptions
IllegalArgumentException:
if size is <= 0

Method Detail

closeback to summary
public void close()

Implements abstract java.util.logging.Handler.close.

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

Annotations
@Override
flushback to summary
public void flush()

Implements abstract java.util.logging.Handler.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".

Annotations
@Override
getPushLevelback to summary
public Level getPushLevel()

Get the pushLevel.

Returns:Level

the value of the pushLevel

initback to summary
private void init()
isLoggableback to summary
public boolean isLoggable(LogRecord record)

Overrides java.util.logging.Handler.isLoggable.

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 (may be null).

Returns:boolean

true if the LogRecord would be logged.

Annotations
@Override
publishback to summary
public synchronized void publish(LogRecord record)

Implements abstract java.util.logging.Handler.publish.

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

Annotations
@Override
pushback to summary
public synchronized void push()

Push any buffered output to the target Handler.

The buffer is then cleared.

setPushLevelback to summary
public synchronized 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