|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.synametrics.commons.util.logging.LoggingFW
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.
private
void writeLogs(){
Usage:
//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 |
public static final int FATAL
public static final int ERROR
public static final int WARN
public static final int INFO
public static final int DEBUG
public static final int ENTER
public static final int EXIT
public static java.util.Hashtable perfCounters
Constructor Detail |
public LoggingFW()
Method Detail |
public static boolean isDebugEnabled(java.lang.Object caller)
public static void log(int priority, java.lang.Object caller, java.lang.String message, java.lang.Throwable thrown)
priority
- Priority level. Can be FATAL, ERROR, WARN, INFO, DEBUGcaller
- Caller class name. This acts a the log4j Loggermessage
- The actual message to logthrown
- Original throwable objectpublic static void log(int priority, java.lang.Object caller, java.lang.String message)
priority
- Priority level. Can be FATAL, ERROR, WARN, INFO, DEBUGcaller
- Caller class name. This acts a the log4j loggermessage
- The actual message to logpublic static void perf(int direction, java.lang.Object caller, java.lang.String message)
direction
- This must be either ENTER or EXITcaller
- This can be either String or any other object from where the method is getting calledmessage
- A user defined messagepublic static void setPerformanceViewer(PerformanceViewer aViewer)
aViewer
- This object will receive incoming messages.public static void enableRemoteLoggingForPerformance(java.lang.String viewerHost, int viewerPort)
viewerHost
- Host name of the machine where the viewer is runningviewerPort
- 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.public static void enablePerformanceLogging(boolean enable)
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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |