![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Example property file: ################################################################# ################################################################# module_log=com.p6spy.engine.logging.P6LogSpyDriver ################################################################# # realdriver = org.gjt.mm.mysql.Driver ################################################################ ################################################################
# comma separated list of tables to include # sql expression to evaluate if using regex # filter what is logged # turn on tracing # sets the date format using Java's SimpleDateFormat routine #list of categories to explicitly include #list of categories to exclude: info, batch, debug, statement, #allows you to use a regex engine or your own matching engine to determine
# prints a stack trace for every statement logged # determines if property file should be reloaded #For log4j logging #log4j.appender.CHAINSAW_CLIENT=org.apache.log4j.net.SocketAppender log4j.logger.p6spy=INFO,STDOUT module_xxx module_xxx is the name of a particular module to be loaded at system startup. A module contains a group of functionality. If a module line is not commented out, it is loaded into memory, and will remain in memory until the application is restarted. Modules can not be changed by using the reloadproperties function. If all modules are commented out, then nothing except the real database driver is loaded. Currently the following modules are supported: module_log=com.p6spy.engine.logging.P6LogSpyDriver module_log
is required for the logging functionality, see P6Log. realdriver realdriver is where you specify the real database driver that you use. P6Spy wraps around your existing driver, intercepts the incoming database requests, and outputs them to a log file. To achieve this without requiring any code changes, the P6Spy driver is listed with your application as the primary driver. P6Spy then intercepts and logs the requests, and passes the request to the realdriver where it is processed as usual. Example: realdriver = oracle.jdbc.driver.OracleDriver realdriver2, realdriver3 if you have multiple database drivers then you need a way to specify these drivers. This is where realdriver2 and realdriver3 are used. To monitor the first database, you modified your server settings or application settings to tell your application to use P6Spy as your database driver, which is: com.p6spy.engine.spy.P6SpyDriver For the second database, specify the driver as com.p6spy.engine.spy.P6SpyDriver2 and set realdriver2 to the real driver. For the third database, specify the driver as com.p6spy.engine.spy.P6SpyDriver3 and set realdriver3 to the real driver. Note that if you are using the same database driver with multiple connection strings, you should use the same driver. E.g. say you have two MySQL databses: mydb and testdb. You want to connect to both databases and log their activity. You have two datasources defined. You should specify com.p6spy.engine.spy.P6SpyDriver as the database driver for both of these and you should set the realdriver= the real mysql JDBC driver name. realdriver2, realdriver3 are only intended for use when you are connecting with two different drivers, for example Oracle versus MySQL. To understand why this is the case, remember that Java uses the DriverManager to register all of the drivers. As each class is loaded, it registers itself with the DriverManager. When a connection is requested for a specific URL, the driver manager goes through the list of registered drivers and asks each in turn if it will handle that url (via the acceptURL method). The first driver that says yes becomes the driver that is used. Since an Oracle driver can handle any valid Oracle URL, registering the driver twice will just cause only one of the drivers (the first one that was registered) to handle the request. The second will be ignored. Therefore, if you specify the same driver in realdriver and realdriver2 you won't have any problems, but you will have the same driver registered multiple times. filter, include, exclude P6Spy lets you monitor specific tables or specific statement types. By setting filter=true P6Spy will perform string matching on each statement to determine if it should be written to the log file. include accepts a comma separated list of expressions which are required to be appear in a statement before it can appear in the log, exclude accepts a comma separated list to exclude. By default string matching is performed using a basic substring match. However Regex matching can also be used (see Custom Filtering below). Note that exclusion overrides inclusion, so that a statement matching both an include string and an exclude string will be excluded. example (capture all select statements except the orders table): filter =
true example (only captures statements against order,order_details,price, and price_history): filter =
true example (captures all statements except statements against the order table): filter =
false filter, sqlexpression If you plan on using a regex engine, a simple alternative to exclude and include is to use sqlexpression. It works like this: filter =
true If your expression matches the SQL string, it is logged, if not, it is not. Note, if you use sqlexpression, any values set in include and exclude are ignored. stringmatcher (Custom Filtering) If you want to apply more intelligence to what is logged or not logged by P6Spy you can specify a custom matching engine. P6Spy comes with support for several regex engines, though it is trivial to introduce another engine by implementing the StringMatcher interface. If a stringmatcher engine is specified, P6Spy will pass each statement to the class specified to determine if that statement should be logged. Using
GNU RegEx # Use GNU
Regex Matching for Filtering # Use Apache
Jakarta Regex Matching for Filtering autoflush For standard development this value should be set to true. When set to true every time a statement is intercepted it is immediately written to the log file. In some cases, however, instant feedback on every statement is not a requirement, and the system will perform slightly faster with this value set to false Example: Specifies the name of the file to generate. Use "stdout" for standard output. Note, if you are in Windows and are specifying a pathname, make sure to use forward slashes (e.g. c:/mylog/spy.log) Example: logfile =
spy.log you can also use log4j for your logging 1.- Set the
logfile property to "log4j" If for some reason log4j cannot be initialized, the logging will go to a file called log4jaux.log append Setting append=true causes p6spy to continue to append to the logfile, if it exists. Setting append=false causes the logfile to be truncated each time p6spy is restarted (typically when your application or application server is restarted). excludecategories The log includes category information that describes the type of statement. This property excludes the listed categories. Valid options include:
Enter a comma separated list of categories to exclude from your log file. See filter,include,exclude for more details on how this process works. includecategories The log includes category information that describes the type of statement. This property is a comma separated list of categories to include. See excludecategories for a valid list of categories. dateformat Setting a value for dateformat changes the date format value printed in the log file. No value prints the current time in milliseconds, a useful feature for parsing the log. The date format engine is Java's SimpleDateFormat class. See the SimpleDateFormat class in the JavaDocs for information on setting this value. Example value: dateformat=MM-dd-yy HH:mm:ss:SS stacktrace If stack trace is set, prints out the stack trace for each sql statement logged. stacktraceclass Limits the
stack traces printed out to those that contain this value. E.g. specifying
stacktraceclass=com.mycompany.myclass would limit the printing of stack
traces to the specified class value. The stack trace is converted to a
String and string.indexOf(stacktraceclass) is performed. If reloadproperties is set to true, then the property file is reloaded every n seconds, where n is defined by the value set by reloadpropertiesinterval. For example, if reloadproperties=true and reloadpropertiesinterval=10 then the system checks the File.lastModified() property of the property file every 10 seconds, and if the file has been modified, then it will be reloaded. Warning! If you have append=true the log will be suddenly truncated if you change your properties. This is because using reloadproperties is intended to be the equivalent of restarting your application server, and in the case of an application server restart your file would be truncated. Limitations: reloadproperties will not reload any driver information (such as realdriver, realdriver2, and realdriver3) and will not change the modules that are in memory. useprefix When set to true requires you to prefix your URLs with p6spy:. The default is false, but may become true in a future release. This helps avoid a common pital when installing p6spy, that your real driver is registered elsewhere and because the URLs are the same, the system does not know which driver to use. Command Line Options Every parameter specified in the property file can be set and override at the command line using the Java -D flag. Example: java -Dp6logfile=my.log -Dp6trace=true In addition, you can set the default directory to look for spy.properties: java -Dp6.home=c:\orion\lib The log file format of spy.log is as follows: current time|execution time|category|statement SQL String|effective SQL string
P6Spy now includes a JSP application that can be used to view configuration information about P6Spy and to create a demarcation in the log file. The easiest way to use the JSP application is to copy p6spy.war into the deployment directory of your application server. (For example, in JBoss this might be C:\JBoss-2.4.4_Tomcat-4.0.1\jboss\deploy). Once the .war file is deployed, you can access the application by using the URL http://machine:port/p6spy For example, if you are running the application on your own machine, and using Tomcat as the servlet engine, you would go to: http://localhost:8080/p6spy
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |