Peer locator v1.0

com.unet.warmachine.peerlocator
Class Logger

java.lang.Object
  |
  +--com.unet.warmachine.peerlocator.Logger

public class Logger
extends java.lang.Object

This class is a simple logger and is used for debugging purposes. Messages logged by this class are displayed on standard output or can be diverted to file. Messages are associated with a severity and category. Each category can be configured to suppress messages of a specific severity or lower. All variables and functions are static, so no instance needs to be referenced but multiple Loggers can't exist.


Field Summary
static int CATEGORY_CONNECTION
          Acknowledgement/rejection of connections between agents.
static int CATEGORY_DEBUG
          Various debugging information.
static int CATEGORY_MEMBER_EXCH
          Events concerning new members, exchange of membership lists and location.
static int CATEGORY_MESSAGE_RCVD
          Details of incoming messages.
static int CATEGORY_MESSAGE_SENT
          Details of outgoing messages.
static int CATEGORY_SEARCH
          Search algorithm for other agents.
static int CATEGORY_SERVICE_REQ
          Service requests and results of public interfaces.
static int CATEGORY_SOCKET
          Creation and deletion of sockets.
static int CATEGORY_STARTSTOP
          Startup/shutdown information.
static int CATEGORY_TESTCLIENT
          Reserved for agent clients.
static boolean logOn
          Whether logging is enabled.
static int SEVERITY_DETAIL1
          Provides medium level information such as algorithm results, service configuration or events.
static int SEVERITY_DETAIL2
          Provides low level information.
static int SEVERITY_ERROR
          The highest severity level and indicates a function has failed or exception that can't be handled.
static int SEVERITY_INFO
          Provides high level information such as start or end of major service.
static int SEVERITY_NONE
          This severity level is used by setCategoryMask() to suppress all messages of a category; it is not a message severity itself.
static int SEVERITY_TRACE
          Records trace of function entry and exits with parameters and results.
static int SEVERITY_WARNING
          Indicates an unexpected or erroneous condition that does not make function fail and can be ignored or an exception that can be handled.
 
Method Summary
static int getCategoryMask(int category)
          Returns lowest severity level that can be displayed for category.
static long getLogMask()
          Returns complete category suppression list encoded as 32-bit integer.
static void logMessage(int category, int severity, java.lang.String message)
          Displays message to standard output, file or output stream as configured.
static void logMessage(int category, int severity, java.lang.String message, java.lang.Exception e)
          Displays message, exception class, message and stack trace to standard output, file or output stream as configured.
static void setCategoryMask(int category, int severity)
          Sets lowest severity level that can be displayed for category.
static void setLogFile(java.lang.String filename)
          Sets output log file.
static void setLogMask(int logMask)
          Sets category suppression list encoded as 32-bit integer.
static void setLogStream(java.io.OutputStream outStream)
          Sets output stream for logging messages.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logOn

public static final boolean logOn
Whether logging is enabled. This switch can only be changed at compile time.

SEVERITY_NONE

public static final int SEVERITY_NONE
This severity level is used by setCategoryMask() to suppress all messages of a category; it is not a message severity itself.

SEVERITY_ERROR

public static final int SEVERITY_ERROR
The highest severity level and indicates a function has failed or exception that can't be handled.

SEVERITY_WARNING

public static final int SEVERITY_WARNING
Indicates an unexpected or erroneous condition that does not make function fail and can be ignored or an exception that can be handled.

SEVERITY_INFO

public static final int SEVERITY_INFO
Provides high level information such as start or end of major service.

SEVERITY_DETAIL1

public static final int SEVERITY_DETAIL1
Provides medium level information such as algorithm results, service configuration or events.

SEVERITY_DETAIL2

public static final int SEVERITY_DETAIL2
Provides low level information.

SEVERITY_TRACE

public static final int SEVERITY_TRACE
Records trace of function entry and exits with parameters and results.

CATEGORY_DEBUG

public static final int CATEGORY_DEBUG
Various debugging information.

CATEGORY_TESTCLIENT

public static final int CATEGORY_TESTCLIENT
Reserved for agent clients.

CATEGORY_SERVICE_REQ

public static final int CATEGORY_SERVICE_REQ
Service requests and results of public interfaces.

CATEGORY_STARTSTOP

public static final int CATEGORY_STARTSTOP
Startup/shutdown information.

CATEGORY_SOCKET

public static final int CATEGORY_SOCKET
Creation and deletion of sockets.

CATEGORY_MESSAGE_RCVD

public static final int CATEGORY_MESSAGE_RCVD
Details of incoming messages.

CATEGORY_MESSAGE_SENT

public static final int CATEGORY_MESSAGE_SENT
Details of outgoing messages.

CATEGORY_CONNECTION

public static final int CATEGORY_CONNECTION
Acknowledgement/rejection of connections between agents.

CATEGORY_SEARCH

public static final int CATEGORY_SEARCH
Search algorithm for other agents.

CATEGORY_MEMBER_EXCH

public static final int CATEGORY_MEMBER_EXCH
Events concerning new members, exchange of membership lists and location.
Method Detail

getLogMask

public static long getLogMask()
Returns complete category suppression list encoded as 32-bit integer. Encoding scheme is not described here.
Returns:
Encoded category suppression list.

setLogMask

public static void setLogMask(int logMask)
Sets category suppression list encoded as 32-bit integer. Encoding scheme is not described here.
Parameters:
logMask - Encoded category suppression list.

getCategoryMask

public static int getCategoryMask(int category)
Returns lowest severity level that can be displayed for category.
Parameters:
category - See CATEGORY_ constants.
Returns:
Lowest, displayed severity level for category.

setCategoryMask

public static void setCategoryMask(int category,
                                   int severity)
Sets lowest severity level that can be displayed for category.
Parameters:
category - See CATEGORY_ constants.
severity - Lowest, displayed severity level for category.

setLogFile

public static void setLogFile(java.lang.String filename)
                       throws java.io.FileNotFoundException
Sets output log file.
Parameters:
filename - Filename of log file.
Throws:
java.io.FileNotFoundException - Error creating or opening file.

setLogStream

public static void setLogStream(java.io.OutputStream outStream)
Sets output stream for logging messages.
Parameters:
outStream - Output stream.

logMessage

public static void logMessage(int category,
                              int severity,
                              java.lang.String message)
Displays message to standard output, file or output stream as configured.
Parameters:
category - Category of message. See CATEGORY_ constants.
severity - Severity level of message. See SEVERITY_ constants.
message - Message to output.

logMessage

public static void logMessage(int category,
                              int severity,
                              java.lang.String message,
                              java.lang.Exception e)
Displays message, exception class, message and stack trace to standard output, file or output stream as configured.
Parameters:
category - Category of message. See CATEGORY_ constants.
severity - Severity level of message. See SEVERITY_ constants.
message - Message to output.
e - Exception to display, with stack trace.

Peer locator v1.0