Class Overview
A handler that writes log messages to a socket connection.
This handler reads the following properties from the log manager to
initialize itself:
- java.util.logging.ConsoleHandler.level specifies the logging level,
defaults to
Level.ALL
if this property is not found or has an invalid
value.
- java.util.logging.SocketHandler.filter specifies the name of the filter
class to be associated with this handler, defaults to
null
if this
property is not found or has an invalid value.
- java.util.logging.SocketHandler.formatter specifies the name of the
formatter class to be associated with this handler, defaults to
java.util.logging.XMLFormatter
if this property is not found or has
an invalid value.
- java.util.logging.SocketHandler.encoding specifies the encoding this
handler will use to encode log messages, defaults to
null
if this
property is not found or has an invalid value.
- java.util.logging.SocketHandler.host specifies the name of the host that
this handler should connect to. There's no default value for this property.
- java.util.logging.SocketHandler.encoding specifies the port number that
this handler should connect to. There's no default value for this property.
This handler buffers the outgoing messages, but flushes each time a log
record has been published.
This class is not thread-safe.
Summary
Public Constructors |
|
SocketHandler()
Constructs a SocketHandler object using the properties read by
the log manager, including the host name and port number.
|
|
SocketHandler(String host, int port)
Constructs a SocketHandler object using the specified host name
and port number together with other properties read by the log manager.
|
Public Methods |
void
|
close()
Closes this handler.
|
void
|
publish(LogRecord record)
Logs a record if necessary.
|
[Expand]
Inherited Methods |
From class java.util.logging.StreamHandler
|
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()
Called before the object's memory is reclaimed by the VM.
|
final
Class<? extends Object>
|
getClass()
Returns the unique instance of Class that 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()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method 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.
|
|
Public Constructors
public
SocketHandler
()
Constructs a SocketHandler
object using the properties read by
the log manager, including the host name and port number. Default
formatting uses the XMLFormatter class and level is set to ALL.
Throws
IOException
| if failed to connect to the specified host and port. |
IllegalArgumentException
| if the host name or port number is illegal. |
SecurityException
| if a security manager determines that the caller does not
have the required permission to control this handler.
|
public
SocketHandler
(String host, int port)
Constructs a SocketHandler
object using the specified host name
and port number together with other properties read by the log manager.
Default formatting uses the XMLFormatter class and level is set to ALL.
Parameters
host
| the host name |
port
| the port number |
Throws
IOException
| if failed to connect to the specified host and port. |
IllegalArgumentException
| if the host name or port number is illegal. |
SecurityException
| if a security manager determines that the caller does not
have the required permission to control this handler.
|
Public Methods
public
void
close
()
Closes this handler. The network connection to the host is also closed.
Throws
SecurityException
| If a security manager determines that the caller does not
have the required permission to control this handler.
|
public
void
publish
(LogRecord record)
Logs a record if necessary. A flush operation will be done afterwards.
Parameters
record
| the log record to be logged.
|