java.util.logging
Class StreamHandler
A StreamHandler
publishes LogRecords
to
a instances of java.io.OutputStream
.
StreamHandler() - Creates a
StreamHandler without an output stream.
|
StreamHandler(OutputStream out, Formatter formatter) - Creates a
StreamHandler that formats log messages
with the specified Formatter and publishes them to the specified
output stream.
|
void | close() - Closes this
StreamHandler after having forced any
data that may have been buffered to the underlying output
device.
|
void | flush() - Forces any data that may have been buffered to the underlying
output device.
|
boolean | isLoggable(LogRecord record) - Checks whether or not a
LogRecord would be logged
if it was passed to this StreamHandler for publication.
|
void | publish(LogRecord record) - Publishes a
LogRecord to the associated output
stream, provided the record passes all tests for being loggable.
|
void | setEncoding(String encoding) - Sets the character encoding which this handler uses for publishing
log records.
|
protected void | setOutputStream(OutputStream out) - Changes the output stream to which this handler publishes
logging records.
|
close , flush , getEncoding , getErrorManager , getFilter , getFormatter , getLevel , isLoggable , publish , reportError , setEncoding , setErrorManager , setFilter , setFormatter , setLevel |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
StreamHandler
public StreamHandler(OutputStream out,
Formatter formatter)
Creates a StreamHandler
that formats log messages
with the specified Formatter and publishes them to the specified
output stream.
out
- the output stream to which the formatted log messages
are published.formatter
- the Formatter
that will be used
to format log messages.
close
public void close()
throws SecurityException
Closes this
StreamHandler
after having forced any
data that may have been buffered to the underlying output
device.
As soon as
close
has been called,
a
Handler
should not be used anymore. Attempts
to publish log records, to flush buffers, or to modify the
Handler
in any other way may throw runtime
exceptions after calling
close
.
In case of an I/O failure, the
ErrorManager
of this
Handler
will be informed, but the caller
of this method will not receive an exception.
If a
StreamHandler
that has been closed earlier
is closed a second time, the Sun J2SE 1.4 reference can be
observed to silently ignore the call. The GNU implementation,
however, intentionally behaves differently by informing the
ErrorManager
associated with this
StreamHandler
. Since the condition indicates a
programming error, the programmer should be informed. It also
seems extremely unlikely that any application would depend on the
exact behavior in this rather obscure, erroneous case --
especially since the API specification does not prescribe what is
supposed to happen.
- close in interface Handler
SecurityException
- if a security manager exists and
the caller is not granted the permission to control
the logging infrastructure.
flush
public void flush()
Forces any data that may have been buffered to the underlying
output device.
In case of an I/O failure, the
ErrorManager
of this
Handler
will be informed, but the caller
of this method will not receive an exception.
If a
StreamHandler
that has been closed earlier
is closed a second time, the Sun J2SE 1.4 reference can be
observed to silently ignore the call. The GNU implementation,
however, intentionally behaves differently by informing the
ErrorManager
associated with this
StreamHandler
. Since the condition indicates a
programming error, the programmer should be informed. It also
seems extremely unlikely that any application would depend on the
exact behavior in this rather obscure, erroneous case --
especially since the API specification does not prescribe what is
supposed to happen.
- flush in interface Handler
isLoggable
public boolean isLoggable(LogRecord record)
Checks whether or not a
LogRecord
would be logged
if it was passed to this
StreamHandler
for publication.
The
StreamHandler
implementation first checks
whether a writer is present and the handler's level is greater
than or equal to the severity level threshold. In a second step,
if a
Filter
has been installed, its
isLoggable
method is
invoked. Subclasses of
StreamHandler
can override
this method to impose their own constraints.
- isLoggable in interface Handler
record
- the LogRecord
to be checked.
true
if record
would
be published by publish
,
false
if it would be discarded.
publish
public void publish(LogRecord record)
Publishes a
LogRecord
to the associated output
stream, provided the record passes all tests for being loggable.
The
StreamHandler
will localize the message of the
log record and substitute any message parameters.
Most applications do not need to call this method directly.
Instead, they will use use a
Logger
, which will create
LogRecords and distribute them to registered handlers.
In case of an I/O failure, the
ErrorManager
of this
Handler
will be informed, but the caller
of this method will not receive an exception.
If a log record is being published to a
StreamHandler
that has been closed earlier, the Sun
J2SE 1.4 reference can be observed to silently ignore the
call. The GNU implementation, however, intentionally behaves
differently by informing the
ErrorManager
associated
with this
StreamHandler
. Since the condition
indicates a programming error, the programmer should be
informed. It also seems extremely unlikely that any application
would depend on the exact behavior in this rather obscure,
erroneous case -- especially since the API specification does not
prescribe what is supposed to happen.
- publish in interface Handler
record
- the log event to be published.
setEncoding
public void setEncoding(String encoding)
throws SecurityException,
UnsupportedEncodingException
Sets the character encoding which this handler uses for publishing
log records. The encoding of a StreamHandler
must be
set before any log records have been published.
- setEncoding in interface Handler
encoding
- the name of a character encoding, or null
for the default encoding.
SecurityException
- if a security manager exists and
the caller is not granted the permission to control the
the logging infrastructure.IllegalStateException
- if any log records have been
published to this StreamHandler
before. Please
be aware that this is a pecularity of the GNU implementation.
While the API specification indicates that it is an error
if the encoding is set after records have been published,
it does not mandate any specific behavior for that case.
StreamHandler.java --
A class for publishing log messages to instances of java.io.OutputStream
Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.