Class MemoryTarget
java.lang.Object
org.apache.log.output.AbstractTarget
org.apache.log.output.MemoryTarget
- All Implemented Interfaces:
ErrorAware, LogTarget, Closeable
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
FieldsModifier and TypeFieldDescriptionprivate final LogEvent[]Buffer for all the LogEventsprivate intPosition of last element insertedprivate booleanFlag indicating whether it is possible to overite elements in arrayprivate LogTargetTarget to push LogEvents toprivate PriorityPriority at which to push LogEvents to next LogTargetprivate intCount of used events -
Constructor Summary
ConstructorsConstructorDescriptionMemoryTarget(LogTarget target, int size, Priority threshold) Creation of a new instance of the memory target. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoProcessEvent(LogEvent event) Process a log event, via formatting and outputting it.final 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.Methods inherited from class AbstractTarget
close, getErrorHandler, isOpen, open, processEvent, setErrorHandler
-
Field Details
-
m_buffer
Buffer for all the LogEvents -
m_threshold
Priority at which to push LogEvents to next LogTarget -
m_target
Target to push LogEvents to -
m_used
private int m_usedCount of used events -
m_index
private int m_indexPosition of last element inserted -
m_overwrite
private boolean m_overwriteFlag indicating whether it is possible to overite elements in array
-
-
Constructor Details
-
MemoryTarget
-
-
Method Details
-
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
-
doProcessEvent
Process a log event, via formatting and outputting it.- Specified by:
doProcessEventin classAbstractTarget- Parameters:
event- the log event
-
isFull
public final boolean isFull()Check if memory buffer is full.- Returns:
- true if buffer is full, false otherwise
-
shouldPush
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
-
push
public void push()Push log events to target.
-