Known Direct Subclasses
ConsoleHandler |
A handler that writes log messages to the standard output stream
System.err . |
FileHandler |
A FileHandler writes logging records into a specified file or a
rotating set of files. |
SocketHandler |
A handler that writes log messages to a socket connection. |
|
Class Overview
A StreamHandler
object writes log messages to an output stream, that
is, objects of the class OutputStream
.
A StreamHandler
object reads the following properties from the log
manager to initialize itself. A default value will be used if a property is
not found or has an invalid value.
- java.util.logging.StreamHandler.encoding specifies the encoding this
handler will use to encode log messages. Default is the encoding used by the
current platform.
- java.util.logging.StreamHandler.filter specifies the name of the filter
class to be associated with this handler. No
Filter
is used by
default.
- java.util.logging.StreamHandler.formatter specifies the name of the
formatter class to be associated with this handler. Default is
java.util.logging.SimpleFormatter
.
- java.util.logging.StreamHandler.level specifies the logging level.
Defaults is
Level.INFO
.
This class is not thread-safe.
Summary
Public Methods |
void
|
close()
Closes this handler.
|
void
|
flush()
Flushes any buffered output.
|
boolean
|
isLoggable(LogRecord record)
Determines whether the supplied log record needs to be logged.
|
synchronized
void
|
publish(LogRecord record)
Accepts a logging request.
|
void
|
setEncoding(String encoding)
Sets the character encoding used by this handler.
|
[Expand]
Inherited Methods |
From class java.util.logging.Handler
abstract
void
|
close()
Closes this handler.
|
abstract
void
|
flush()
Flushes any buffered output.
|
String
|
getEncoding()
Gets the character encoding used by this handler, null for
default encoding.
|
ErrorManager
|
getErrorManager()
Gets the error manager used by this handler to report errors during
logging.
|
Filter
|
getFilter()
Gets the filter used by this handler.
|
Formatter
|
getFormatter()
Gets the formatter used by this handler to format the logging messages.
|
Level
|
getLevel()
Gets the logging level of this handler, records with levels lower than
this value will be dropped.
|
boolean
|
isLoggable(LogRecord record)
Determines whether the supplied log record needs to be logged.
|
abstract
void
|
publish(LogRecord record)
Accepts a logging request and sends it to the the target.
|
void
|
reportError(String msg, Exception ex, int code)
Reports an error to the error manager associated with this handler,
ErrorManager is used for that purpose.
|
void
|
setEncoding(String encoding)
Sets the character encoding used by this handler, null indicates
a default encoding.
|
void
|
setErrorManager(ErrorManager em)
Sets the error manager for this handler.
|
void
|
setFilter(Filter newFilter)
Sets the filter to be used by this handler.
|
void
|
setFormatter(Formatter newFormatter)
Sets the formatter to be used by this handler.
|
void
|
setLevel(Level newLevel)
Sets the logging level of the messages logged by this handler, levels
lower than this value will be dropped.
|
|
From class java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Is called before the object's memory is being reclaimed by the VM.
|
final
Class<? extends Object>
|
getClass()
Returns the unique instance of Class which represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
|
Public Constructors
public
StreamHandler
()
Constructs a StreamHandler
object. The new stream handler
does not have an associated output stream.
Constructs a StreamHandler
object with the supplied output stream
and formatter.
Parameters
os
| the output stream this handler writes to. |
formatter
| the formatter this handler uses to format the output. |
Public Methods
public
void
close
()
Closes this handler. The tail string of the formatter associated with
this handler is written out. A flush operation and a subsequent close
operation is then performed upon the output stream. Client applications
should not use a handler after closing it.
Throws
SecurityException
| if a security manager determines that the caller does not
have the required permission.
|
public
void
flush
()
Flushes any buffered output.
public
boolean
isLoggable
(LogRecord record)
Determines whether the supplied log record needs to be logged. The
logging levels are checked as well as the filter. The output stream of
this handler is also checked. If it is null
, this method returns
false
.
Notice : Case of no output stream will return false
.
Parameters
record
| the log record to be checked. |
Returns
true
if record
needs to be logged, false
otherwise.
public
synchronized
void
publish
(LogRecord record)
Accepts a logging request. The log record is formatted and written to the
output stream if the following three conditions are met:
- the supplied log record has at least the required logging level;
- the supplied log record passes the filter associated with this
handler, if any;
- the output stream associated with this handler is not
null
.
If it is the first time a log record is written out, the head string of
the formatter associated with this handler is written out first.
Parameters
record
| the log record to be logged.
|
public
void
setEncoding
(String encoding)
Sets the character encoding used by this handler. A null
value
indicates that the default encoding should be used.
Parameters
encoding
| the character encoding to set. |
Protected Methods
protected
void
setOutputStream
(OutputStream os)
Sets the output stream this handler writes to. If there's an existing
output stream, the tail string of the associated formatter will be
written to it. Then it will be flushed, closed and replaced with
os
.
Parameters
os
| the new output stream. |