org.apache.log.output

Class MemoryTarget

public class MemoryTarget extends AbstractTarget

Output LogEvents into an buffer in memory. At a later stage these LogEvents can be forwarded or pushed to another target. This pushing is triggered when buffer is full, the priority of a LogEvent reaches a threshold or when another class calls the push method. This is based on specification of MemoryHandler in Logging JSR47.

Author: Avalon Development Team Peter Donald

Field Summary
LogEvent[]m_buffer
intm_index
booleanm_overwrite
LogTargetm_target
Prioritym_threshold
intm_used
Constructor Summary
MemoryTarget(LogTarget target, int size, Priority threshold)
Creation of a new instance of the memory target.
Method Summary
protected voiddoProcessEvent(LogEvent event)
Process a log event, via formatting and outputting it.
booleanisFull()
Check if memory buffer is full.
voidpush()
Push log events to target.
protected voidsetOverwrite(boolean overwrite)
Set flag indicating whether it is valid to overwrite memory buffer.
protected booleanshouldPush(LogEvent event)
Determine if LogEvent should initiate a push to target.

Field Detail

m_buffer

private final LogEvent[] m_buffer

m_index

private int m_index

m_overwrite

private boolean m_overwrite

m_target

private LogTarget m_target

m_threshold

private Priority m_threshold

m_used

private int m_used

Constructor Detail

MemoryTarget

public MemoryTarget(LogTarget target, int size, Priority threshold)
Creation of a new instance of the memory target.

Parameters: target the target to push LogEvents to size the event buffer size threshold the priority at which to push LogEvents to next LogTarget

Method Detail

doProcessEvent

protected void doProcessEvent(LogEvent event)
Process a log event, via formatting and outputting it.

Parameters: event the log event

isFull

public final boolean isFull()
Check if memory buffer is full.

Returns: true if buffer is full, false otherwise

push

public void push()
Push log events to target.

setOverwrite

protected void setOverwrite(boolean overwrite)
Set flag indicating whether it is valid to overwrite memory buffer.

Parameters: overwrite true if buffer should overwrite logevents in buffer, false otherwise

shouldPush

protected boolean shouldPush(LogEvent event)
Determine if LogEvent should initiate a push to target. Subclasses can overide this method to change the conditions under which a push occurs.

Parameters: event the incoming LogEvent

Returns: true if should push, false otherwise