You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2004/05/20 17:38:00 UTC
cvs commit: logging-log4j/src/java/org/apache/log4j/net JMSAppender.java
ceki 2004/05/20 08:38:00
Modified: src/java/org/apache/log4j/db DBReceiver.java
ConnectionSource.java DBAppender.java
DataSourceConnectionSource.java
JNDIConnectionSource.java
DriverManagerConnectionSource.java
src/java/org/apache/log4j/spi LocationInfo.java
tests/input/db append-with-drivermanager1.xml .cvsignore
db.properties
tests build.xml build.properties.sample
src/java/org/apache/log4j/db/dialect Util.java
postgresql.sql mysql.sql oracle.sql
tests/src/java/org/apache/log4j/db FullCycleDBTest.java
src/java/org/apache/log4j/net JMSAppender.java
Added: tests/input/db hsqldb.properties.sample deleteTables.sql
src/java/org/apache/log4j/db/dialect HSQLDBDialect.java
hsqldb.sql
Removed: tests/input/db dbAppender1.xml
Log:
- Added support for locationInfo in DBAppender/DBReceiver.
- Added related test cases
- Fixed the LocationInfo.equals method
- Attemted to add HSQLDB support and failed.
- Improved the tests/build.file
- Minor doco fixes in JMSAppedder
Revision Changes Path
1.6 +31 -4 logging-log4j/src/java/org/apache/log4j/db/DBReceiver.java
Index: DBReceiver.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBReceiver.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DBReceiver.java 20 May 2004 14:53:16 -0000 1.5
+++ DBReceiver.java 20 May 2004 15:37:59 -0000 1.6
@@ -29,6 +29,7 @@
import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.scheduler.Job;
import org.apache.log4j.scheduler.Scheduler;
+import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
@@ -137,9 +138,21 @@
LoggerRepository loggerRepository = getLoggerRepository();
Connection connection = connectionSource.getConnection();
StringBuffer sql = new StringBuffer();
- sql.append("SELECT sequence_number, timestamp, rendered_message, ");
- sql.append("logger_name, level_string, ndc, thread_name, ");
- sql.append("reference_flag, event_id from logging_event ");
+ sql.append("SELECT ");
+ sql.append("sequence_number, ");
+ sql.append("timestamp, ");
+ sql.append("rendered_message, ");
+ sql.append("logger_name, ");
+ sql.append("level_string, ");
+ sql.append("ndc, ");
+ sql.append("thread_name, ");
+ sql.append("reference_flag, ");
+ sql.append("caller_filename, ");
+ sql.append("caller_class, ");
+ sql.append("caller_method, ");
+ sql.append("caller_line, ");
+ sql.append("event_id ");
+ sql.append("FROM logging_event ");
// have subsequent SELECTs start from we left off last time
sql.append(" WHERE event_id > "+lastId);
sql.append(" ORDER BY event_id ASC");
@@ -164,9 +177,23 @@
event.setNDC(rs.getString(6));
event.setThreadName(rs.getString(7));
+
+
short mask = rs.getShort(8);
- id = rs.getLong(9);
+ String fileName = rs.getString(9);
+ String className = rs.getString(10);
+ String methodName = rs.getString(11);
+ String lineNumber = rs.getString(12).trim();
+
+ if(fileName.equals(LocationInfo.NA)) {
+ event.setLocationInformation(LocationInfo.NA_LOCATION_INFO);
+ } else {
+ event.setLocationInformation(new LocationInfo(fileName, className,
+ methodName, lineNumber));
+ }
+
+ id = rs.getLong(13);
lastId = id;
//event.setProperty("id", Long.toString(id));
1.4 +2 -2 logging-log4j/src/java/org/apache/log4j/db/ConnectionSource.java
Index: ConnectionSource.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/ConnectionSource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConnectionSource.java 18 May 2004 17:00:08 -0000 1.3
+++ ConnectionSource.java 20 May 2004 15:37:59 -0000 1.4
@@ -37,7 +37,7 @@
final int MYSQL_DIALECT = 2;
final int ORACLE_DIALECT = 3;
final int MSSQL_DIALECT = 4;
-
+ final int HSQLDB_DIALECT = 5;
/**
* Obtain a {@link java.sql.Connection} for use. The client is
* responsible for closing the {@link java.sql.Connection} when it is no
@@ -60,5 +60,5 @@
* Get the SQL dialect that should be used for this connection.
*
*/
- int getSQLDialect();
+ int getSQLDialectCode();
}
1.9 +50 -20 logging-log4j/src/java/org/apache/log4j/db/DBAppender.java
Index: DBAppender.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBAppender.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DBAppender.java 18 May 2004 16:50:42 -0000 1.8
+++ DBAppender.java 20 May 2004 15:37:59 -0000 1.9
@@ -17,11 +17,10 @@
package org.apache.log4j.db;
import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.db.dialect.MySQLDialect;
-import org.apache.log4j.db.dialect.OracleDialect;
-import org.apache.log4j.db.dialect.PostgreSQLDialect;
import org.apache.log4j.db.dialect.SQLDialect;
+import org.apache.log4j.db.dialect.Util;
import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import java.sql.Connection;
@@ -42,6 +41,7 @@
public class DBAppender extends AppenderSkeleton {
ConnectionSource connectionSource;
SQLDialect sqlDialect;
+ boolean locationInfo = false;
public void activateOptions() {
LogLog.debug("DBAppender.activateOptions called");
@@ -51,20 +51,9 @@
"DBAppender cannot function without a connection source");
}
- switch (connectionSource.getSQLDialect()) {
- case ConnectionSource.POSTGRES_DIALECT:
- sqlDialect = new PostgreSQLDialect();
-
- break;
- case ConnectionSource.MYSQL_DIALECT:
- sqlDialect = new MySQLDialect();
-
- break;
- case ConnectionSource.ORACLE_DIALECT:
- sqlDialect = new OracleDialect();
+ sqlDialect = Util.getDialectFromCode(connectionSource.getSQLDialectCode());
- break;
- default:
+ if (sqlDialect == null) {
throw new IllegalStateException(
"DBAppender cannot function without a determined SQL dialect");
}
@@ -101,10 +90,21 @@
// id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
StringBuffer sql = new StringBuffer();
sql.append("INSERT INTO logging_event (");
- sql.append("sequence_number, timestamp, rendered_message, ");
- sql.append(
- "logger_name, level_string, ndc, thread_name, reference_flag) ");
- sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?)");
+ sql.append("sequence_number, ");
+ sql.append("timestamp, ");
+ sql.append("rendered_message, ");
+ sql.append("logger_name, ");
+ sql.append("level_string, ");
+ sql.append("ndc, ");
+ sql.append("thread_name, ");
+ sql.append("reference_flag, ");
+ sql.append("caller_filename, ");
+ sql.append("caller_class, ");
+ sql.append("caller_method, ");
+ sql.append("caller_line) ");
+
+ sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?)");
+
PreparedStatement insertStatement =
connection.prepareStatement(sql.toString());
@@ -117,6 +117,19 @@
insertStatement.setString(7, event.getThreadName());
insertStatement.setShort(8, DBHelper.computeReferenceMask(event));
+ LocationInfo li;
+
+ if (event.locationInformationExists() || locationInfo) {
+ li = event.getLocationInformation();
+ } else {
+ li = LocationInfo.NA_LOCATION_INFO;
+ }
+
+ insertStatement.setString(9, li.getFileName());
+ insertStatement.setString(10, li.getClassName());
+ insertStatement.setString(11, li.getMethodName());
+ insertStatement.setString(12, li.getLineNumber());
+
int updateCount = insertStatement.executeUpdate();
if (updateCount != 1) {
@@ -197,5 +210,22 @@
*/
public boolean requiresLayout() {
return false;
+ }
+
+ /**
+ * Returns value of the <b>LocationInfo</b> property which determines whether
+ * caller's location info is written to the database.
+ * */
+ public boolean getLocationInfo() {
+ return locationInfo;
+ }
+
+ /**
+ * If true, the information written to the database will include
+ * caller's location information. Due to performance concerns, by default no
+ * location information is written to the database.
+ * */
+ public void setLocationInfo(boolean locationInfo) {
+ this.locationInfo = locationInfo;
}
}
1.4 +1 -1 logging-log4j/src/java/org/apache/log4j/db/DataSourceConnectionSource.java
Index: DataSourceConnectionSource.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DataSourceConnectionSource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DataSourceConnectionSource.java 19 May 2004 17:58:09 -0000 1.3
+++ DataSourceConnectionSource.java 20 May 2004 15:37:59 -0000 1.4
@@ -84,7 +84,7 @@
this.dataSource = dataSource;
}
- public int getSQLDialect() {
+ public int getSQLDialectCode() {
return dialectCode;
}
}
1.5 +1 -10 logging-log4j/src/java/org/apache/log4j/db/JNDIConnectionSource.java
Index: JNDIConnectionSource.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/JNDIConnectionSource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JNDIConnectionSource.java 20 May 2004 11:49:07 -0000 1.4
+++ JNDIConnectionSource.java 20 May 2004 15:37:59 -0000 1.5
@@ -17,7 +17,6 @@
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -146,22 +145,14 @@
}
- public int getSQLDialect() {
+ public int getSQLDialectCode() {
return dialectCode;
}
private DataSource lookupDataSource()
throws NamingException, SQLException {
DataSource ds;
-
- Hashtable env = new Hashtable(11);
-// env.put(Context.INITIAL_CONTEXT_FACTORY,
-// "com.sun.jndi.fscontext.RefFSContextFactory");
-// env.put(Context.PROVIDER_URL,
-// "file:///home/jndi");
Context ctx = new InitialContext();
-
- //Context ctx = new InitialContext();
Object obj = ctx.lookup(jndiLocation);
ds = (DataSource)PortableRemoteObject.narrow(obj, DataSource.class);
1.4 +4 -1 logging-log4j/src/java/org/apache/log4j/db/DriverManagerConnectionSource.java
Index: DriverManagerConnectionSource.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DriverManagerConnectionSource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DriverManagerConnectionSource.java 19 May 2004 17:58:09 -0000 1.3
+++ DriverManagerConnectionSource.java 20 May 2004 15:37:59 -0000 1.4
@@ -71,6 +71,7 @@
static private final String MYSQL_PART = "mysql";
static private final String ORACLE_PART = "oracle";
static private final String MSSQL_PART = "mssql";
+ static private final String HSQLDB_PART = "hsqldb";
private String driverClass = null;
protected String url = null;
@@ -141,7 +142,7 @@
}
- public int getSQLDialect() {
+ public int getSQLDialectCode() {
int dialectCode = 0;
if (url == null) {
@@ -156,6 +157,8 @@
return ConnectionSource.ORACLE_DIALECT;
} else if (url.indexOf(MSSQL_PART) != -1) {
return ConnectionSource.MSSQL_DIALECT;
+ } else if (url.indexOf(HSQLDB_PART) != -1) {
+ return ConnectionSource.HSQLDB_DIALECT;
} else {
return ConnectionSource.UNKNOWN_DIALECT;
}
1.21 +19 -23 logging-log4j/src/java/org/apache/log4j/spi/LocationInfo.java
Index: LocationInfo.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LocationInfo.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- LocationInfo.java 12 May 2004 19:39:14 -0000 1.20
+++ LocationInfo.java 20 May 2004 15:37:59 -0000 1.21
@@ -21,6 +21,8 @@
import org.apache.log4j.Layout;
import org.apache.log4j.helpers.LogLog;
+import sun.security.action.GetLongAction;
+
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -180,48 +182,38 @@
}
public boolean equals(Object o) {
+ LogLog.info("equals called");
if (this == o) {
return true;
}
if (!(o instanceof LocationInfo)) {
+ LogLog.info("inequality point 1");
return false;
}
LocationInfo r = (LocationInfo) o;
- if(lineNumber == null) {
- if(r.lineNumber != null) {
- return false;
- }
- } else if(!lineNumber.equals(r.lineNumber)){
+ if(!getClassName().equals(r.getClassName())){
+ LogLog.info("inequality point 2");
return false;
}
-
- if(fileName == null) {
- if(r.fileName != null) {
- return false;
- }
- } else if(!fileName.equals(r.fileName)){
+
+ if(!getFileName().equals(r.getFileName())) {
+ LogLog.info("inequality point 3");
return false;
}
- if(className == null) {
- if(r.className != null) {
- return false;
- }
- } else if(!className.equals(r.className)){
+ if(!getMethodName().equals(r.getMethodName())){
+ LogLog.info("inequality point 4");
return false;
}
-
- if(methodName == null) {
- if(r.methodName != null) {
- return false;
- }
- } else if(!methodName.equals(r.methodName)){
+
+ if(!getLineNumber().equals(r.getLineNumber())){
+ LogLog.info("inequality point 5");
return false;
}
-
+
return true;
}
@@ -341,5 +333,9 @@
}
return methodName;
+ }
+
+ public String toString() {
+ return "(class="+getClassName()+", file="+getFileName()+", line="+getLineNumber()+", methodName="+getMethodName();
}
}
1.2 +1 -0 logging-log4j/tests/input/db/append-with-drivermanager1.xml
Index: append-with-drivermanager1.xml
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/db/append-with-drivermanager1.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- append-with-drivermanager1.xml 19 May 2004 17:58:09 -0000 1.1
+++ append-with-drivermanager1.xml 20 May 2004 15:37:59 -0000 1.2
@@ -6,6 +6,7 @@
<substitutionProperty file="input/db/db.properties"/>
<appender name="DB" class="org.apache.log4j.db.DBAppender">
+ <param name="locationInfo" value="true"/>
<connectionSource class="org.apache.log4j.db.DriverManagerConnectionSource">
<param name="driverClass" value="${driverClass}"/>
<param name="url" value="${url}"/>
1.2 +1 -0 logging-log4j/tests/input/db/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/db/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- .cvsignore 18 May 2004 16:50:43 -0000 1.1
+++ .cvsignore 20 May 2004 15:37:59 -0000 1.2
@@ -1,2 +1,3 @@
mysql.properties
postgresql.properties
+hsqldb.properties
1.4 +11 -18 logging-log4j/tests/input/db/db.properties
Index: db.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/db/db.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- db.properties 18 May 2004 16:50:43 -0000 1.3
+++ db.properties 20 May 2004 15:37:59 -0000 1.4
@@ -1,25 +1,18 @@
-# If you would like to test DBAppender/DBReceiver with PostgreSQL, then
+# If you would like to test DBAppender/DBReceiver for MySQL, then
# set the url and user parameters for your local environment and
-# copy this file to "postgresql.properties".
+# copy this file to "mysql.properties".
-# The JDBC driver class for PostgreSQL
-driverClass=org.postgresql.Driver
+# The JDBC driver class for MySQL
+driverClass=com.mysql.jdbc.Driver
-# The DataSource class for PostgreSQL
-dataSourceClass=org.postgresql.jdbc2.optional.SimpleDataSource
+# The DataSource class for MySQL
+dataSourceClass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
+# Native pooled DataSource class for MySQL
+pooledDataSourceClass=com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
-# =======================================================
# The following parameters should be set for your machine.
-# =======================================================
-
-# you need to set both the url and serverName and databaseName
-# this is redundant but allows the same properties file to be used
-# in different config files
-url=jdbc:postgresql://gil/test
-serverName=gil
-databaseName=test
-
-user=pg
-password=pg
\ No newline at end of file
+url=jdbc:mysql:///test
+user=root
+password=
\ No newline at end of file
1.1 logging-log4j/tests/input/db/hsqldb.properties.sample
Index: hsqldb.properties.sample
===================================================================
# If you would like to test DBAppender/DBReceiver for HSQLDB, then set
# the url and user parameters for your local environment and copy this
# file to "hsqldb.properties".
# The JDBC driver class for HSQLDB
driverClass=org.hsqldb.jdbcDriver
# The following parameters should be set for your machine.
url=jdbc:hsqldb:hsql://localhost
user=sa
password=
1.1 logging-log4j/tests/input/db/deleteTables.sql
Index: deleteTables.sql
===================================================================
delete from logging_event_exception;
delete from logging_event_property;
delete from logging_event;
1.57 +78 -42 logging-log4j/tests/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/logging-log4j/tests/build.xml,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- build.xml 20 May 2004 11:49:07 -0000 1.56
+++ build.xml 20 May 2004 15:38:00 -0000 1.57
@@ -507,7 +507,7 @@
<!-- The target that performs the actual test -->
- <target name="DB">
+ <target name="invokeDBTestCase">
<junit printsummary="yes" fork="no" haltonfailure="yes">
<sysproperty key="toto" value="${toto}"/>
<sysproperty key="appendConfigFile" value="${appendConfigFile}"/>
@@ -517,48 +517,101 @@
<test name="org.apache.log4j.db.FullCycleDBTest" />
</junit>
</target>
-
- <!-- ============ MySQL specific tests ============== -->
- <target name="mysqlCheck">
- <condition property="mysql-present">
- <and>
- <available file="./input/db/mysql.properties" />
- <available classname="com.mysql.jdbc.Driver">
- <classpath refid="tests.classpath"/>
- </available>
- </and>
+
+
+ <!-- the following target is shared by MySQL and PostgreSQL targets -->
+ <target name="commonDB">
+ <property file="./input/db/db.properties"/>
+
+ <!-- This task deletes existing entries in the database -->
+ <!-- Do not use on a table with valuable dataset -->
+ <input
+ message="All data is going to be deleted from DB. Continue (y/n)?"
+ validargs="y,n"
+ addproperty="do.delete"
+ />
+ <condition property="do.abort">
+ <equals arg1="n" arg2="${do.delete}"/>
</condition>
- </target>
+ <fail if="do.abort">Build aborted by user.</fail>
+ <sql driver="${driverClass}"
+ url="${url}"
+ userid="${user}"
+ password="${password}"
+ src="./input/db/deleteTables.sql">
+ <classpath refid="tests.classpath"/>
+ </sql>
- <target name="mysql" depends="mysqlCheck, build" if="mysql-present">
- <delete file="./input/db/db.properties"/>
- <echo message="MySQL available"/>
- <copy file="./input/db/mysql.properties" tofile="./input/db/db.properties"/>
-<!-- <echo message="Running test case with DriverManager config file"/>
- <antcall target="DB">
+ <echo message="Running test case with DriverManager config file"/>
+ <antcall target="invokeDBTestCase">
<param name="appendConfigFile" value="./input/db/append-with-drivermanager1.xml"/>
<param name="readConfigFile" value="./input/db/read-with-drivermanager1.xml"/>
</antcall>
<echo message="Running test case with DataSource"/>
- <antcall target="DB">
+ <antcall target="invokeDBTestCase">
<param name="appendConfigFile" value="./input/db/append-with-datasource1.xml"/>
<param name="readConfigFile" value="./input/db/read-with-datasource1.xml"/>
</antcall>
<echo message="Running test case with a native *pooled* DataSource"/>
- <antcall target="DB">
+ <antcall target="invokeDBTestCase">
<param name="appendConfigFile" value="./input/db/append-with-pooled-datasource1.xml"/>
<param name="readConfigFile" value="./input/db/read-with-pooled-datasource1.xml"/>
</antcall>
--->
+
<echo message="Running test case with a DataSource with JNDI"/>
- <antcall target="DB">
+ <antcall target="invokeDBTestCase">
<param name="appendConfigFile" value="./input/db/append-with-jndi1.xml"/>
<param name="readConfigFile" value="./input/db/read-with-jndi1.xml"/>
+ </antcall>
+ </target>
+
+ <!-- ============ hsqldb specific tests ============== -->
+
+
+ <target name="hsqldbCheck">
+ <condition property="hsqldb-present">
+ <and>
+ <available file="./input/db/hsqldb.properties" />
+ <available classname="org.hsqldb.jdbcDriver">
+ <classpath refid="tests.classpath"/>
+ </available>
+ </and>
+ </condition>
+ </target>
+
+ <target name="hsqldb" depends="hsqldbCheck, build" if="hsqldb-present">
+ <delete file="./input/db/db.properties"/>
+ <echo message="hsqldb available"/>
+ <copy file="./input/db/hsqldb.properties" tofile="./input/db/db.properties"/>
+
+ <echo message="Running test case with DriverManager config file"/>
+ <antcall target="invokeDBTestCase">
+ <param name="appendConfigFile" value="./input/db/append-with-drivermanager1.xml"/>
+ <param name="readConfigFile" value="./input/db/read-with-drivermanager1.xml"/>
</antcall>
-
+ </target>
+
+ <!-- ============ MySQL specific tests ============== -->
+ <target name="mysqlCheck">
+ <condition property="mysql-present">
+ <and>
+ <available file="./input/db/mysql.properties" />
+ <available classname="com.mysql.jdbc.Driver">
+ <classpath refid="tests.classpath"/>
+ </available>
+ </and>
+ </condition>
+ </target>
+
+ <target name="mysql" depends="mysqlCheck, build" if="mysql-present">
+ <delete file="./input/db/db.properties"/>
+ <echo message="MySQL available"/>
+ <copy file="./input/db/mysql.properties" tofile="./input/db/db.properties"/>
+
+ <antcall target="commonDB"/>
</target>
<!-- ============ PostgreSQL specific tests ============== -->
@@ -578,25 +631,8 @@
<delete file="./input/db/db.properties"/>
<echo message="PostgreSQL available"/>
<copy file="./input/db/postgresql.properties" tofile="./input/db/db.properties"/>
-
- <echo message="Running test case with DriverManager config file"/>
- <antcall target="DB">
- <param name="appendConfigFile" value="./input/db/append-with-drivermanager1.xml"/>
- <param name="readConfigFile" value="./input/db/read-with-drivermanager1.xml"/>
- </antcall>
-
- <echo message="Running test case with DataSource"/>
- <antcall target="DB">
- <param name="appendConfigFile" value="./input/db/append-with-datasource1.xml"/>
- <param name="readConfigFile" value="./input/db/read-with-datasource1.xml"/>
- </antcall>
-
- <echo message="Running test case with *pooled* DataSource"/>
- <antcall target="DB">
- <param name="appendConfigFile" value="./input/db/append-with-pooled-datasource1.xml"/>
- <param name="readConfigFile" value="./input/db/read-with-pooled-datasource1.xml"/>
- </antcall>
- </target>
+ <antcall target="commonDB"/>
+ </target>
<!-- ================================================================= -->
<!-- ========================= long Tests ========================= -->
1.5 +5 -3 logging-log4j/tests/build.properties.sample
Index: build.properties.sample
===================================================================
RCS file: /home/cvs/logging-log4j/tests/build.properties.sample,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- build.properties.sample 20 May 2004 11:49:07 -0000 1.4
+++ build.properties.sample 20 May 2004 15:38:00 -0000 1.5
@@ -2,8 +2,9 @@
jakarta.oro.jar=../../jakarta-oro-2.0.5/jakarta-oro-2.0.5.jar
-
-# junit must be on the classpath or in ANT_HOME/lib. It can't be
+# Junit test cases
+# ================
+# junit.jar must be on the classpath or in ANT_HOME/lib. It can't be
# handled as a property.
@@ -21,4 +22,5 @@
# Click on "Download JNDI 1.2.1 & More"
#
# Once you obtained the JNDI File System Service Provider place
-# the file fscontext.jar in the ./tests/lib/ directory.
\ No newline at end of file
+# the files fscontext.jar and providerutil.jar in the ./tests/lib/
+# directory.
\ No newline at end of file
1.2 +37 -10 logging-log4j/src/java/org/apache/log4j/db/dialect/Util.java
Index: Util.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/Util.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Util.java 19 May 2004 17:58:09 -0000 1.1
+++ Util.java 20 May 2004 15:38:00 -0000 1.2
@@ -16,16 +16,16 @@
package org.apache.log4j.db.dialect;
+import org.apache.log4j.db.ConnectionSource;
+import org.apache.log4j.helpers.LogLog;
+
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
-import org.apache.log4j.db.ConnectionSource;
-import org.apache.log4j.helpers.LogLog;
-
/**
- *
+ *
* @author Ceki Gulcu
*
*/
@@ -33,20 +33,19 @@
private static final String POSTGRES_PART = "postgresql";
private static final String MYSQL_PART = "mysql";
private static final String ORACLE_PART = "oracle";
- private static final String MSSQL_PART = "mssqlserver4";
-
-
- static public int discoverSQLDialect(Connection connection ) {
+ private static final String MSSQL_PART = "mssqlserver4";
+
+ public static int discoverSQLDialect(Connection connection) {
int dialectCode = 0;
try {
-
DatabaseMetaData meta = connection.getMetaData();
String dbName = meta.getDatabaseProductName().toLowerCase();
LogLog.debug("**db name is " + dbName);
if (dbName.indexOf(POSTGRES_PART) != -1) {
- LogLog.debug("POSTGRESQL dialect selected");
+ LogLog.debug("POSTGRESQL dialect selected");
+
return ConnectionSource.POSTGRES_DIALECT;
} else if (dbName.indexOf(MYSQL_PART) != -1) {
return ConnectionSource.MYSQL_DIALECT;
@@ -62,5 +61,33 @@
}
return dialectCode;
+ }
+
+ public static SQLDialect getDialectFromCode(int dialectCode) {
+ SQLDialect sqlDialect = null;
+
+ switch (dialectCode) {
+ case ConnectionSource.POSTGRES_DIALECT:
+ sqlDialect = new PostgreSQLDialect();
+
+ break;
+ case ConnectionSource.MYSQL_DIALECT:
+ sqlDialect = new MySQLDialect();
+
+ break;
+ case ConnectionSource.ORACLE_DIALECT:
+ sqlDialect = new OracleDialect();
+
+ break;
+ case ConnectionSource.MSSQL_DIALECT:
+ sqlDialect = new MsSQLDialect();
+
+ break;
+ case ConnectionSource.HSQLDB_DIALECT:
+ sqlDialect = new HSQLDBDialect();
+
+ break;
+ }
+ return sqlDialect;
}
}
1.9 +4 -0 logging-log4j/src/java/org/apache/log4j/db/dialect/postgresql.sql
Index: postgresql.sql
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/postgresql.sql,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- postgresql.sql 18 May 2004 16:50:43 -0000 1.8
+++ postgresql.sql 20 May 2004 15:38:00 -0000 1.9
@@ -22,6 +22,10 @@
ndc TEXT,
thread_name VARCHAR(254),
reference_flag SMALLINT,
+ caller_filename VARCHAR(254) NOT NULL,
+ caller_class VARCHAR(254) NOT NULL,
+ caller_method VARCHAR(254) NOT NULL,
+ caller_line CHAR(4) NOT NULL,
event_id INT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY
);
1.9 +5 -1 logging-log4j/src/java/org/apache/log4j/db/dialect/mysql.sql
Index: mysql.sql
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/mysql.sql,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- mysql.sql 15 May 2004 18:23:35 -0000 1.8
+++ mysql.sql 20 May 2004 15:38:00 -0000 1.9
@@ -6,9 +6,9 @@
BEGIN;
-DROP TABLE IF EXISTS logging_event;
DROP TABLE IF EXISTS logging_event_property;
DROP TABLE IF EXISTS logging_event_exception;
+DROP TABLE IF EXISTS logging_event;
COMMIT;
@@ -23,6 +23,10 @@
ndc TEXT,
thread_name VARCHAR(254),
reference_flag SMALLINT,
+ caller_filename VARCHAR(254) NOT NULL,
+ caller_class VARCHAR(254) NOT NULL,
+ caller_method VARCHAR(254) NOT NULL,
+ caller_line CHAR(4) NOT NULL,
event_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
);
COMMIT;
1.9 +4 -0 logging-log4j/src/java/org/apache/log4j/db/dialect/oracle.sql
Index: oracle.sql
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/oracle.sql,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- oracle.sql 15 May 2004 18:23:35 -0000 1.8
+++ oracle.sql 20 May 2004 15:38:00 -0000 1.9
@@ -25,6 +25,10 @@
ndc VARCHAR2(4000),
thread_name VARCHAR2(254),
reference_flag SMALLINT,
+ caller_filename VARCHAR2(254) NOT NULL,
+ caller_class VARCHAR2(254) NOT NULL,
+ caller_method VARCHAR2(254) NOT NULL,
+ caller_line CHAR(4) NOT NULL,
event_id NUMBER(10) PRIMARY KEY
);
1.1 logging-log4j/src/java/org/apache/log4j/db/dialect/HSQLDBDialect.java
Index: HSQLDBDialect.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j.db.dialect;
/**
* <b>DBAppender DOES NOT WORK WITH HSQLDB.</b>
*
* The HSQLDB dialect.
*
* <b>WARNING</b>
* IT IS ESTABLISHED THAT DBAppender DOES NOT WORK WITH HSQLDB.
*
* @author Ceki Gulcu
*/
public class HSQLDBDialect implements SQLDialect {
public static final String SELECT_CURRVAL = "CALL IDENTITY()";
public String getSelectInsertId() {
return SELECT_CURRVAL;
}
}
1.1 logging-log4j/src/java/org/apache/log4j/db/dialect/hsqldb.sql
Index: hsqldb.sql
===================================================================
# This SQL script creates the required tables by
# org.apache.log4j.db.DBAppender and org.apache.log4j.db.DBReceiver.
#
#
# It is intended for HSQLDB.
#
#
# ====================================================================
# WARNING: IT IS ESTABLISHED THAT DBAppender DOES NOT WORK WITH HSQLDB.
# ====================================================================
DROP TABLE logging_event_exception;
DROP TABLE logging_event_property;
DROP TABLE logging_event;
CREATE TABLE logging_event
(
sequence_number BIGINT NOT NULL,
timestamp BIGINT NOT NULL,
rendered_message LONGVARCHAR NOT NULL,
logger_name VARCHAR NOT NULL,
level_string VARCHAR NOT NULL,
ndc LONGVARCHAR,
thread_name VARCHAR,
reference_flag SMALLINT,
event_id INT NOT NULL IDENTITY
);
CREATE TABLE logging_event_property
(
event_id INT NOT NULL,
mapped_key VARCHAR(254) NOT NULL,
mapped_value LONGVARCHAR,
PRIMARY KEY(event_id, mapped_key),
FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
);
CREATE TABLE logging_event_exception
(
event_id INT NOT NULL,
i SMALLINT NOT NULL,
trace_line VARCHAR NOT NULL,
PRIMARY KEY(event_id, i),
FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
);
1.6 +23 -51 logging-log4j/tests/src/java/org/apache/log4j/db/FullCycleDBTest.java
Index: FullCycleDBTest.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/db/FullCycleDBTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FullCycleDBTest.java 19 May 2004 17:58:09 -0000 1.5
+++ FullCycleDBTest.java 20 May 2004 15:38:00 -0000 1.6
@@ -31,14 +31,23 @@
import org.apache.log4j.helpers.IntializationUtil;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.joran.JoranConfigurator;
+import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.RootLogger;
/**
- * @author Ceki Gülcü
- *
+ * This test case writes a few events into a databases and reads them
+ * back comparing the event written and read back.
+ *
+ * <p>It relies heavily on the proper configuration of its environment
+ * in joran config files as well system properties.
+ * </p>
+ *
+ * <p>See also the Ant build file in the tests/ directory.</p>
+ *
+ * @author Ceki Gülcü
*/
public class FullCycleDBTest
extends TestCase {
@@ -116,32 +125,6 @@
readBack(readConfigFile, startTime);
}
-//
-// public void testDataSource()
-// throws Exception {
-//
-// LogLog.setInternalDebugging(true);
-// JoranConfigurator jc1 = new JoranConfigurator();
-// jc1.doConfigure("input/db/append-with-datasource1.xml", lrWrite);
-//
-//
-// long startTime = System.currentTimeMillis();
-// LogLog.info("startTime is "+startTime);
-//
-// // Write out just one log message
-// Logger out = lrWrite.getLogger("testSingleOutput.out");
-// out.debug("some message"+startTime);
-//
-// VectorAppender witnessAppender = (VectorAppender) lrWrite.getRootLogger().getAppender("VECTOR");
-// witnessEvents = witnessAppender.getVector();
-// assertEquals(1, witnessEvents.size());
-//
-// LogLog.info("----------------------------------------------");
-// // now read it back
-// readBack("input/db/read-with-datasource1.xml", startTime);
-// }
-
-
/**
* This test starts by writing a single event to a DB using DBAppender
@@ -187,7 +170,6 @@
void readBack(String configfile, long startTime) {
- // now read it back
JoranConfigurator jc2 = new JoranConfigurator();
jc2.doConfigure(configfile, lrRead);
@@ -224,6 +206,7 @@
assertEquals(le.getProperties(), re.getProperties());
}
comprareStringArrays( le.getThrowableStrRep(), re.getThrowableStrRep());
+ compareLocationInfo(le, re);
}
}
@@ -237,7 +220,14 @@
}
}
-
+ void compareLocationInfo(LoggingEvent l, LoggingEvent r) {
+ if(l.locationInformationExists()) {
+ assertEquals(l.getLocationInformation(), r.getLocationInformation());
+ } else {
+ assertEquals(LocationInfo.NA_LOCATION_INFO, r.getLocationInformation());
+ }
+ }
+
Vector getRelevantEventsFromVA(VectorAppender va, long startTime) {
assertNotNull(va);
Vector v = va.getVector();
@@ -254,29 +244,11 @@
}
return r;
}
-
-
-// public void xtestJNDI()
-// throws Exception {
-// Hashtable env = new Hashtable();
-//
-// env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
-// env.put(Context.PROVIDER_URL, "file:///home/jndi");
-//
-// Context ctx = new InitialContext(env);
-//
-// //ctx.addToEnvironment("toto", new Integer(1));
-// ctx.bind("toto", new Integer(1));
-// }
-
- public static Test suite() {
+
+ public static Test XXsuite() {
TestSuite suite = new TestSuite();
- //suite.addTest(new FullCycleDBTest("test1"));
suite.addTest(new FullCycleDBTest("testSingleOutput"));
- //suite.addTest(new FullCycleDBTest("testAllFields"));
- //suite.addTest(new FullCycleDBTest("testDataSource"));
-
-
+ suite.addTest(new FullCycleDBTest("testAllFields"));
return suite;
}
}
1.15 +8 -7 logging-log4j/src/java/org/apache/log4j/net/JMSAppender.java
Index: JMSAppender.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/net/JMSAppender.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- JMSAppender.java 9 Oct 2002 22:50:04 -0000 1.14
+++ JMSAppender.java 20 May 2004 15:38:00 -0000 1.15
@@ -147,9 +147,9 @@
/**
- Returns value of the <b>LocationInfo</b> property which
- determines whether location (stack) info is sent to the remote
- subscriber. */
+ * Returns value of the <b>LocationInfo</b> property which determines whether
+ * caller's location info is sent to the remote subscriber.
+ * */
public
boolean getLocationInfo() {
return locationInfo;
@@ -380,10 +380,11 @@
}
- /**
- If true, the information sent to the remote subscriber will
- include caller's location information. By default no location
- information is sent to the subscriber. */
+ /**
+ * If true, the information sent to the remote subscriber will include
+ * caller's location information. Due to performance concerns, by default no
+ * location information is sent to the subscriber.
+ * */
public void setLocationInfo(boolean locationInfo) {
this.locationInfo = locationInfo;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org