MemoryHandler

public class MemoryHandler extends Handler

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:

  • An incoming LogRecord has a type that is greater than a pre-defined level, the pushLevel.
  • An external class calls the push method explicitly.
  • A subclass overrides the 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. 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.

  • java.util.logging.MemoryHandler.level specifies the level for the Handler (defaults to Level.ALL).
  • java.util.logging.MemoryHandler.filter specifies the name of a Filter class to use (defaults to no Filter).
  • java.util.logging.MemoryHandler.size defines the buffer size (defaults to 1000).
  • java.util.logging.MemoryHandler.push defines the pushLevel (defaults to level.SEVERE).
  • java.util.logging.MemoryHandler.target specifies the name of the target Handler class. (no default).

Public Constructor Summary

MemoryHandler()
Create a MemoryHandler and configure it based on LogManager configuration properties.
MemoryHandler(Handler target, int size, Level pushLevel)
Create a MemoryHandler.

Public Method Summary

void
close()
Close the Handler and free all associated resources.
void
flush()
Causes a flush on the target Handler.
synchronized Level
getPushLevel()
Get the pushLevel.
boolean
isLoggable(LogRecord record)
Check if this Handler would actually log a given LogRecord into its internal buffer.
synchronized void
publish(LogRecord record)
Store a LogRecord in an internal buffer.
synchronized void
push()
Push any buffered output to the target Handler.
void
setPushLevel(Level newLevel)
Set the pushLevel.

Inherited Method Summary

Public Constructors

public MemoryHandler ()

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