com.wutka.util
Class Log

java.lang.Object
  |
  +--com.wutka.util.Log

public class Log
extends java.lang.Object

A general mechanism for logging error messages. The Log class supports different clients so messages can be logged in different ways. A log entry has a severity associated with it. Log clients register to receive log messages with a minimum severity value. If there are no clients logging at the entry's severity, no further processing takes place. Thus, the overhead for debug messages is not very heavy.


Field Summary
static java.lang.String ALL
          For log clients, grab messages for all subsystems
protected static java.util.Hashtable clients
          The clients currently registered with the logger
static java.lang.String DEFAULT
          For a log entry, a default location for log messages not associated with a particular subsystem.
protected static java.lang.String hexDigits
           
protected static java.util.Hashtable minLevels
          The minimum levels being logged for each subsystem
 
Constructor Summary
Log()
           
 
Method Summary
static void addClient(java.lang.String subsystem, LogSeverity minSeverity, LogClient theClient)
          Add a new client for a particular subsystem and severity level
static void logBytes(LogSeverity severity, java.lang.String message, byte[] data)
          Logs a text message and a hex dump of data to the default subsystem
static void logBytes(LogSeverity severity, java.lang.String message, byte[] data, int offset, int length)
          Logs a text message and a hex dump of data to the default subsystem
static void logBytes(LogSeverity severity, java.lang.String subsystem, java.lang.String message, byte[] data)
          Logs a text message and a hex dump of data for a particular subsystem
static void logBytes(LogSeverity severity, java.lang.String subsystem, java.lang.String message, byte[] data, int offset, int length)
          Logs a text message and a hex dump of data for a particular subsystem
static void logException(LogSeverity severity, java.lang.String message, java.lang.Exception exc)
          Logs a text message and an exception to the default subsystem
static void logException(LogSeverity severity, java.lang.String subsystem, java.lang.String message, java.lang.Exception exc)
          Logs a text message for a particular subsystem
static void logMessage(LogSeverity severity, java.lang.String message)
          Logs a text message to the default subsystem
static void logMessage(LogSeverity severity, java.lang.String subsystem, java.lang.String message)
          Logs a text message for a particular subsystem
static java.lang.String makeHexDump(byte[] data, int offset, int length)
          Creates a string containing a hex dump of the data bytes
protected static void recomputeMinLevel(java.lang.String subsystem)
          Recalculate the minimum logging level for a subsystem (and for all)
static void removeClient(LogClient theClient)
          Removes a client from all subsystems it is logging
static void removeClient(java.lang.String subsystem, LogClient theClient)
          Removes a client that is logging messages for the named subsystems
static boolean wouldLog(java.lang.String subsystem, LogSeverity severity)
          Returns true if a message for this subsystem and severity would be logged.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final java.lang.String DEFAULT
For a log entry, a default location for log messages not associated with a particular subsystem.

ALL

public static final java.lang.String ALL
For log clients, grab messages for all subsystems

clients

protected static java.util.Hashtable clients
The clients currently registered with the logger

minLevels

protected static java.util.Hashtable minLevels
The minimum levels being logged for each subsystem

hexDigits

protected static java.lang.String hexDigits
Constructor Detail

Log

public Log()
Method Detail

addClient

public static void addClient(java.lang.String subsystem,
                             LogSeverity minSeverity,
                             LogClient theClient)
Add a new client for a particular subsystem and severity level
Parameters:
subsystem - The subsystem the client wants to receive messages for (Log.ALL for all subsystems
minSeverity - The minimum threshold for messages to be sent to this client
theClient - The client that will receive the messages

recomputeMinLevel

protected static void recomputeMinLevel(java.lang.String subsystem)
Recalculate the minimum logging level for a subsystem (and for all)
Parameters:
subsystem - The subsystem the level is being computed for

removeClient

public static void removeClient(java.lang.String subsystem,
                                LogClient theClient)
Removes a client that is logging messages for the named subsystems
Parameters:
subsystem - The subsystem the client is being removed from
theClient - The client being removed

removeClient

public static void removeClient(LogClient theClient)
Removes a client from all subsystems it is logging
Parameters:
theClient - being removed

wouldLog

public static boolean wouldLog(java.lang.String subsystem,
                               LogSeverity severity)
Returns true if a message for this subsystem and severity would be logged. This is useful if you want to check before trying to log a message, in case it is too expensive to even try to log the message.
Parameters:
subsystem - The subsystem the message would be logged for
severity - The severity level to test

logMessage

public static void logMessage(LogSeverity severity,
                              java.lang.String message)
Logs a text message to the default subsystem
Parameters:
severity - The severity level of the message
message - The message to be logged

logMessage

public static void logMessage(LogSeverity severity,
                              java.lang.String subsystem,
                              java.lang.String message)
Logs a text message for a particular subsystem
Parameters:
severity - The severity level of the message
subsystem - The subsystem being logged
message - The message to be logged

logException

public static void logException(LogSeverity severity,
                                java.lang.String message,
                                java.lang.Exception exc)
Logs a text message and an exception to the default subsystem
Parameters:
severity - The severity level of the message
message - The message to be logged
exc - The exception to be logged

logException

public static void logException(LogSeverity severity,
                                java.lang.String subsystem,
                                java.lang.String message,
                                java.lang.Exception exc)
Logs a text message for a particular subsystem
Parameters:
severity - The severity level of the message
subsystem - The subsystem being logged
message - The message to be logged
exc - The exception to be logged

logBytes

public static void logBytes(LogSeverity severity,
                            java.lang.String message,
                            byte[] data)
Logs a text message and a hex dump of data to the default subsystem
Parameters:
severity - The severity level of the message
message - The message to be logged
data - The data to be logged

logBytes

public static void logBytes(LogSeverity severity,
                            java.lang.String subsystem,
                            java.lang.String message,
                            byte[] data)
Logs a text message and a hex dump of data for a particular subsystem
Parameters:
severity - The severity level of the message
subsystem - The subsystem being logged
message - The message to be logged
data - The data to be logged

logBytes

public static void logBytes(LogSeverity severity,
                            java.lang.String message,
                            byte[] data,
                            int offset,
                            int length)
Logs a text message and a hex dump of data to the default subsystem
Parameters:
severity - The severity level of the message
message - The message to be logged
data - The data to be logged
offset - The first byte in the data to be logged
length - The number of bytes to be logged

logBytes

public static void logBytes(LogSeverity severity,
                            java.lang.String subsystem,
                            java.lang.String message,
                            byte[] data,
                            int offset,
                            int length)
Logs a text message and a hex dump of data for a particular subsystem
Parameters:
severity - The severity level of the message
subsystem - The subsystem being logged
message - The message to be logged
data - The data to be logged
offset - The first byte in the data to be logged
length - The number of bytes to be logged

makeHexDump

public static java.lang.String makeHexDump(byte[] data,
                                           int offset,
                                           int length)
Creates a string containing a hex dump of the data bytes
Parameters:
data - The bytes to be converted
offset - The offset of the first byte to be converted
length - The number of bytes to be converted
Returns:
A hex dump of the bytes