java.util.logging
Class Handler

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.logging.Handler
Direct Known Subclasses:
MemoryHandler sample code for java.util.logging.MemoryHandler definition code for java.util.logging.MemoryHandler , StreamHandler sample code for java.util.logging.StreamHandler definition code for java.util.logging.StreamHandler

public abstract class Handler
extends Object sample code for java.lang.Object definition code for java.lang.Object

A Handler object takes log messages from a Logger and exports them. It might for example, write them to a console or write them to a file, or send them to a network logging service, or forward them to an OS log, or whatever.

A Handler can be disabled by doing a setLevel(Level.OFF) and can be re-enabled by doing a setLevel with an appropriate level.

Handler classes typically use LogManager properties to set default values for the Handler's Filter, Formatter, and Level. See the specific documentation for each concrete Handler class.

Since:
1.4

Constructor Summary
protected Handler sample code for java.util.logging.Handler.Handler() definition code for java.util.logging.Handler.Handler() ()
          Default constructor.
 
Method Summary
abstract  void close sample code for java.util.logging.Handler.close() definition code for java.util.logging.Handler.close() ()
          Close the Handler and free all associated resources.
abstract  void flush sample code for java.util.logging.Handler.flush() definition code for java.util.logging.Handler.flush() ()
          Flush any buffered output.
 String sample code for java.lang.String definition code for java.lang.String getEncoding sample code for java.util.logging.Handler.getEncoding() definition code for java.util.logging.Handler.getEncoding() ()
          Return the character encoding for this Handler.
 ErrorManager sample code for java.util.logging.ErrorManager definition code for java.util.logging.ErrorManager getErrorManager sample code for java.util.logging.Handler.getErrorManager() definition code for java.util.logging.Handler.getErrorManager() ()
          Retrieves the ErrorManager for this Handler.
 Filter sample code for java.util.logging.Filter definition code for java.util.logging.Filter getFilter sample code for java.util.logging.Handler.getFilter() definition code for java.util.logging.Handler.getFilter() ()
          Get the current Filter for this Handler.
 Formatter sample code for java.util.logging.Formatter definition code for java.util.logging.Formatter getFormatter sample code for java.util.logging.Handler.getFormatter() definition code for java.util.logging.Handler.getFormatter() ()
          Return the Formatter for this Handler.
 Level sample code for java.util.logging.Level definition code for java.util.logging.Level getLevel sample code for java.util.logging.Handler.getLevel() definition code for java.util.logging.Handler.getLevel() ()
          Get the log level specifying which messages will be logged by this Handler.
 boolean 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) (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.
abstract  void 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) (LogRecord sample code for java.util.logging.LogRecord definition code for java.util.logging.LogRecord  record)
          Publish a LogRecord.
protected  void 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) (String sample code for java.lang.String definition code for java.lang.String  msg, Exception sample code for java.lang.Exception definition code for java.lang.Exception  ex, int code)
          Protected convenience method to report an error to this Handler's ErrorManager.
 void setEncoding sample code for java.util.logging.Handler.setEncoding(java.lang.String) definition code for java.util.logging.Handler.setEncoding(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  encoding)
          Set the character encoding used by this Handler.
 void 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) (ErrorManager sample code for java.util.logging.ErrorManager definition code for java.util.logging.ErrorManager  em)
          Define an ErrorManager for this Handler.
 void 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) (Filter sample code for java.util.logging.Filter definition code for java.util.logging.Filter  newFilter)
          Set a Filter to control output on this Handler.
 void 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) (Formatter sample code for java.util.logging.Formatter definition code for java.util.logging.Formatter  newFormatter)
          Set a Formatter.
 void 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) (Level sample code for java.util.logging.Level definition code for java.util.logging.Level  newLevel)
          Set the log level specifying which message levels will be logged by this Handler.
 
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

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

protected Handler()
Default constructor. The resulting Handler has a log level of Level.ALL, no Formatter, and no Filter. A default ErrorManager instance is installed as the ErrorManager.

Method Detail

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)

public abstract void publish(LogRecord sample code for java.util.logging.LogRecord definition code for java.util.logging.LogRecord  record)
Publish a LogRecord.

The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

The Handler is responsible for formatting the message, when and if necessary. The formatting should include localization.

Parameters:
record - description of the log event. A null record is silently ignored and is not published

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

public abstract void flush()
Flush any buffered output.


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

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

The close method will perform a flush and then close the Handler. After close has been called this Handler should no longer be used. Method calls may either be silently ignored or may throw runtime exceptions.

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").

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)

public void setFormatter(Formatter sample code for java.util.logging.Formatter definition code for java.util.logging.Formatter  newFormatter)
                  throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Set a Formatter. This Formatter will be used to format LogRecords for this Handler.

Some Handlers may not use Formatters, in which case the Formatter will be remembered, but not used.

Parameters:
newFormatter - the Formatter to use (may not be null)
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").

getFormatter sample code for java.util.logging.Handler.getFormatter() definition code for java.util.logging.Handler.getFormatter()

public Formatter sample code for java.util.logging.Formatter definition code for java.util.logging.Formatter  getFormatter()
Return the Formatter for this Handler.

Returns:
the Formatter (may be null).

setEncoding sample code for java.util.logging.Handler.setEncoding(java.lang.String) definition code for java.util.logging.Handler.setEncoding(java.lang.String)

public void setEncoding(String sample code for java.lang.String definition code for java.lang.String  encoding)
                 throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException ,
                        UnsupportedEncodingException sample code for java.io.UnsupportedEncodingException definition code for java.io.UnsupportedEncodingException 
Set the character encoding used by this Handler.

The encoding should be set before any LogRecords are written to the Handler.

Parameters:
encoding - The name of a supported character encoding. May be null, to indicate the default platform encoding.
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").
UnsupportedEncodingException - if the named encoding is not supported.

getEncoding sample code for java.util.logging.Handler.getEncoding() definition code for java.util.logging.Handler.getEncoding()

public String sample code for java.lang.String definition code for java.lang.String  getEncoding()
Return the character encoding for this Handler.

Returns:
The encoding name. May be null, which indicates the default encoding should be used.

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)

public void setFilter(Filter sample code for java.util.logging.Filter definition code for java.util.logging.Filter  newFilter)
               throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Set a Filter to control output on this Handler.

For each call of publish the Handler will call this Filter (if it is non-null) to check if the LogRecord should be published or discarded.

Parameters:
newFilter - a Filter object (may be null)
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").

getFilter sample code for java.util.logging.Handler.getFilter() definition code for java.util.logging.Handler.getFilter()

public Filter sample code for java.util.logging.Filter definition code for java.util.logging.Filter  getFilter()
Get the current Filter for this Handler.

Returns:
a Filter object (may be null)

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)

public void setErrorManager(ErrorManager sample code for java.util.logging.ErrorManager definition code for java.util.logging.ErrorManager  em)
Define an ErrorManager for this Handler.

The ErrorManager's "error" method will be invoked if any errors occur while using this Handler.

Parameters:
em - the new ErrorManager
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").

getErrorManager sample code for java.util.logging.Handler.getErrorManager() definition code for java.util.logging.Handler.getErrorManager()

public ErrorManager sample code for java.util.logging.ErrorManager definition code for java.util.logging.ErrorManager  getErrorManager()
Retrieves the ErrorManager for this 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").

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)

protected void reportError(String sample code for java.lang.String definition code for java.lang.String  msg,
                           Exception sample code for java.lang.Exception definition code for java.lang.Exception  ex,
                           int code)
Protected convenience method to report an error to this Handler's ErrorManager. Note that this method retrieves and uses the ErrorManager without doing a security check. It can therefore be used in environments where the caller may be non-privileged.

Parameters:
msg - a descriptive string (may be null)
ex - an exception (may be null)
code - an error code defined in ErrorManager

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)

public void setLevel(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 log level specifying which message levels will be logged by this Handler. Message levels lower than this value will be discarded.

The intention is to allow developers to turn on voluminous logging, but to limit the messages that are sent to certain Handlers.

Parameters:
newLevel - the new value for the log level
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").

getLevel sample code for java.util.logging.Handler.getLevel() definition code for java.util.logging.Handler.getLevel()

public Level sample code for java.util.logging.Level definition code for java.util.logging.Level  getLevel()
Get the log level specifying which messages will be logged by this Handler. Message levels lower than this level will be discarded.

Returns:
the level of messages being logged.

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)

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.

This method checks if the LogRecord has an appropriate Level and whether it satisfies any Filter. It also may make other Handler specific checks that might prevent a handler from logging the LogRecord. It will return false if the LogRecord is Null.

Parameters:
record - a LogRecord
Returns:
true if the LogRecord would be logged.