FileDocCategorySizeDatePackage
Handler.javaAPI DocJava SE 5 API9740Fri Aug 26 14:57:28 BST 2005java.util.logging

Handler

public abstract class Handler extends 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.

version
1.17, 01/12/04
since
1.4

Fields Summary
private static final int
offValue
private LogManager
manager
private Filter
filter
private Formatter
formatter
private Level
logLevel
private ErrorManager
errorManager
private String
encoding
boolean
sealed
Constructors Summary
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.


                                     
      
    
Methods Summary
voidcheckAccess()

	if (sealed) {
	    manager.checkAccess();
	}
    
public abstract voidclose()
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.

exception
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

public abstract voidflush()
Flush any buffered output.

public java.lang.StringgetEncoding()
Return the character encoding for this Handler.

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

	return encoding;
    
public java.util.logging.ErrorManagergetErrorManager()
Retrieves the ErrorManager for this Handler.

exception
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

	checkAccess();
	return errorManager;
    
public java.util.logging.FiltergetFilter()
Get the current Filter for this Handler.

return
a Filter object (may be null)

	return filter;
    
public java.util.logging.FormattergetFormatter()
Return the Formatter for this Handler.

return
the Formatter (may be null).

	return formatter;
    
public synchronized java.util.logging.LevelgetLevel()
Get the log level specifying which messages will be logged by this Handler. Message levels lower than this level will be discarded.

return
the level of messages being logged.

	return logLevel;
    
public booleanisLoggable(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.

param
record a LogRecord
return
true if the LogRecord would be logged.

	int levelValue = getLevel().intValue();
	if (record.getLevel().intValue() < levelValue || levelValue == offValue) {
	    return false;
	}
	Filter filter = getFilter();
	if (filter == null) {	
	    return true;
	}
	return filter.isLoggable(record);
    
public abstract voidpublish(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.

param
record description of the log event. A null record is silently ignored and is not published

protected voidreportError(java.lang.String msg, 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.

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

	try {
	    errorManager.error(msg, ex, code);
	} catch (Exception ex2) {
	    System.err.println("Handler.reportError caught:");	
	    ex2.printStackTrace();
	}
    
public voidsetEncoding(java.lang.String encoding)
Set the character encoding used by this Handler.

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

param
encoding The name of a supported character encoding. May be null, to indicate the default platform encoding.
exception
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").
exception
UnsupportedEncodingException if the named encoding is not supported.

	checkAccess();
	if (encoding != null) {
	    // Check the encoding exists.
	    sun.io.CharToByteConverter.getConverter(encoding);
	}
	this.encoding = encoding;
    
public voidsetErrorManager(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.

param
em the new ErrorManager
exception
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

	checkAccess();
	if (em == null) {
	   throw new NullPointerException();
	}
	errorManager = em;
    
public voidsetFilter(java.util.logging.Filter newFilter)
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.

param
newFilter a Filter object (may be null)
exception
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

	checkAccess();
	filter = newFilter;
    
public voidsetFormatter(java.util.logging.Formatter newFormatter)
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.

param
newFormatter the Formatter to use (may not be null)
exception
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

	checkAccess();
	// Check for a null pointer:
	newFormatter.getClass();
	formatter = newFormatter;
    
public synchronized voidsetLevel(java.util.logging.Level newLevel)
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.

param
newLevel the new value for the log level
exception
SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

	if (newLevel == null) {
	    throw new NullPointerException();
	}
	checkAccess();
	logLevel = newLevel;