java.util.logging
Class StreamHandler

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.StreamHandler
Direct Known Subclasses:
ConsoleHandler sample code for java.util.logging.ConsoleHandler definition code for java.util.logging.ConsoleHandler , FileHandler sample code for java.util.logging.FileHandler definition code for java.util.logging.FileHandler , SocketHandler sample code for java.util.logging.SocketHandler definition code for java.util.logging.SocketHandler

public class StreamHandler
extends Handler sample code for java.util.logging.Handler definition code for java.util.logging.Handler

Stream based logging Handler.

This is primarily intended as a base class or support class to be used in implementing other logging Handlers.

LogRecords are published to a given java.io.OutputStream.

Configuration: By default each StreamHandler is initialized using the following LogManager configuration properties. If properties are not defined (or have invalid values) then the specified default values are used.

Since:
1.4

Constructor Summary
StreamHandler sample code for java.util.logging.StreamHandler.StreamHandler() definition code for java.util.logging.StreamHandler.StreamHandler() ()
          Create a StreamHandler, with no current output stream.
StreamHandler sample code for java.util.logging.StreamHandler.StreamHandler(java.io.OutputStream, java.util.logging.Formatter) definition code for java.util.logging.StreamHandler.StreamHandler(java.io.OutputStream, java.util.logging.Formatter) (OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out, Formatter sample code for java.util.logging.Formatter definition code for java.util.logging.Formatter  formatter)
          Create a StreamHandler with a given Formatter and output stream.
 
Method Summary
 void close sample code for java.util.logging.StreamHandler.close() definition code for java.util.logging.StreamHandler.close() ()
          Close the current output stream.
 void flush sample code for java.util.logging.StreamHandler.flush() definition code for java.util.logging.StreamHandler.flush() ()
          Flush any buffered messages.
 boolean isLoggable sample code for java.util.logging.StreamHandler.isLoggable(java.util.logging.LogRecord) definition code for java.util.logging.StreamHandler.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.
 void publish sample code for java.util.logging.StreamHandler.publish(java.util.logging.LogRecord) definition code for java.util.logging.StreamHandler.publish(java.util.logging.LogRecord) (LogRecord sample code for java.util.logging.LogRecord definition code for java.util.logging.LogRecord  record)
          Format and publish a LogRecord.
 void setEncoding sample code for java.util.logging.StreamHandler.setEncoding(java.lang.String) definition code for java.util.logging.StreamHandler.setEncoding(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  encoding)
          Set (or change) the character encoding used by this Handler.
protected  void setOutputStream sample code for java.util.logging.StreamHandler.setOutputStream(java.io.OutputStream) definition code for java.util.logging.StreamHandler.setOutputStream(java.io.OutputStream) (OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out)
          Change the output stream.
 
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) , 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

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

public StreamHandler()
Create a StreamHandler, with no current output stream.


StreamHandler sample code for java.util.logging.StreamHandler(java.io.OutputStream, java.util.logging.Formatter) definition code for java.util.logging.StreamHandler(java.io.OutputStream, java.util.logging.Formatter)

public StreamHandler(OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out,
                     Formatter sample code for java.util.logging.Formatter definition code for java.util.logging.Formatter  formatter)
Create a StreamHandler with a given Formatter and output stream.

Parameters:
out - the target output stream
formatter - Formatter to be used to format output
Method Detail

setOutputStream sample code for java.util.logging.StreamHandler.setOutputStream(java.io.OutputStream) definition code for java.util.logging.StreamHandler.setOutputStream(java.io.OutputStream)

protected void setOutputStream(OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out)
                        throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Change the output stream.

If there is a current output stream then the Formatter's tail string is written and the stream is flushed and closed. Then the output stream is replaced with the new output stream.

Parameters:
out - New output stream. 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").

setEncoding sample code for java.util.logging.StreamHandler.setEncoding(java.lang.String) definition code for java.util.logging.StreamHandler.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 (or change) the character encoding used by this Handler.

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

Overrides:
setEncoding sample code for java.util.logging.Handler.setEncoding(java.lang.String) definition code for java.util.logging.Handler.setEncoding(java.lang.String) in class Handler sample code for java.util.logging.Handler definition code for java.util.logging.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 sample code for java.io.UnsupportedEncodingException definition code for java.io.UnsupportedEncodingException - if the named encoding is not supported.

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

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

The StreamHandler first checks if there is an OutputStream and if the given LogRecord has at least the required log level. If not it silently returns. If so, it calls any associated Filter to check if the record should be published. If so, it calls its Formatter to format the record and then writes the result to the current output stream.

If this is the first LogRecord to be written to a given OutputStream, the Formatter's "head" string is written to the stream before the LogRecord is written.

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

isLoggable sample code for java.util.logging.StreamHandler.isLoggable(java.util.logging.LogRecord) definition code for java.util.logging.StreamHandler.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 will also return false if no output stream has been assigned yet or 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.

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

public void flush()
Flush any buffered messages.

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.StreamHandler.close() definition code for java.util.logging.StreamHandler.close()

public void close()
           throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Close the current output stream.

The Formatter's "tail" string is written to the stream before it is closed. In addition, if the Formatter's "head" string has not yet been written to the stream, it will be written before the "tail" string.

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