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:
LogRecord has a type that is greater than
a pre-defined level, the pushLevel. push method explicitly. log method and scans each incoming
LogRecord and calls push if a record matches some
desired criteria.
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.
Handler
(defaults to Level.ALL). Filter class to use
(defaults to no Filter). pushLevel (defaults to level.SEVERE). Handler class.
(no default).
For example, the properties for MemoryHandler would be:
For a custom handler, e.g. com.foo.MyHandler, the properties would be:
| Modifier and Type | Field and Description |
|---|---|
| private LogRecord[] | |
| pack-priv int | |
| private static final int | |
| private volatile Level | |
| private int | |
| pack-priv int | |
| private Handler |
| Access | Constructor and Description |
|---|---|
| public | MemoryHandler()
Create a |
| 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 |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements abstract java. Close the |
| public void | |
| public Level | |
| private void | |
| public boolean | Returns: true if theLogRecord would be logged.a record)LogRecord (may be null).Overrides java. Check if this |
| public synchronized void | publish(LogRecord
description of the log event. A null record is
silently ignored and is not published record)Implements abstract java. Store a |
| public synchronized void | |
| public synchronized void |
| buffer | back to summary |
|---|---|
| private LogRecord[] buffer | |
| count | back to summary |
|---|---|
| pack-priv int count | |
| DEFAULT_SIZE | back to summary |
|---|---|
| private static final int DEFAULT_SIZE | |
| pushLevel | back to summary |
|---|---|
| private volatile Level pushLevel | |
| size | back to summary |
|---|---|
| private int size | |
| start | back to summary |
|---|---|
| pack-priv int start | |
| target | back to summary |
|---|---|
| private Handler target | |
| MemoryHandler | back to summary |
|---|---|
| public MemoryHandler() Create a | |
| MemoryHandler | back to summary |
|---|---|
| public MemoryHandler(Handler target, int size, Level pushLevel) Create a
The
| |
| close | back to summary |
|---|---|
| public void close() Implements abstract java. Close the
| |
| flush | back to summary |
|---|---|
| public void flush() Implements abstract java. Causes a flush on the target
Note that the current contents of the
| |
| getPushLevel | back to summary |
|---|---|
| public Level getPushLevel() Get the
| |
| init | back to summary |
|---|---|
| private void init() | |
| isLoggable | back to summary |
|---|---|
| public boolean isLoggable(LogRecord record) Overrides java. Check if this
This method checks if the | |
| publish | back to summary |
|---|---|
| public synchronized void publish(LogRecord record) Implements abstract java. Store a
If there is a | |
| push | back to summary |
|---|---|
| public synchronized void push() Push any buffered output to the target The buffer is then cleared. | |
| setPushLevel | back to summary |
|---|---|
| public synchronized void setPushLevel(Level newLevel) Set the
| |