org.javasimon.jdbc.logging
Class LoggingCallback

java.lang.Object
  extended by org.javasimon.CallbackSkeleton
      extended by org.javasimon.jdbc.logging.LoggingCallback
All Implemented Interfaces:
Callback

public final class LoggingCallback
extends CallbackSkeleton

LoggingCallback implements JDBC logging logic.

LoggingCallback extends from empty Callback implementation (CallbackSkeleton) and implements two events: stopwatch start and stopwatch stop. By implementing start end stop event focusing on JDBC callback produces those JDBC events:

Class also contains two build-in formatters: LoggingCallback.HumanFormatter and LoggingCallback.CsvFormatter.

Since:
2
Version:
$Revision: 304 $ $Date: 2011-04-08 10:39:02 +0200 (Fri, 08 Apr 2011) $
Author:
Radovan Sninsky

Nested Class Summary
private static class LoggingCallback.CsvFormatter
          CsvFormatter formats log messages to comma separated value form.
private static class LoggingCallback.HumanFormatter
          HumanFormatter formats log messages to human readable form.
 
Nested classes/interfaces inherited from interface org.javasimon.Callback
Callback.Event
 
Field Summary
private  String logFilename
           
private  String logFormat
           
private  Logger logger
           
private  String loggerName
           
private  boolean logToConsole
           
private  String prefix
           
 
Constructor Summary
LoggingCallback()
          Default class constructor.
 
Method Summary
private  SimonFormatter formatter()
          Determine and returns formatter.
 String getPrefix()
          Return JDBC prefix that identifies JDBC driver that has enabled logging.
 void initialize()
          Based on parameters (could be set through setters) initialize logger, handler and formatter.
 void setLogFilename(String logFilename)
          Sets filename where log messages will be written.
 void setLogFormat(String logFormat)
          Sets log formatter for formating log messages.
 void setLoggerName(String loggerName)
          Sets logger name that will be used for log JDBC events.
 void setLogToConsole()
          Sets logging to console.
 void setPrefix(String prefix)
          Sets JDBC prefix that identifies JDBC driver that has enabled logging.
 void stopwatchStart(Split split)
          Custom start event handler for JDBC logging.
 void stopwatchStop(Split split)
          Custom stop event handler for JDBC logging.
 
Methods inherited from class org.javasimon.CallbackSkeleton
addCallback, callbacks, cleanup, clear, counterDecrease, counterIncrease, counterSet, message, removeCallback, reset, simonCreated, simonDestroyed, stopwatchAdd, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prefix

private String prefix

logFilename

private String logFilename

loggerName

private String loggerName

logToConsole

private boolean logToConsole

logFormat

private String logFormat

logger

private Logger logger
Constructor Detail

LoggingCallback

public LoggingCallback()
Default class constructor.

Method Detail

getPrefix

public String getPrefix()
Return JDBC prefix that identifies JDBC driver that has enabled logging.

Returns:
JDBC prefix
See Also:
Driver

setPrefix

public void setPrefix(String prefix)
Sets JDBC prefix that identifies JDBC driver that has enabled logging.

Parameters:
prefix - new prexif value

setLogFilename

public void setLogFilename(String logFilename)
Sets filename where log messages will be written.

Parameters:
logFilename - filename value

setLoggerName

public void setLoggerName(String loggerName)
Sets logger name that will be used for log JDBC events.

Parameters:
loggerName - new logger name value

setLogToConsole

public void setLogToConsole()
Sets logging to console.


setLogFormat

public void setLogFormat(String logFormat)
Sets log formatter for formating log messages. Formatter could be identified by identifier, if build-in formatter (HUMAN, CSV) or classname.

Parameters:
logFormat - new formatter value

initialize

public void initialize()
Based on parameters (could be set through setters) initialize logger, handler and formatter.

Specified by:
initialize in interface Callback
Overrides:
initialize in class CallbackSkeleton

formatter

private SimonFormatter formatter()
Determine and returns formatter. If no formatter is set or initialization of formatter instance failed LoggingCallback.HumanFormatter is returned.

Returns:
choosed formatter or LoggingCallback.HumanFormatter

stopwatchStart

public void stopwatchStart(Split split)
Custom start event handler for JDBC logging. Checks if stopwatch Simon is one of JDBC stopwatch and if it is connection or statement stopwatch, if yes, logs event.

Specified by:
stopwatchStart in interface Callback
Overrides:
stopwatchStart in class CallbackSkeleton
Parameters:
split - split from stopwatch from start moment

stopwatchStop

public void stopwatchStop(Split split)
Custom stop event handler for JDBC logging. Checks if stopwatch Simon is one of JDBC stopwatch, if yes, logs event.

Specified by:
stopwatchStop in interface Callback
Overrides:
stopwatchStop in class CallbackSkeleton
Parameters:
split - split from stopwatch from stop moment


Copyright © 2011. All Rights Reserved.