java.util.logging
Class MemoryHandler

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.logging.Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler 
      extended by java.util.logging.MemoryHandler

public class MemoryHandler
extends Handler sample code for java.util.logging.Handler definition code for java.util.logging.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:

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.

Since:
1.4

Constructor Summary
MemoryHandler sample code for java.util.logging.MemoryHandler.MemoryHandler() definition code for java.util.logging.MemoryHandler.MemoryHandler() ()
          Create a MemoryHandler and configure it based on LogManager configuration properties.
MemoryHandler sample code for java.util.logging.MemoryHandler.MemoryHandler(java.util.logging.Handler, int, java.util.logging.Level) definition code for java.util.logging.MemoryHandler.MemoryHandler(java.util.logging.Handler, int, java.util.logging.Level) (Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler  target, int size, Level sample code for java.util.logging.Level definition code for java.util.logging.Level  pushLevel)
          Create a MemoryHandler.
 
Method Summary
 void close sample code for java.util.logging.MemoryHandler.close() definition code for java.util.logging.MemoryHandler.close() ()
          Close the Handler and free all associated resources.
 void flush sample code for java.util.logging.MemoryHandler.flush() definition code for java.util.logging.MemoryHandler.flush() ()
          Causes a flush on the target Handler.
 Level sample code for java.util.logging.Level definition code for java.util.logging.Level getPushLevel sample code for java.util.logging.MemoryHandler.getPushLevel() definition code for java.util.logging.MemoryHandler.getPushLevel() ()
          Get the pushLevel.
 boolean isLoggable sample code for java.util.logging.MemoryHandler.isLoggable(java.util.logging.LogRecord) definition code for java.util.logging.MemoryHandler.isLoggable(java.util.logging.LogRecord) (LogRecord sample code for java.util.logging.LogRecord definition code for java.util.logging.LogRecord  record)
          Check if this Handler would actually log a given LogRecord into its internal buffer.
 void publish sample code for java.util.logging.MemoryHandler.publish(java.util.logging.LogRecord) definition code for java.util.logging.MemoryHandler.publish(java.util.logging.LogRecord) (LogRecord sample code for java.util.logging.LogRecord definition code for java.util.logging.LogRecord  record)
          Store a LogRecord in an internal buffer.
 void push sample code for java.util.logging.MemoryHandler.push() definition code for java.util.logging.MemoryHandler.push() ()
          Push any buffered output to the target Handler.
 void setPushLevel sample code for java.util.logging.MemoryHandler.setPushLevel(java.util.logging.Level) definition code for java.util.logging.MemoryHandler.setPushLevel(java.util.logging.Level) (Level sample code for java.util.logging.Level definition code for java.util.logging.Level  newLevel)
          Set the pushLevel.
 
Methods inherited from class java.util.logging.Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler
getEncoding sample code for java.util.logging.Handler.getEncoding() definition code for java.util.logging.Handler.getEncoding() , getErrorManager sample code for java.util.logging.Handler.getErrorManager() definition code for java.util.logging.Handler.getErrorManager() , getFilter sample code for java.util.logging.Handler.getFilter() definition code for java.util.logging.Handler.getFilter() , getFormatter sample code for java.util.logging.Handler.getFormatter() definition code for java.util.logging.Handler.getFormatter() , getLevel sample code for java.util.logging.Handler.getLevel() definition code for java.util.logging.Handler.getLevel() , reportError sample code for java.util.logging.Handler.reportError(java.lang.String, java.lang.Exception, int) definition code for java.util.logging.Handler.reportError(java.lang.String, java.lang.Exception, int) , setEncoding sample code for java.util.logging.Handler.setEncoding(java.lang.String) definition code for java.util.logging.Handler.setEncoding(java.lang.String) , setErrorManager sample code for java.util.logging.Handler.setErrorManager(java.util.logging.ErrorManager) definition code for java.util.logging.Handler.setErrorManager(java.util.logging.ErrorManager) , setFilter sample code for java.util.logging.Handler.setFilter(java.util.logging.Filter) definition code for java.util.logging.Handler.setFilter(java.util.logging.Filter) , setFormatter sample code for java.util.logging.Handler.setFormatter(java.util.logging.Formatter) definition code for java.util.logging.Handler.setFormatter(java.util.logging.Formatter) , setLevel sample code for java.util.logging.Handler.setLevel(java.util.logging.Level) definition code for java.util.logging.Handler.setLevel(java.util.logging.Level)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

MemoryHandler sample code for java.util.logging.MemoryHandler() definition code for java.util.logging.MemoryHandler()

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


MemoryHandler sample code for java.util.logging.MemoryHandler(java.util.logging.Handler, int, java.util.logging.Level) definition code for java.util.logging.MemoryHandler(java.util.logging.Handler, int, java.util.logging.Level)

public MemoryHandler(Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler  target,
                     int size,
                     Level sample code for java.util.logging.Level definition code for java.util.logging.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 - the Handler to which to publish output.
size - the number of log records to buffer (must be greater than zero)
pushLevel - message level to push on
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - is size is <= 0
Method Detail

publish sample code for java.util.logging.MemoryHandler.publish(java.util.logging.LogRecord) definition code for java.util.logging.MemoryHandler.publish(java.util.logging.LogRecord)

public void publish(LogRecord sample code for java.util.logging.LogRecord definition code for java.util.logging.LogRecord  record)
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.

Specified by:
publish sample code for java.util.logging.Handler.publish(java.util.logging.LogRecord) definition code for java.util.logging.Handler.publish(java.util.logging.LogRecord) in class Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler
Parameters:
record - description of the log event. A null record is silently ignored and is not published

push sample code for java.util.logging.MemoryHandler.push() definition code for java.util.logging.MemoryHandler.push()

public void push()
Push any buffered output to the target Handler.

The buffer is then cleared.


flush sample code for java.util.logging.MemoryHandler.flush() definition code for java.util.logging.MemoryHandler.flush()

public void 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".

Specified by:
flush sample code for java.util.logging.Handler.flush() definition code for java.util.logging.Handler.flush() in class Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler

close sample code for java.util.logging.MemoryHandler.close() definition code for java.util.logging.MemoryHandler.close()

public void close()
           throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Close the Handler and free all associated resources. This will also close the target Handler.

Specified by:
close sample code for java.util.logging.Handler.close() definition code for java.util.logging.Handler.close() in class Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

setPushLevel sample code for java.util.logging.MemoryHandler.setPushLevel(java.util.logging.Level) definition code for java.util.logging.MemoryHandler.setPushLevel(java.util.logging.Level)

public void setPushLevel(Level sample code for java.util.logging.Level definition code for java.util.logging.Level  newLevel)
                  throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
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 - the new value of the pushLevel
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

getPushLevel sample code for java.util.logging.MemoryHandler.getPushLevel() definition code for java.util.logging.MemoryHandler.getPushLevel()

public Level sample code for java.util.logging.Level definition code for java.util.logging.Level  getPushLevel()
Get the pushLevel.

Returns:
the value of the pushLevel

isLoggable sample code for java.util.logging.MemoryHandler.isLoggable(java.util.logging.LogRecord) definition code for java.util.logging.MemoryHandler.isLoggable(java.util.logging.LogRecord)

public boolean isLoggable(LogRecord sample code for java.util.logging.LogRecord definition code for java.util.logging.LogRecord  record)
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.

Overrides:
isLoggable sample code for java.util.logging.Handler.isLoggable(java.util.logging.LogRecord) definition code for java.util.logging.Handler.isLoggable(java.util.logging.LogRecord) in class Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler
Parameters:
record - a LogRecord
Returns:
true if the LogRecord would be logged.