vc.util
Class Logger

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--vc.util.Logger
All Implemented Interfaces:
java.lang.Runnable

public class Logger
extends java.lang.Thread

Title: Logger Description: Logger is a simple class that can offer many features of logging in a very powerfull manner. This class offers the logging features are provided in a userfriendly manner. The features are provided by this class are sufficient for most of the project requirements and it can be extended for more feture. It's features include : 1. Cache the log messages and write the log using a background thread 2. Frequency of the log writing can be set based upon requirements 3. Logging to multiple I/O devices is supported including Console, files and other type of streams 4. Abstraction for logging the Exceptions, different levels of logging, timestamps, different formats of logging etc. For using the class instantiate it with the required parameters and access its methods.


Field Summary
static int DebugLevel_High
          This flag/constant is to be used for setting the debug level on.
static int DebugLevel_Highest
          This flag/constant is to be used for setting the debug level on.
static int DebugLevel_Low
          This flag/constant is to be used for setting the debug level on.
static int DebugLevel_Lowest
          This flag/constant is to be used for setting the debug level on.
static int DebugLevel_Medium
          This flag/constant is to be used for setting the debug level on.
static int DebugLevel_Off
          This flag/constant is to be used for setting the debugging to off.
static int ExceptionLogLevel_OriginOnly
          This flag/constant is to be used if the Exception message is to be logged with the information that an exception of a particular type was raised.
static int ExceptionLogLevel_WithMessage
          This flag/constant is to be used if the Exception message is to be logged with the detailed information.
static int ExceptionLogLevel_WithStackTrace
          This flag/constant is to be used if the Exception message is to be logged with the detailed information and stacktrace will be logged into the I/O devices like console and streams.
static int LogFormat_MsgTypeFirst
          This flag/constant is to be used if the log entries should be made in a format as , ,
static int LogFormat_TimeStampFirst
          This flag/constant is to be used if the log entries should be made in a format as , ,
static int LoggingFrequency_High
          This flag/constant is to be used if the logging activity is very high in a particular application.
static int LoggingFrequency_Low
          This flag/constant is to be used if the logging activity is not very high in a particular application.
static int LoggingFrequency_Medium
          This flag/constant is to be used if the logging activity is neigther very high nor very low in a particular application.
static int LoggingType_CacheAndLog
          This flag/constant is to be used if messages are to be cached/queued and then logged by using abackground thread.
static int LoggingType_LogImmediatly
          This flag/constant is to be used if messages are to be logged immediatly without queuing.
static int MsgType_Critical
          This flag/constant is to be used if the log message is a Critical Error
static int MsgType_Error
          This flag/constant is to be used if the log message is an Error
static int MsgType_Exception
          This flag/constant is to be used if the log message is an Exception Information
static int MsgType_Info
          This flag/constant is to be used if the log message is an Information
static int MsgType_UserDef
          This flag/constant is to be used if the log message is user-defined/non-standard
static int MsgType_Warning
          This flag/constant is to be used if the log message is a Warning
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Logger(int loggingType)
          Logger() - This constructor is to be used for constructing the object which dont log the messages to a file(atleast initially).
Logger(java.lang.String logFileName, int loggingType, int loggingFrequency)
          Logger() - This constructor is to be used for constructing the object which will log the messages to a file in addition to other I/O devices like Console.
 
Method Summary
 void addExtraLogDevice(java.io.OutputStream logStream)
          Adds OutputStream object to the list of existing log devices.
 void addExtraLogDevice(java.io.Writer logWriter)
          Adds LogWriter object to the list of existing log devices.
 void finalize()
          This method does the clenup for the object before it dies.
 boolean getConsoleLogging()
          Returns the current console logging status of the Logger object.
 int getDebugLevel()
          Returns the current debugging level of the Logger object.
 java.io.FileOutputStream getLogFile()
          Returns the default log file associated with the Logger object
 int getLogFormat()
          Returns the current logging format of this object
 void logDebugMessage(int debugLevel, java.lang.String message)
          Synchronized method logDebugMessage() - Writes the debug messages to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object.
 void logException(IgnorableException iex, java.lang.String source)
          Synchronized method logException() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object.
 void logException(java.lang.Throwable catchedException, int exceptionLogLevel)
          Synchronized method logException() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object.
 void logException(VCException catchedException, java.lang.String source)
          Synchronized method logException() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object.
 void logExceptionWithMessage(java.lang.Throwable catchedException, int exceptionLogLevel, int messageType, java.lang.String message, java.lang.String customMessageTitle)
          Synchronized method logExceptionWithMessage() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object.
 void logMessage(int messageType, java.lang.String message, java.lang.String customMessageTitle)
          Synchronized method logMessage() - Writes the log messages to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object.
 void logMessageWithoutCaching(java.lang.String message)
          Synchronized method logMessageWithoutCaching() - Writes the messages to the log devices directly without caching the messages in a queue.
 void removeAllExtraLogDevices()
          This will remove all the extra log devices that existwith this object.
 void run()
          This method is for the multithreaded functionality required by the objects of Logger.
 void setConsoleLogging(boolean isConsoleLog)
          Console Logging can be turned on and off with this method.
 void setDebugLevel(int debugLevel)
          sets the current debug level of the Logger object.
 void setLogFile(java.io.FileOutputStream logFile)
          Sets/Resets the Logger object's data memeber logFile to the parameter logFile.
 void setLogFile(java.lang.String logFileName)
          Sets/Resets the Logger object's data memeber logFile to the file named with the value of the parameter logFileName.
 void setLogFormat(int logFormat)
          Sets the Logger object's logging format with the parameter logFormat.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LoggingType_CacheAndLog

public static final int LoggingType_CacheAndLog
This flag/constant is to be used if messages are to be cached/queued and then logged by using abackground thread. This way much time wont be taken for I/O operations.

LoggingType_LogImmediatly

public static final int LoggingType_LogImmediatly
This flag/constant is to be used if messages are to be logged immediatly without queuing. This way much time may be taken for doing I/O operations.

LogFormat_TimeStampFirst

public static final int LogFormat_TimeStampFirst
This flag/constant is to be used if the log entries should be made in a format as , ,

LogFormat_MsgTypeFirst

public static final int LogFormat_MsgTypeFirst
This flag/constant is to be used if the log entries should be made in a format as , ,

MsgType_UserDef

public static final int MsgType_UserDef
This flag/constant is to be used if the log message is user-defined/non-standard

MsgType_Info

public static final int MsgType_Info
This flag/constant is to be used if the log message is an Information

MsgType_Warning

public static final int MsgType_Warning
This flag/constant is to be used if the log message is a Warning

MsgType_Error

public static final int MsgType_Error
This flag/constant is to be used if the log message is an Error

MsgType_Critical

public static final int MsgType_Critical
This flag/constant is to be used if the log message is a Critical Error

MsgType_Exception

public static final int MsgType_Exception
This flag/constant is to be used if the log message is an Exception Information

ExceptionLogLevel_OriginOnly

public static final int ExceptionLogLevel_OriginOnly
This flag/constant is to be used if the Exception message is to be logged with the information that an exception of a particular type was raised.

ExceptionLogLevel_WithMessage

public static final int ExceptionLogLevel_WithMessage
This flag/constant is to be used if the Exception message is to be logged with the detailed information.

ExceptionLogLevel_WithStackTrace

public static final int ExceptionLogLevel_WithStackTrace
This flag/constant is to be used if the Exception message is to be logged with the detailed information and stacktrace will be logged into the I/O devices like console and streams.

LoggingFrequency_Medium

public static final int LoggingFrequency_Medium
This flag/constant is to be used if the logging activity is neigther very high nor very low in a particular application. Based upon this value, the Logger will optimize the cycles/time required for logging activities.

LoggingFrequency_Low

public static final int LoggingFrequency_Low
This flag/constant is to be used if the logging activity is not very high in a particular application. Based upon this value, the Logger will optimize the cycles/time required for logging activities.

LoggingFrequency_High

public static final int LoggingFrequency_High
This flag/constant is to be used if the logging activity is very high in a particular application. Based upon this value, the Logger will optimize the cycles/time required for logging activities.

DebugLevel_Off

public static final int DebugLevel_Off
This flag/constant is to be used for setting the debugging to off. It is the lowest level of the debugging.

DebugLevel_Lowest

public static final int DebugLevel_Lowest
This flag/constant is to be used for setting the debug level on. It is the lowest level of the debugging.

DebugLevel_Low

public static final int DebugLevel_Low
This flag/constant is to be used for setting the debug level on. It is the low level of the debugging.

DebugLevel_Medium

public static final int DebugLevel_Medium
This flag/constant is to be used for setting the debug level on. It is the medium level of the debugging. Also this is the default debugging level.

DebugLevel_High

public static final int DebugLevel_High
This flag/constant is to be used for setting the debug level on. It is the high level of the debugging.

DebugLevel_Highest

public static final int DebugLevel_Highest
This flag/constant is to be used for setting the debug level on. It is the highest level of the debugging.
Constructor Detail

Logger

public Logger(int loggingType)
Logger() - This constructor is to be used for constructing the object which dont log the messages to a file(atleast initially).
Parameters:
loggingType - is to tell if caching of log messages is required or not. Its value is taken from one of the constants loggingType_CacheAndLog and loggingType_LogImmediatly.

Logger

public Logger(java.lang.String logFileName,
              int loggingType,
              int loggingFrequency)
       throws java.io.IOException
Logger() - This constructor is to be used for constructing the object which will log the messages to a file in addition to other I/O devices like Console.
Parameters:
logFileName - is the name of the file to which the log is to be generated.
loggingType - is to indicate if caching of log messages is required or not. This parameter takes the value from one of the constants loggingType_CacheAndLog and loggingType_LogImmediatly.
loggingFrequency - is to indicate the frequency of doing the logging activities. Value of this parameter will be used only if log messages are cached. This parameter takes the value from one of the constants loggingFrequency_Medium, loggingFrequency_Low and loggingFrequency_High.
Method Detail

logMessageWithoutCaching

public void logMessageWithoutCaching(java.lang.String message)
Synchronized method logMessageWithoutCaching() - Writes the messages to the log devices directly without caching the messages in a queue. Also this wont add any additional log information like timestamp, message type etc.
Parameters:
message - Is the actual string that will be logged into the log devices.

logDebugMessage

public void logDebugMessage(int debugLevel,
                            java.lang.String message)
Synchronized method logDebugMessage() - Writes the debug messages to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object. This method makes a log entry with additional information like timestamp etc.
Parameters:
debugLevel - Is the parameter that will write the string information about log level. Takes its value from one of the constants : 1. debugLevel_Off 2. debugLevel_Lowest 3. debugLevel_Low 4. debugLevel_Medium 5. debugLevel_High 6. debugLevel_High
message - Is the actual string that will be logged into the log devices.

logMessage

public void logMessage(int messageType,
                       java.lang.String message,
                       java.lang.String customMessageTitle)
Synchronized method logMessage() - Writes the log messages to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object. This method makes a log entry with additional information like timestamp etc.
Parameters:
messageType - Is the parameter that will write the string information about log level. Takes its value from one of the constants : 1. MsgType_UserDef 2. MsgType_Info 3. MsgType_Warning 4. MsgType_Error 5. MsgType_Critical 6. MsgType_Exception
message - Is the actual string that will be logged into the log devices.
customMessageTitle - Is the parameter that carries the title of the custom log level, "messageType" parameter takes the value MsgType_UserDef, or else will be null.

logException

public void logException(java.lang.Throwable catchedException,
                         int exceptionLogLevel)
Synchronized method logException() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object. This method makes a log entry with the information extracted from the exception object passed as the parameter. The information varies according to the parameter ExceptionLogLevel
Parameters:
catchedException - Is the parameter that carries the exception object whose information is to be logged.
exceptionLogLevel - Is the parameter that will write the string information about log level for exceptions.Takes its value from one of the constants: 1. ExceptionLogLevel_OriginOnly 2. ExceptionLogLevel_WithMessage 3. ExceptionLogLevel_WithStackTrace

logExceptionWithMessage

public void logExceptionWithMessage(java.lang.Throwable catchedException,
                                    int exceptionLogLevel,
                                    int messageType,
                                    java.lang.String message,
                                    java.lang.String customMessageTitle)
Synchronized method logExceptionWithMessage() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object. Along with the exception information, additional information related to the same context can be looged. This method makes a log entry with the information extracted from the exception object passed as the parameter. The information varies according to the parameter exceptionLogLevel
Parameters:
catchedException - Is the parameter that carries the exception object whose information is to be logged.
exceptionLogLevel - Is the parameter that will write the string information about log level for exceptions.Takes its value from one of the constants: 1. ExceptionLogLevel_OriginOnly 2. ExceptionLogLevel_WithMessage 3. ExceptionLogLevel_WithStackTrace
messageType - Is the parameter that will write the string information about log level. Takes its value from one of the constants : 1. MsgType_UserDef 2. MsgType_Info 3. MsgType_Warning 4. MsgType_Error 5. MsgType_Critical 6. MsgType_Exception
message - Is the actual string that will be logged into the log devices.
customMessageTitle - Is the parameter that carries the title of the custom log level, "messageType" parameter takes the value Msgype_UserDef, or else will be null.

run

public void run()
This method is for the multithreaded functionality required by the objects of Logger. If Logger object uses the queueing of log messages, then this method will execute in a different thread to extract the log messages from the queue and then write them to the log devices.
Overrides:
run in class java.lang.Thread

setLogFile

public void setLogFile(java.lang.String logFileName)
                throws java.io.IOException
Sets/Resets the Logger object's data memeber logFile to the file named with the value of the parameter logFileName. If alredy a file is associated with the object it will be closed and a new one will be opened.
Parameters:
logFileName - Is to carry the file name that should be set as the log file.
Throws:
java.io.IOException -  

setLogFile

public void setLogFile(java.io.FileOutputStream logFile)
                throws java.io.IOException
Sets/Resets the Logger object's data memeber logFile to the parameter logFile. If alredy a file is associated with the object it will be closed and a new one will be set.
Parameters:
logFile - Is the FileOutputStream object that should be set as the log file.
Throws:
java.io.IOException -  

getLogFile

public java.io.FileOutputStream getLogFile()
Returns the default log file associated with the Logger object
Returns:
Returns the data memeber of the object logFile

setConsoleLogging

public void setConsoleLogging(boolean isConsoleLog)
Console Logging can be turned on and off with this method. This will immediatly take affect, and the next comming messages(even those in the queue) will be logged accordingly.
Parameters:
isConsoleLog - If carries a value "true" then the next messages will be logged into the console also, or else they wont be logged to the console.

getConsoleLogging

public boolean getConsoleLogging()
Returns the current console logging status of the Logger object.
Returns:
Returns current console logging status of the Logger object using the data memeber isConsoleLog.

setDebugLevel

public void setDebugLevel(int debugLevel)
sets the current debug level of the Logger object.
Parameters:
debugLevel - is to set the dubug level and it takes effect immediatly

getDebugLevel

public int getDebugLevel()
Returns the current debugging level of the Logger object.
Returns:
Returns current debugging level of the Logger object using the data memeber debugLevel.

addExtraLogDevice

public void addExtraLogDevice(java.io.OutputStream logStream)
Adds OutputStream object to the list of existing log devices. This will immediatly take affect, and the next comming messages(even those in the queue) will be logged accordingly. This log device is an extra log device(i.e one other than console and file log devices)
Parameters:
logStream - Is the extra log device to which the log is to be written.

addExtraLogDevice

public void addExtraLogDevice(java.io.Writer logWriter)
Adds LogWriter object to the list of existing log devices. This will immediatly take affect, and the next comming messages(even those in the queue) will be logged accordingly. This log device is an extra log device(i.e one other than console and file log devices)
Parameters:
logWriter - Is the extra log device to which the log is to be written.

removeAllExtraLogDevices

public void removeAllExtraLogDevices()
This will remove all the extra log devices that existwith this object. This will immediatly take affect, and the next comming messages(even those in the queue) will be logged accordingly. After this new log devices can be added ad needed.

setLogFormat

public void setLogFormat(int logFormat)
Sets the Logger object's logging format with the parameter logFormat.
Parameters:
logFormat - Is to set the Logger object's logging format. It can take the value from one of the following. 1. logFormat_TimeStampFirst 2. logFormat_MsgTypeFirst

getLogFormat

public int getLogFormat()
Returns the current logging format of this object
Returns:
Returns the data memeber of the object logFormat that holds the objects current logging format.

finalize

public void finalize()
This method does the clenup for the object before it dies. It closes the IODevices held by this object, so that the information in them becomes persistent.
Overrides:
finalize in class java.lang.Object

logException

public void logException(VCException catchedException,
                         java.lang.String source)
Synchronized method logException() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object. This method makes a log entry with the information extracted from the exception object passed as the parameter. The information varies according to the parameter ExceptionLogLevel
Parameters:
catchedException - Is the parameter that carries the CORBA exception object whose information is to be logged.
source - IS the string carrying the location of the object which is the source of this exception

logException

public void logException(IgnorableException iex,
                         java.lang.String source)
Synchronized method logException() - Writes the exception inmformation to the log devices eigther by queueing the message or writing it directly to the log devices, based upon the looggingType parameter passed to the constructor of the object. This method makes a log entry with the information extracted from the exception object passed as the parameter. The information varies according to the parameter ExceptionLogLevel
Parameters:
catchedException - Is the parameter that carries the CORBA exception which is not serious and can be ignored , and its information will be logged.
source - IS the string carrying the location of the object which is the source of this exception