com.synametrics.commons.util.logging
Class LoggingFW

java.lang.Object
  |
  +--com.synametrics.commons.util.logging.LoggingFW

public class LoggingFW
extends java.lang.Object

This is the main class for Synametrics' Logging Framework, which is a wrapper around Apache Log4j. The benefit of a wrapper is that you can always change the underlying framework without modifying your client code. The user, in this case a programmer only calls the public methods of this class.
Usage:

private void writeLogs(){
    //Write performance log enter. The last parameter is a description
    //of the method where performances is being logged
    LoggingFW.perf(LoggingFW.ENTER,
this, "Write Log");
    slowDown();
//Sleep for a while
    //Log a DEBUG message
    LoggingFW.perf(LoggingFW.ENTER,
this, "Before debug");
    LoggingFW.log(LoggingFW.DEBUG,
this, "Total tables in database are 400");
    slowDown();
//Sleep for a while
    //Log an INFO message
    LoggingFW.perf(LoggingFW.ENTER,
this, "Before info");
    LoggingFW.log(LoggingFW.INFO,
this, "Increasing connection pool size to 20");
    slowDown();
//Sleep for a while
    //Log a WARNING message
    LoggingFW.perf(LoggingFW.ENTER,
this, "Before warning");
    LoggingFW.log(LoggingFW.WARN,
this, "Running low on memory");
    slowDown();
//Sleep for a while
    //Log an ERROR. You can also pass a thrown exception to log the stack trace
    LoggingFW.perf(LoggingFW.ENTER,
this, "Before error");
    LoggingFW.log(LoggingFW.ERROR,
this, "Invalid SQL statement");
    slowDown();
//Sleep for a while
    //Log a FATAL ERROR. You can also pass a thrown exception to log the stack trace
    LoggingFW.perf(LoggingFW.ENTER,
this, "Before fatal");
    LoggingFW.log(LoggingFW.FATAL,
this, "Database not responding");
    slowDown();
//Sleep for a while


    //Write performance log exit. The last parameter is a description
    //of the method where performances is being logged. This should
    //be same as the enter statement. This way it is easier to
    //track in the log.
    LoggingFW.perf(LoggingFW.EXIT,
this, "Before fatal");
    LoggingFW.perf(LoggingFW.EXIT,
this, "Before error");
    LoggingFW.perf(LoggingFW.EXIT,
this, "Before warning");
    LoggingFW.perf(LoggingFW.EXIT,
this, "Before info");
    LoggingFW.perf(LoggingFW.EXIT,
this, "Before debug");

    LoggingFW.perf(LoggingFW.EXIT,
this, "Write Log");

}


Field Summary
static int DEBUG
          Designates fine-grained informational events that are most useful to debug an application.
static int ENTER
          Used for performance measure to signfy enterence of a method
static int ERROR
          Designates error events that might still allow the application to continue running but are important and should be fixed ASAP.
static int EXIT
          Used for performance measure to signfy enterence of a method
static int FATAL
          Designates very severe error events that will presumably lead the application to abort.
static int INFO
          Designates informational messages that highlight the progress of the application at coarse-grained level.
static java.util.Hashtable perfCounters
          This hash table holds the performance counters.
static int WARN
          Designates potentially harmful situations.
 
Constructor Summary
LoggingFW()
           
 
Method Summary
static void enablePerformanceLogging(boolean enable)
          Enables/disables performance logging.
static void enableRemoteLoggingForPerformance(java.lang.String viewerHost, int viewerPort)
          This method should be called by a client using the Logging Framework to send the result of performance logging to a remote viewer.
static boolean isDebugEnabled(java.lang.Object caller)
           
static void log(int priority, java.lang.Object caller, java.lang.String message)
          log a message with throwable set to null.
static void log(int priority, java.lang.Object caller, java.lang.String message, java.lang.Throwable thrown)
          log a message with throwable set to null.
static void perf(int direction, java.lang.Object caller, java.lang.String message)
          This method is used for measuring performance.
static void setPerformanceViewer(PerformanceViewer aViewer)
          This method should be called by a log viewer client to register itself with the logging framework.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FATAL

public static final int FATAL
Designates very severe error events that will presumably lead the application to abort. For instance, a required RDBMS system is unavailable

See Also:
Constant Field Values

ERROR

public static final int ERROR
Designates error events that might still allow the application to continue running but are important and should be fixed ASAP. For instance, a required lookup table in an RDBMS system is missing and as a result the application will read stale data from a text file.

See Also:
Constant Field Values

WARN

public static final int WARN
Designates potentially harmful situations. For instance, available memory is too low.

See Also:
Constant Field Values

INFO

public static final int INFO
Designates informational messages that highlight the progress of the application at coarse-grained level. For instance, during system initialization a program displays the total number of available connection in a database connection pool object.

See Also:
Constant Field Values

DEBUG

public static final int DEBUG
Designates fine-grained informational events that are most useful to debug an application. For instance, before and after an object in the business tier is about to compute a lengthy process.

See Also:
Constant Field Values

ENTER

public static final int ENTER
Used for performance measure to signfy enterence of a method

See Also:
Constant Field Values

EXIT

public static final int EXIT
Used for performance measure to signfy enterence of a method

See Also:
Constant Field Values

perfCounters

public static java.util.Hashtable perfCounters
This hash table holds the performance counters. Each element in the hash table is for a thread.

Constructor Detail

LoggingFW

public LoggingFW()
Method Detail

isDebugEnabled

public static boolean isDebugEnabled(java.lang.Object caller)

log

public static void log(int priority,
                       java.lang.Object caller,
                       java.lang.String message,
                       java.lang.Throwable thrown)
log a message with throwable set to null.

Parameters:
priority - Priority level. Can be FATAL, ERROR, WARN, INFO, DEBUG
caller - Caller class name. This acts a the log4j Logger
message - The actual message to log
thrown - Original throwable object

log

public static void log(int priority,
                       java.lang.Object caller,
                       java.lang.String message)
log a message with throwable set to null.

Parameters:
priority - Priority level. Can be FATAL, ERROR, WARN, INFO, DEBUG
caller - Caller class name. This acts a the log4j logger
message - The actual message to log

perf

public static void perf(int direction,
                        java.lang.Object caller,
                        java.lang.String message)
This method is used for measuring performance.

Parameters:
direction - This must be either ENTER or EXIT
caller - This can be either String or any other object from where the method is getting called
message - A user defined message

setPerformanceViewer

public static void setPerformanceViewer(PerformanceViewer aViewer)
This method should be called by a log viewer client to register itself with the logging framework. This method should be called only if you are using the remote logging feature of the Logging Framework

Parameters:
aViewer - This object will receive incoming messages.

enableRemoteLoggingForPerformance

public static void enableRemoteLoggingForPerformance(java.lang.String viewerHost,
                                                     int viewerPort)
This method should be called by a client using the Logging Framework to send the result of performance logging to a remote viewer. The viewer can be on any machine and it listens on port 7500 by default. You can change the default port setting by specifying a system property.

Parameters:
viewerHost - Host name of the machine where the viewer is running
viewerPort - TCP/IP port number on which the viewer is listening. The default value is 7500. If you change this to a different number make sure that you change it in the viewer as well.

enablePerformanceLogging

public static void enablePerformanceLogging(boolean enable)
Enables/disables performance logging.

Parameters:
enable - If true performance logging will be enabled and false otherwise. By default performance logging is ON. All the messages will be sent to the console