[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-115-g1fd3f4e
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Wed Mar 24 19:51:45 CET 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via 1fd3f4ed5e26bd3ddff55f043a0729afc67efdc3 (commit)
from cc1540f6a907d3f366cc1acbafc6056824b89875 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=1fd3f4ed5e26bd3ddff55f043a0729afc67efdc3
http://github.com/ceki/logback/commit/1fd3f4ed5e26bd3ddff55f043a0729afc67efdc3
commit 1fd3f4ed5e26bd3ddff55f043a0729afc67efdc3
Author: Ceki Gulcu <ceki at qos.ch>
Date: Wed Mar 24 19:50:33 2010 +0100
- fixed LBCLASSIC-187 by adding 4 new columns to the logging_event table
diff --git a/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java b/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
index b8e3a25..e8b1057 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/db/DBAppender.java
@@ -70,9 +70,8 @@ public class DBAppender extends DBAppenderBase<AccessEvent> {
}
@Override
- protected void subAppend(Object eventObject, Connection connection,
+ protected void subAppend(AccessEvent event, Connection connection,
PreparedStatement insertStatement) throws Throwable {
- AccessEvent event = (AccessEvent) eventObject;
addAccessEvent(insertStatement, event);
@@ -80,9 +79,11 @@ public class DBAppender extends DBAppenderBase<AccessEvent> {
if (updateCount != 1) {
addWarn("Failed to insert access event");
}
-
+ }
+
+ protected void secondarySubAppend(AccessEvent event, Connection connection,
+ long eventId) throws Throwable {
if (insertHeaders) {
- long eventId = selectEventId(insertStatement, connection);
addRequestHeaders(event, connection, eventId);
}
}
diff --git a/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java b/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java
index 88c5aa2..fa8f90e 100644
--- a/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java
+++ b/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java
@@ -138,7 +138,7 @@ public class DBAppenderTest {
AccessEvent event = createAccessEvent();
appender.append(event);
-
+
Statement stmt = connectionSource.getConnection().createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM access_event_header");
@@ -169,12 +169,15 @@ public class DBAppenderTest {
@Test
public void testAppendMultipleEvents() throws SQLException {
+ setInsertHeadersAndStart(false);
String uri = "testAppendMultipleEvents";
for (int i = 0; i < 10; i++) {
AccessEvent event = createAccessEvent(uri);
appender.append(event);
}
+ StatusPrinter.print(context);
+
Statement stmt = connectionSource.getConnection().createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM access_event where requestURI='"+uri+"'");
diff --git a/logback-classic/doc/designDiscussion/LoggingEvent Serialization.odt b/logback-classic/doc/designDiscussion/LoggingEvent Serialization.odt
deleted file mode 100644
index 993ee65..0000000
Binary files a/logback-classic/doc/designDiscussion/LoggingEvent Serialization.odt and /dev/null differ
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java b/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
index b0c298a..0bbc74e 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
@@ -50,6 +50,22 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
private DBNameResolver dbNameResolver;
+ static final int TIMESTMP_INDEX = 1;
+ static final int FORMATTED_MESSAGE_INDEX = 2;
+ static final int LOGGER_NAME_INDEX = 3;
+ static final int LEVEL_STRING_INDEX = 4;
+ static final int THREAD_NAME_INDEX = 5;
+ static final int REFERENCE_FLAG_INDEX = 6;
+ static final int ARG0_INDEX = 7;
+ static final int ARG1_INDEX = 8;
+ static final int ARG2_INDEX = 9;
+ static final int ARG3_INDEX = 10;
+ static final int CALLER_FILENAME_INDEX = 11;
+ static final int CALLER_CLASS_INDEX = 12;
+ static final int CALLER_METHOD_INDEX = 13;
+ static final int CALLER_LINE_INDEX = 14;
+ static final int EVENT_ID_INDEX = 15;
+
static {
// PreparedStatement.getGeneratedKeys() method was added in JDK 1.4
Method getGeneratedKeysMethod;
@@ -81,11 +97,12 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
}
@Override
- protected void subAppend(Object eventObject, Connection connection,
+ protected void subAppend(ILoggingEvent event, Connection connection,
PreparedStatement insertStatement) throws Throwable {
- ILoggingEvent event = (ILoggingEvent) eventObject;
bindLoggingEventWithInsertStatement(insertStatement, event);
+ bindLoggingEventArgumentsWithPreparedStatement(insertStatement, event.getArgumentArray());
+
// This is expensive... should we do it every time?
bindCallerDataWithPreparedStatement(insertStatement, event.getCallerData());
@@ -93,9 +110,10 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
if (updateCount != 1) {
addWarn("Failed to insert loggingEvent");
}
-
- long eventId = selectEventId(insertStatement, connection);
-
+ }
+
+ protected void secondarySubAppend(ILoggingEvent event, Connection connection,
+ long eventId) throws Throwable {
Map<String, String> mergedMap = mergePropertyMaps(event);
insertProperties(mergedMap, connection, eventId);
@@ -106,22 +124,48 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
void bindLoggingEventWithInsertStatement(PreparedStatement stmt,
ILoggingEvent event) throws SQLException {
- stmt.setLong(1, event.getTimeStamp());
- stmt.setString(2, event.getFormattedMessage());
- stmt.setString(3, event.getLoggerName());
- stmt.setString(4, event.getLevel().toString());
- stmt.setString(5, event.getThreadName());
- stmt.setShort(6, DBHelper.computeReferenceMask(event));
+ stmt.setLong(TIMESTMP_INDEX, event.getTimeStamp());
+ stmt.setString(FORMATTED_MESSAGE_INDEX, event.getFormattedMessage());
+ stmt.setString(LOGGER_NAME_INDEX, event.getLoggerName());
+ stmt.setString(LEVEL_STRING_INDEX, event.getLevel().toString());
+ stmt.setString(THREAD_NAME_INDEX, event.getThreadName());
+ stmt.setShort(REFERENCE_FLAG_INDEX, DBHelper.computeReferenceMask(event));
}
+ void bindLoggingEventArgumentsWithPreparedStatement(PreparedStatement stmt,
+ Object[] argArray) throws SQLException {
+
+ int arrayLen = argArray != null ? argArray.length : 0;
+
+ for(int i = 0; i < arrayLen && i < 4; i++) {
+ stmt.setString(ARG0_INDEX+i, truncateTo254(argArray[i].toString()));
+ }
+ if(arrayLen < 4) {
+ for(int i = arrayLen; i < 4; i++) {
+ stmt.setString(ARG0_INDEX+i, null);
+ }
+ }
+ }
+
+ String truncateTo254(String s) {
+ if(s == null) {
+ return null;
+ }
+ if(s.length() <= 254) {
+ return s;
+ } else {
+ return s.substring(0, 254);
+ }
+ }
+
void bindCallerDataWithPreparedStatement(PreparedStatement stmt,
StackTraceElement[] callerDataArray) throws SQLException {
StackTraceElement callerData = callerDataArray[0];
if (callerData != null) {
- stmt.setString(7, callerData.getFileName());
- stmt.setString(8, callerData.getClassName());
- stmt.setString(9, callerData.getMethodName());
- stmt.setString(10, Integer.toString(callerData.getLineNumber()));
+ stmt.setString(CALLER_FILENAME_INDEX, callerData.getFileName());
+ stmt.setString(CALLER_CLASS_INDEX, callerData.getClassName());
+ stmt.setString(CALLER_METHOD_INDEX, callerData.getMethodName());
+ stmt.setString(CALLER_LINE_INDEX, Integer.toString(callerData.getLineNumber()));
}
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/SQLBuilder.java b/logback-classic/src/main/java/ch/qos/logback/classic/db/SQLBuilder.java
index 1390237..8ebeece 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/SQLBuilder.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/SQLBuilder.java
@@ -50,11 +50,15 @@ public class SQLBuilder {
sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.LEVEL_STRING)).append(", ");
sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.THREAD_NAME)).append(", ");
sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.REFERENCE_FLAG)).append(", ");
+ sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG0)).append(", ");
+ sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG1)).append(", ");
+ sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG2)).append(", ");
+ sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.ARG3)).append(", ");
sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_FILENAME)).append(", ");
sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_CLASS)).append(", ");
sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_METHOD)).append(", ");
sqlBuilder.append(dbNameResolver.getColumnName(ColumnName.CALLER_LINE)).append(") ");
- sqlBuilder.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?)");
+ sqlBuilder.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
return sqlBuilder.toString();
}
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/db2.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/db2.sql
index 16db5a0..94964fe 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/db2.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/db2.sql
@@ -20,6 +20,10 @@ CREATE TABLE logging_event
level_string VARCHAR(254) NOT NULL,
thread_name VARCHAR(254),
reference_flag SMALLINT,
+ arg0 VARCHAR(254),
+ arg1 VARCHAR(254),
+ arg2 VARCHAR(254),
+ arg3 VARCHAR(254),
caller_filename VARCHAR(254) NOT NULL,
caller_class VARCHAR(254) NOT NULL,
caller_method VARCHAR(254) NOT NULL,
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/deleteTables.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/deleteTables.sql
deleted file mode 100644
index bd7c256..0000000
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/deleteTables.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-
-delete from access_event_property;
-delete from access_event;
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql
index f053863..94306c8 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/h2.sql
@@ -14,6 +14,10 @@ CREATE TABLE logging_event (
level_string VARCHAR(256) NOT NULL,
thread_name VARCHAR(256),
reference_flag SMALLINT,
+ arg0 VARCHAR(256),
+ arg1 VARCHAR(256),
+ arg2 VARCHAR(256),
+ arg3 VARCHAR(256),
caller_filename VARCHAR(256),
caller_class VARCHAR(256),
caller_method VARCHAR(256),
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql
index 07cf847..671f675 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/hsqldb.sql
@@ -13,6 +13,10 @@ CREATE TABLE logging_event (
level_string VARCHAR(256) NOT NULL,
thread_name VARCHAR(256),
reference_flag SMALLINT,
+ arg0 VARCHAR(256),
+ arg1 VARCHAR(256),
+ arg2 VARCHAR(256),
+ arg3 VARCHAR(256),
caller_filename VARCHAR(256),
caller_class VARCHAR(256),
caller_method VARCHAR(256),
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mssql.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mssql.sql
index 734757c..cbe4ef6 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mssql.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mssql.sql
@@ -13,6 +13,10 @@ CREATE TABLE logging_event
level_string VARCHAR(254) NOT NULL,
thread_name VARCHAR(254),
reference_flag SMALLINT,
+ arg0 VARCHAR(254),
+ arg1 VARCHAR(254),
+ arg2 VARCHAR(254),
+ arg3 VARCHAR(254),
caller_filename VARCHAR(254) NOT NULL,
caller_class VARCHAR(254) NOT NULL,
caller_method VARCHAR(254) NOT NULL,
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mysql.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mysql.sql
index 5195dcf..e6ee387 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mysql.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/mysql.sql
@@ -20,6 +20,10 @@ CREATE TABLE logging_event
level_string VARCHAR(254) NOT NULL,
thread_name VARCHAR(254),
reference_flag SMALLINT,
+ arg0 VARCHAR(254),
+ arg1 VARCHAR(254),
+ arg2 VARCHAR(254),
+ arg3 VARCHAR(254),
caller_filename VARCHAR(254) NOT NULL,
caller_class VARCHAR(254) NOT NULL,
caller_method VARCHAR(254) NOT NULL,
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/oracle.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/oracle.sql
index 89e244e..3d239ad 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/oracle.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/oracle.sql
@@ -22,6 +22,10 @@ CREATE TABLE logging_event
level_string VARCHAR(254) NOT NULL,
thread_name VARCHAR(254),
reference_flag SMALLINT,
+ arg0 VARCHAR(254),
+ arg1 VARCHAR(254),
+ arg2 VARCHAR(254),
+ arg3 VARCHAR(254),
caller_filename VARCHAR(254) NOT NULL,
caller_class VARCHAR(254) NOT NULL,
caller_method VARCHAR(254) NOT NULL,
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/postgresql.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/postgresql.sql
index 25a3dd1..576f26c 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/postgresql.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/postgresql.sql
@@ -19,6 +19,10 @@ CREATE TABLE logging_event
level_string VARCHAR(254) NOT NULL,
thread_name VARCHAR(254),
reference_flag SMALLINT,
+ arg0 VARCHAR(254),
+ arg1 VARCHAR(254),
+ arg2 VARCHAR(254),
+ arg3 VARCHAR(254),
caller_filename VARCHAR(254) NOT NULL,
caller_class VARCHAR(254) NOT NULL,
caller_method VARCHAR(254) NOT NULL,
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/sybaseSqlAnywhere.sql b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/sybaseSqlAnywhere.sql
index 4daa77d..9ad7e70 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/sybaseSqlAnywhere.sql
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/sybaseSqlAnywhere.sql
@@ -7,18 +7,22 @@ DROP TABLE logging_event
CREATE TABLE logging_event
(
-timestmp bigint NOT NULL,
-formatted_message LONG VARCHAR NOT NULL,
-logger_name VARCHAR(254) NOT NULL,
-level_string VARCHAR(254) NOT NULL,
-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 varCHAR(4) NOT NULL,
-event_id int NOT NULL DEFAULT AUTOINCREMENT,
-PRIMARY KEY(event_id)
+ timestmp bigint NOT NULL,
+ formatted_message LONG VARCHAR NOT NULL,
+ logger_name VARCHAR(254) NOT NULL,
+ level_string VARCHAR(254) NOT NULL,
+ thread_name VARCHAR(254),
+ reference_flag SMALLINT,
+ arg0 VARCHAR(254),
+ arg1 VARCHAR(254),
+ arg2 VARCHAR(254),
+ arg3 VARCHAR(254),
+ caller_filename VARCHAR(254) NOT NULL,
+ caller_class VARCHAR(254) NOT NULL,
+ caller_method VARCHAR(254) NOT NULL,
+ caller_line varCHAR(4) NOT NULL,
+ event_id int NOT NULL DEFAULT AUTOINCREMENT,
+ PRIMARY KEY(event_id)
)
CREATE TABLE logging_event_property
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/names/ColumnName.java b/logback-classic/src/main/java/ch/qos/logback/classic/db/names/ColumnName.java
index 2717331..0ed90fb 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/names/ColumnName.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/names/ColumnName.java
@@ -10,6 +10,10 @@ public enum ColumnName {
LEVEL_STRING,
THREAD_NAME,
REFERENCE_FLAG,
+ ARG0,
+ ARG1,
+ ARG2,
+ ARG3,
CALLER_FILENAME,
CALLER_CLASS,
CALLER_METHOD,
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
index 286d570..f8daa42 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
@@ -92,16 +92,17 @@ public class DBAppenderH2Test {
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM logging_event");
if (rs.next()) {
- assertEquals(event.getTimeStamp(), rs.getLong(1));
- assertEquals(event.getFormattedMessage(), rs.getString(2));
- assertEquals(event.getLoggerName(), rs.getString(3));
- assertEquals(event.getLevel().toString(), rs.getString(4));
- assertEquals(event.getThreadName(), rs.getString(5));
- assertEquals(DBHelper.computeReferenceMask(event), rs.getShort(6));
+ assertEquals(event.getTimeStamp(), rs.getLong(DBAppender.TIMESTMP_INDEX));
+ assertEquals(event.getFormattedMessage(), rs.getString(DBAppender.FORMATTED_MESSAGE_INDEX));
+ assertEquals(event.getLoggerName(), rs.getString(DBAppender.LOGGER_NAME_INDEX));
+ assertEquals(event.getLevel().toString(), rs.getString(DBAppender.LEVEL_STRING_INDEX));
+ assertEquals(event.getThreadName(), rs.getString(DBAppender.THREAD_NAME_INDEX));
+ assertEquals(DBHelper.computeReferenceMask(event), rs.getShort(DBAppender.REFERENCE_FLAG_INDEX));
+ assertEquals(String.valueOf(diff), rs.getString(DBAppender.ARG0_INDEX));
StackTraceElement callerData = event.getCallerData()[0];
- assertEquals(callerData.getFileName(), rs.getString(7));
- assertEquals(callerData.getClassName(), rs.getString(8));
- assertEquals(callerData.getMethodName(), rs.getString(9));
+ assertEquals(callerData.getFileName(), rs.getString(DBAppender.CALLER_FILENAME_INDEX));
+ assertEquals(callerData.getClassName(), rs.getString(DBAppender.CALLER_CLASS_INDEX));
+ assertEquals(callerData.getMethodName(), rs.getString(DBAppender.CALLER_METHOD_INDEX));
} else {
fail("No row was inserted in the database");
}
@@ -182,7 +183,7 @@ public class DBAppenderH2Test {
private ILoggingEvent createLoggingEvent() {
ILoggingEvent le = new LoggingEvent(this.getClass().getName(), logger,
- Level.DEBUG, "test message", new Exception("test Ex"), null);
+ Level.DEBUG, "test message", new Exception("test Ex"), new Integer[] {diff});
return le;
}
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java
index 810e73a..8cbe70b 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2TestFixture.java
@@ -87,6 +87,10 @@ public class DBAppenderH2TestFixture {
buf.append("LEVEL_STRING VARCHAR(256) NOT NULL,");
buf.append("THREAD_NAME VARCHAR(256),");
buf.append("REFERENCE_FLAG SMALLINT,");
+ buf.append("ARG0 VARCHAR(256),");
+ buf.append("ARG1 VARCHAR(256),");
+ buf.append("ARG2 VARCHAR(256),");
+ buf.append("ARG3 VARCHAR(256),");
buf.append("CALLER_FILENAME VARCHAR(256), ");
buf.append("CALLER_CLASS VARCHAR(256), ");
buf.append("CALLER_METHOD VARCHAR(256), ");
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java
index 20cead3..9fd2b72 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTest.java
@@ -34,6 +34,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.db.DriverManagerConnectionSource;
import ch.qos.logback.core.testUtil.RandomUtil;
+import ch.qos.logback.core.util.StatusPrinter;
public class DBAppenderHSQLTest {
@@ -81,22 +82,23 @@ public class DBAppenderHSQLTest {
ILoggingEvent event = createLoggingEvent();
appender.append(event);
- //StatusPrinter.print(lc.getStatusManager());
+ StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
Statement stmt = connectionSource.getConnection().createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM logging_event");
if (rs.next()) {
- assertEquals(event.getTimeStamp(), rs.getLong(1));
- assertEquals(event.getFormattedMessage(), rs.getString(2));
- assertEquals(event.getLoggerName(), rs.getString(3));
- assertEquals(event.getLevel().toString(), rs.getString(4));
- assertEquals(event.getThreadName(), rs.getString(5));
- assertEquals(DBHelper.computeReferenceMask(event), rs.getShort(6));
+ assertEquals(event.getTimeStamp(), rs.getLong(DBAppender.TIMESTMP_INDEX));
+ assertEquals(event.getFormattedMessage(), rs.getString(DBAppender.FORMATTED_MESSAGE_INDEX));
+ assertEquals(event.getLoggerName(), rs.getString(DBAppender.LOGGER_NAME_INDEX));
+ assertEquals(event.getLevel().toString(), rs.getString(DBAppender.LEVEL_STRING_INDEX));
+ assertEquals(event.getThreadName(), rs.getString(DBAppender.THREAD_NAME_INDEX));
+ assertEquals(DBHelper.computeReferenceMask(event), rs.getShort(DBAppender.REFERENCE_FLAG_INDEX));
+ assertEquals(String.valueOf(diff), rs.getString(DBAppender.ARG0_INDEX));
StackTraceElement callerData = event.getCallerData()[0];
- assertEquals(callerData.getFileName(), rs.getString(7));
- assertEquals(callerData.getClassName(), rs.getString(8));
- assertEquals(callerData.getMethodName(), rs.getString(9));
+ assertEquals(callerData.getFileName(), rs.getString(DBAppender.CALLER_FILENAME_INDEX));
+ assertEquals(callerData.getClassName(), rs.getString(DBAppender.CALLER_CLASS_INDEX));
+ assertEquals(callerData.getMethodName(), rs.getString(DBAppender.CALLER_METHOD_INDEX));
} else {
fail("No row was inserted in the database");
}
@@ -180,7 +182,7 @@ public class DBAppenderHSQLTest {
private ILoggingEvent createLoggingEvent() {
ILoggingEvent le = new LoggingEvent(this.getClass().getName(), logger,
- Level.DEBUG, "test message", new Exception("test Ex"), null);
+ Level.DEBUG, "test message", new Exception("test Ex"), new Integer[] {diff});
return le;
}
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java
index 30f8a58..fdac186 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderHSQLTestFixture.java
@@ -115,6 +115,13 @@ public class DBAppenderHSQLTestFixture {
buf.append("LEVEL_STRING VARCHAR(256) NOT NULL,");
buf.append("THREAD_NAME VARCHAR(256),");
buf.append("REFERENCE_FLAG SMALLINT,");
+
+ buf.append("ARG0 VARCHAR(256),");
+ buf.append("ARG1 VARCHAR(256),");
+ buf.append("ARG2 VARCHAR(256),");
+ buf.append("ARG3 VARCHAR(256),");
+
+
buf.append("CALLER_FILENAME VARCHAR(256), ");
buf.append("CALLER_CLASS VARCHAR(256), ");
buf.append("CALLER_METHOD VARCHAR(256), ");
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
index 34c6001..93c5868 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
@@ -48,7 +48,7 @@ public class DBAppenderIntegrationTest {
static String LOCAL_HOST_NAME;
static String[] CONFORMING_HOST_LIST = new String[] { "Orion" };
static String[] POSTGRES_CONFORMING_HOST_LIST = new String[] { "haro" };
- static String[] MYSQL_CONFORMING_HOST_LIST = new String[] { "haro" };
+ static String[] MYSQL_CONFORMING_HOST_LIST = new String[] { "hetz", "haro" };
static String[] ORACLE_CONFORMING_HOST_LIST = new String[] { "haro" };
int diff = RandomUtil.getPositiveInt();
@@ -144,6 +144,7 @@ public class DBAppenderIntegrationTest {
assertEquals("This is a debug message. Message number: " + (diff + 5), msg);
}
+ @SuppressWarnings("unchecked")
void verifyProperty(long lastEventId) throws SQLException {
DriverManagerConnectionSource cs = getConnectionSource();
Connection con = cs.getConnection();
@@ -155,7 +156,7 @@ public class DBAppenderIntegrationTest {
Map<String, String> witness = lc.getCopyOfPropertyMap();
witness.putAll(MDC.getCopyOfContextMap());
- Map map = new HashMap();
+ Map<String, String> map = new HashMap<String, String>();
while (rs.next()) {
String key = rs.getString(1);
String val = rs.getString(2);
diff --git a/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java b/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
index 373ce6c..de7d6ad 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
@@ -21,7 +21,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.UnsynchronizedAppenderBase;
import ch.qos.logback.core.db.dialect.DBUtil;
import ch.qos.logback.core.db.dialect.SQLDialect;
import ch.qos.logback.core.db.dialect.SQLDialectCode;
@@ -31,7 +31,7 @@ import ch.qos.logback.core.db.dialect.SQLDialectCode;
* @author Ray DeCampo
* @author Sébastien Pennec
*/
-public abstract class DBAppenderBase<E> extends AppenderBase<E> {
+public abstract class DBAppenderBase<E> extends UnsynchronizedAppenderBase<E> {
protected ConnectionSource connectionSource;
protected boolean cnxSupportsGetGeneratedKeys = false;
@@ -76,13 +76,12 @@ public abstract class DBAppenderBase<E> extends AppenderBase<E> {
/**
* @param connectionSource
- * The connectionSource to set.
+ * The connectionSource to set.
*/
public void setConnectionSource(ConnectionSource connectionSource) {
this.connectionSource = connectionSource;
}
-
@Override
public void append(E eventObject) {
Connection connection = null;
@@ -90,23 +89,32 @@ public abstract class DBAppenderBase<E> extends AppenderBase<E> {
connection = connectionSource.getConnection();
connection.setAutoCommit(false);
PreparedStatement insertStatement;
+
if (cnxSupportsGetGeneratedKeys) {
String EVENT_ID_COL_NAME = "EVENT_ID";
- // see
- if(connectionSource.getSQLDialectCode() == SQLDialectCode.POSTGRES_DIALECT) {
+ // see
+ if (connectionSource.getSQLDialectCode() == SQLDialectCode.POSTGRES_DIALECT) {
EVENT_ID_COL_NAME = EVENT_ID_COL_NAME.toLowerCase();
}
insertStatement = connection.prepareStatement(getInsertSQL(),
- new String[] {EVENT_ID_COL_NAME});
+ new String[] { EVENT_ID_COL_NAME });
} else {
insertStatement = connection.prepareStatement(getInsertSQL());
}
- subAppend(eventObject, connection, insertStatement);
+
+ long eventId;
+ // inserting an event and getting the result must be exclusive
+ synchronized (this) {
+ subAppend(eventObject, connection, insertStatement);
+ eventId = selectEventId(insertStatement, connection);
+ }
+ System.out.println("eventid="+eventId);
+ secondarySubAppend(eventObject, connection, eventId);
// we no longer need the insertStatement
close(insertStatement);
insertStatement = null;
-
+
connection.commit();
} catch (Throwable sqle) {
addError("problem appending event", sqle);
@@ -115,9 +123,12 @@ public abstract class DBAppenderBase<E> extends AppenderBase<E> {
}
}
- protected abstract void subAppend(Object eventObject, Connection connection,
+ protected abstract void subAppend(E eventObject, Connection connection,
PreparedStatement statement) throws Throwable;
+ protected abstract void secondarySubAppend(E eventObject, Connection connection,
+ long eventId) throws Throwable;
+
protected long selectEventId(PreparedStatement insertStatement,
Connection connection) throws SQLException, InvocationTargetException {
ResultSet rs = null;
@@ -144,7 +155,8 @@ public abstract class DBAppenderBase<E> extends AppenderBase<E> {
if (!gotGeneratedKeys) {
idStatement = connection.createStatement();
idStatement.setMaxRows(1);
- rs = idStatement.executeQuery(sqlDialect.getSelectInsertId());
+ String selectInsertIdStr = sqlDialect.getSelectInsertId();
+ rs = idStatement.executeQuery(selectInsertIdStr);
}
// A ResultSet cursor is initially positioned before the first row;
@@ -156,16 +168,16 @@ public abstract class DBAppenderBase<E> extends AppenderBase<E> {
close(idStatement);
idStatement = null;
-
+
return eventId;
}
void close(Statement statement) throws SQLException {
- if(statement != null) {
+ if (statement != null) {
statement.close();
}
}
-
+
@Override
public void stop() {
super.stop();
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 92ca237..3374279 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -61,6 +61,35 @@
</div>
+ <br/>
+
+ <div style="border: 1px solid #F44; background-color: #FED; padding-left: 1ex; padding-right: 1ex;">
+
+ <h4>Breaking change: DBAppender in logback-classic expects four
+ additional columns
+ </h4>
+
+ <p>Instead of lumping log request arguments into a field,
+ <code>DBAppender</code> (in logback-classic) now outputs up to
+ four arguments in the logging request in separate columns, named
+ <code>arg0</code>, <code>arg1</code>, <code>arg2</code> and
+ <code>arg4</code>. This solves <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-187">LBCLASSIC-187</a>
+ reported by Greg Thomas.</p>
+
+ <p>Existing databases can be migrated to the new table structure
+ by altering the existing tables. Here is how it would be done
+ in PostgreSQL.</p>
+
+ <pre class="prettyprint">
+ALTER TABLE logging_event ADD COLUMN arg0 CARCHAR(254);
+ALTER TABLE logging_event ADD COLUMN arg1 VARCHAR(254);
+ALTER TABLE logging_event ADD COLUMN arg3 VARCHAR(254);
+ALTER TABLE logging_event ADD COLUMN arg3 VARCHAR(254);
+</pre>
+
+
+ </div>
<p><code>FileAppender</code> and derived classes can now
gracefully deal with IO failures and recover quickly after the
original cause of the IO failure is corrected. For example, if the
@@ -150,9 +179,19 @@
in <a href="http://jira.qos.ch/browse/LBCORE-126">LBCORE-126</a>
by Brian Edwards.</p>
+ <p>Event id values in DBAppender are now 64bit instead of 32. This
+ change was requested in <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-198">LBCLASSIC-198</a>
+ by Michael Lynch.
+ </p>
+
<p>Added Sybase SQLAnywhere support in DBAppender. This feature
was requested by Michael Lynch in <a
href="http://jira.qos.ch/browse/LBCLASSIC-197">LBCLASSIC-197</a>.
+ </p>
+
+ <p>Added H2 support in DBAppender.</p>
+
<p>Fixed <a
href="http://jira.qos.ch/browse/LBSITE-36">LBSITE-36</a> reported
-----------------------------------------------------------------------
Summary of changes:
.../java/ch/qos/logback/access/db/DBAppender.java | 9 ++-
.../ch/qos/logback/access/db/DBAppenderTest.java | 5 +-
.../LoggingEvent Serialization.odt | Bin 12724 -> 0 bytes
.../java/ch/qos/logback/classic/db/DBAppender.java | 74 ++++++++++++++++----
.../java/ch/qos/logback/classic/db/SQLBuilder.java | 6 ++-
.../java/ch/qos/logback/classic/db/dialect/db2.sql | 4 +
.../logback/classic/db/dialect/deleteTables.sql | 3 -
.../java/ch/qos/logback/classic/db/dialect/h2.sql | 4 +
.../ch/qos/logback/classic/db/dialect/hsqldb.sql | 4 +
.../ch/qos/logback/classic/db/dialect/mssql.sql | 4 +
.../ch/qos/logback/classic/db/dialect/mysql.sql | 4 +
.../ch/qos/logback/classic/db/dialect/oracle.sql | 4 +
.../qos/logback/classic/db/dialect/postgresql.sql | 4 +
.../classic/db/dialect/sybaseSqlAnywhere.sql | 28 ++++---
.../qos/logback/classic/db/names/ColumnName.java | 4 +
.../qos/logback/classic/db/DBAppenderH2Test.java | 21 +++---
.../classic/db/DBAppenderH2TestFixture.java | 4 +
.../qos/logback/classic/db/DBAppenderHSQLTest.java | 24 ++++---
.../classic/db/DBAppenderHSQLTestFixture.java | 7 ++
.../classic/db/DBAppenderIntegrationTest.java | 5 +-
.../ch/qos/logback/core/db/DBAppenderBase.java | 40 +++++++----
logback-site/src/site/pages/news.html | 39 ++++++++++
22 files changed, 224 insertions(+), 73 deletions(-)
delete mode 100644 logback-classic/doc/designDiscussion/LoggingEvent Serialization.odt
delete mode 100644 logback-classic/src/main/java/ch/qos/logback/classic/db/dialect/deleteTables.sql
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list