[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-114-gcc1540f
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Tue Mar 23 23:53:35 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 cc1540f6a907d3f366cc1acbafc6056824b89875 (commit)
from 2181956a1dae32a14218f9da2d844e8913bb218e (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=cc1540f6a907d3f366cc1acbafc6056824b89875
http://github.com/ceki/logback/commit/cc1540f6a907d3f366cc1acbafc6056824b89875
commit cc1540f6a907d3f366cc1acbafc6056824b89875
Author: Ceki Gulcu <ceki at qos.ch>
Date: Tue Mar 23 23:51:48 2010 +0100
- table and col names converted to lower case
- tests pass for PostgreSQL, Oracle 10, MySQL, H2, HSQL
diff --git a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/hsqldb.sql b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/hsqldb.sql
index c82b677..714630c 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/hsqldb.sql
+++ b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/hsqldb.sql
@@ -17,11 +17,11 @@ CREATE TABLE access_event (
method VARCHAR(254),
serverName VARCHAR(254),
postContent VARCHAR(254),
- event_id INT NOT NULL IDENTITY);
+ event_id BIGINT NOT NULL IDENTITY);
CREATE TABLE access_event_header (
- event_id INT NOT NULL,
+ event_id BIGINT NOT NULL,
header_key VARCHAR(254) NOT NULL,
header_value LONGVARCHAR,
PRIMARY KEY(event_id, header_key),
diff --git a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/mysql.sql b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/mysql.sql
index 6c6a055..70bb9f6 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/mysql.sql
+++ b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/mysql.sql
@@ -10,10 +10,10 @@ DROP TABLE IF EXISTS access_event;
COMMIT;
BEGIN;
-CREATE TABLE access_event
+CREATE TABLE ACCESS_EVENT
(
timestmp BIGINT NOT NULL,
- requestURI VARCHAR(254),
+ requestURI VARCHAR(254),
requestURL VARCHAR(254),
remoteHost VARCHAR(254),
remoteUser VARCHAR(254),
@@ -22,14 +22,14 @@ CREATE TABLE access_event
method VARCHAR(254),
serverName VARCHAR(254),
postContent VARCHAR(254),
- event_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
+ event_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
);
COMMIT;
BEGIN;
CREATE TABLE access_event_header
(
- event_id INT NOT NULL,
+ event_id BIGINT NOT NULL,
header_key VARCHAR(254) NOT NULL,
header_value VARCHAR(1024),
PRIMARY KEY(event_id, header_key),
diff --git a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/oracle.sql b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/oracle.sql
index a41ac46..9533d1e 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/oracle.sql
+++ b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/oracle.sql
@@ -9,7 +9,7 @@ CREATE SEQUENCE access_event_id_seq MINVALUE 1 START WITH 1;
CREATE TABLE access_event
(
timestmp NUMBER(20) NOT NULL,
- requestURI VARCHAR(254),
+ requestURI VARCHAR(254),
requestURL VARCHAR(254),
remoteHost VARCHAR(254),
remoteUser VARCHAR(254),
@@ -18,7 +18,7 @@ CREATE TABLE access_event
method VARCHAR(254),
serverName VARCHAR(254),
postContent VARCHAR(254),
- event_id NUMBER(10) PRIMARY KEY
+ event_id NUMBER(20) PRIMARY KEY
);
-- the / suffix may or may not be needed depending on your SQL Client
@@ -38,7 +38,7 @@ CREATE TRIGGER access_event_id_seq_trig
CREATE TABLE access_event_header
(
- event_id NUMBER(10) NOT NULL,
+ event_id NUMBER(20) NOT NULL,
header_key VARCHAR2(254) NOT NULL,
header_value VARCHAR2(1024),
PRIMARY KEY(event_id, header_key),
diff --git a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/postgresql.sql b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/postgresql.sql
index 00e4af1..ba5cce7 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/db/dialect/postgresql.sql
+++ b/logback-access/src/main/java/ch/qos/logback/access/db/dialect/postgresql.sql
@@ -11,7 +11,7 @@ CREATE SEQUENCE access_event_id_seq MINVALUE 1 START 1;
CREATE TABLE access_event
(
timestmp BIGINT NOT NULL,
- requestURI VARCHAR(254),
+ requestURI VARCHAR(254),
requestURL VARCHAR(254),
remoteHost VARCHAR(254),
remoteUser VARCHAR(254),
@@ -20,12 +20,12 @@ CREATE TABLE access_event
method VARCHAR(254),
serverName VARCHAR(254),
postContent VARCHAR(254),
- event_id INT DEFAULT nextval('access_event_id_seq') PRIMARY KEY
+ event_id BIGINT DEFAULT nextval('access_event_id_seq') PRIMARY KEY
);
CREATE TABLE access_event_header
(
- event_id INT NOT NULL,
+ event_id BIGINT NOT NULL,
header_key VARCHAR(254) NOT NULL,
header_value VARCHAR(1024),
PRIMARY KEY(event_id, header_key),
diff --git a/logback-access/src/test/input/integration/db/postgresql-with-driver.xml b/logback-access/src/test/input/integration/db/postgresql-with-driver.xml
index 8b047ab..34fc95c 100644
--- a/logback-access/src/test/input/integration/db/postgresql-with-driver.xml
+++ b/logback-access/src/test/input/integration/db/postgresql-with-driver.xml
@@ -2,15 +2,15 @@
<configuration>
- <appender name="DB" class="ch.qos.logback.access.db.DBAppender">
- <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
- <driverClass>org.postgresql.Driver</driverClass>
- <url>jdbc:postgresql://192.168.1.5:5432/test</url>
- <user>logback</user>
- <password>logback</password>
- </connectionSource>
- </appender>
+ <appender name="DB" class="ch.qos.logback.access.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+ <driverClass>org.postgresql.Driver</driverClass>
+ <url>jdbc:postgresql://192.168.1.5:5432/test</url>
+ <user>logback</user>
+ <password>logback</password>
+ </connectionSource>
+ </appender>
- <appender-ref ref="DB" />
+ <appender-ref ref="DB" />
</configuration>
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 68c398f..b0c298a 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
@@ -95,8 +95,6 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
}
long eventId = selectEventId(insertStatement, connection);
-
- System.out.println("eventId"+eventId);
Map<String, String> mergedMap = mergePropertyMaps(event);
insertProperties(mergedMap, connection, eventId);
@@ -248,7 +246,6 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
if (cnxSupportsBatchUpdates) {
exceptionStatement.executeBatch();
- System.out.println("executin batch");
}
exceptionStatement.close();
exceptionStatement = null;
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 f8660c0..f053863 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
@@ -3,34 +3,34 @@
# It is intended for H2 databases.
-DROP TABLE LOGGING_EVENT_EXCEPTION IF EXISTSu;
-DROP TABLE LOGGING_EVENT_PROPERTY IF EXISTS;
-DROP TABLE LOGGING_EVENT IF EXISTS;
+DROP TABLE logging_event_exception IF EXISTSu;
+DROP TABLE logging_event_property IF EXISTS;
+DROP TABLE logging_event IF EXISTS;
-CREATE TABLE LOGGING_EVENT (
- TIMESTMP BIGINT NOT NULL,
- FORMATTED_MESSAGE LONGVARCHAR NOT NULL,
- LOGGER_NAME VARCHAR(256) NOT NULL,
- LEVEL_STRING VARCHAR(256) NOT NULL,
- THREAD_NAME VARCHAR(256),
- REFERENCE_FLAG SMALLINT,
- CALLER_FILENAME VARCHAR(256),
- CALLER_CLASS VARCHAR(256),
- CALLER_METHOD VARCHAR(256),
- CALLER_LINE CHAR(4),
- EVENT_ID IDENTITY NOT NULL);
+CREATE TABLE logging_event (
+ timestmp BIGINT NOT NULL,
+ formatted_message LONGVARCHAR NOT NULL,
+ logger_name VARCHAR(256) NOT NULL,
+ level_string VARCHAR(256) NOT NULL,
+ thread_name VARCHAR(256),
+ reference_flag SMALLINT,
+ caller_filename VARCHAR(256),
+ caller_class VARCHAR(256),
+ caller_method VARCHAR(256),
+ caller_line CHAR(4),
+ event_id IDENTITY NOT NULL);
-CREATE TABLE LOGGING_EVENT_PROPERTY (
- EVENT_ID BIGINT 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_property (
+ event_id BIGINT 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 BIGINT NOT NULL,
- I SMALLINT NOT NULL,
- TRACE_LINE VARCHAR(256) NOT NULL,
- PRIMARY KEY(EVENT_ID, I),
- FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));
+CREATE TABLE logging_event_exception (
+ event_id BIGINT NOT NULL,
+ i SMALLINT NOT NULL,
+ trace_line VARCHAR(256) NOT NULL,
+ PRIMARY KEY(event_id, i),
+ FOREIGN KEY (event_id) REFERENCES logging_event(event_id));
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 e308f34..07cf847 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
@@ -2,34 +2,34 @@
#
# It is intended for HSQL databases. It has been tested on HSQL 1.8.07.
-DROP TABLE LOGGING_EVENT_EXCEPTION IF EXISTSu;
-DROP TABLE LOGGING_EVENT_PROPERTY IF EXISTS;
-DROP TABLE LOGGING_EVENT IF EXISTS;
+DROP TABLE logging_event_exception IF EXISTS;
+DROP TABLE logging_event_property IF EXISTS;
+DROP TABLE logging_event IF EXISTS;
-CREATE TABLE LOGGING_EVENT (
- TIMESTMP BIGINT NOT NULL,
- FORMATTED_MESSAGE LONGVARCHAR NOT NULL,
- LOGGER_NAME VARCHAR(256) NOT NULL,
- LEVEL_STRING VARCHAR(256) NOT NULL,
- THREAD_NAME VARCHAR(256),
- REFERENCE_FLAG SMALLINT,
- CALLER_FILENAME VARCHAR(256),
- CALLER_CLASS VARCHAR(256),
- CALLER_METHOD VARCHAR(256),
- CALLER_LINE CHAR(4),
- EVENT_ID BIGINT NOT NULL IDENTITY);
+CREATE TABLE logging_event (
+ timestmp BIGINT NOT NULL,
+ formatted_message LONGVARCHAR NOT NULL,
+ logger_name VARCHAR(256) NOT NULL,
+ level_string VARCHAR(256) NOT NULL,
+ thread_name VARCHAR(256),
+ reference_flag SMALLINT,
+ caller_filename VARCHAR(256),
+ caller_class VARCHAR(256),
+ caller_method VARCHAR(256),
+ caller_line CHAR(4),
+ event_id BIGINT NOT NULL IDENTITY);
-CREATE TABLE LOGGING_EVENT_PROPERTY (
- EVENT_ID BIGINT 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_property (
+ event_id BIGINT 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 BIGINT NOT NULL,
- I SMALLINT NOT NULL,
- TRACE_LINE VARCHAR(256) NOT NULL,
- PRIMARY KEY(EVENT_ID, I),
- FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID));
\ No newline at end of file
+CREATE TABLE logging_event_exception (
+ event_id BIGINT NOT NULL,
+ i SMALLINT NOT NULL,
+ trace_line VARCHAR(256) NOT NULL,
+ PRIMARY KEY(event_id, i),
+ FOREIGN KEY (event_id) REFERENCES logging_event(event_id));
\ No newline at end of file
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 e8c2fb3..5195dcf 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
@@ -5,47 +5,47 @@
BEGIN;
-DROP TABLE IF EXISTS LOGGING_EVENT_PROPERTY;
-DROP TABLE IF EXISTS LOGGING_EVENT_EXCEPTION;
-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;
BEGIN;
-CREATE TABLE LOGGING_EVENT
+CREATE TABLE logging_event
(
- TIMESTMP BIGINT NOT NULL,
- FORMATTED_MESSAGE TEXT 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 CHAR(4) NOT NULL,
- EVENT_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY
+ timestmp BIGINT NOT NULL,
+ formatted_message TEXT 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 CHAR(4) NOT NULL,
+ event_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
);
COMMIT;
BEGIN;
-CREATE TABLE LOGGING_EVENT_PROPERTY
+CREATE TABLE logging_event_property
(
- EVENT_ID INT NOT NULL,
- MAPPED_KEY VARCHAR(254) NOT NULL,
- MAPPED_VALUE TEXT,
- PRIMARY KEY(EVENT_ID, MAPPED_KEY),
- FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID)
+ event_id BIGINT NOT NULL,
+ mapped_key VARCHAR(254) NOT NULL,
+ mapped_value TEXT,
+ PRIMARY KEY(event_id, mapped_key),
+ FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
);
COMMIT;
BEGIN;
-CREATE TABLE LOGGING_EVENT_EXCEPTION
+CREATE TABLE logging_event_exception
(
- EVENT_ID INT NOT NULL,
- I SMALLINT NOT NULL,
- TRACE_LINE VARCHAR(254) NOT NULL,
- PRIMARY KEY(EVENT_ID, I),
- FOREIGN KEY (EVENT_ID) REFERENCES LOGGING_EVENT(EVENT_ID)
+ event_id BIGINT NOT NULL,
+ i SMALLINT NOT NULL,
+ trace_line VARCHAR(254) NOT NULL,
+ PRIMARY KEY(event_id, i),
+ FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
);
COMMIT;
\ No newline at end of file
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 9ac0b79..89e244e 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
@@ -13,7 +13,7 @@
CREATE SEQUENCE logging_event_id_seq MINVALUE 1 START WITH 1;
-CREATE SEQUENCE logging_event_id_seq MINVALUE 1 START WITH 1;
+
CREATE TABLE logging_event
(
timestmp NUMBER(20) 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 55c7343..25a3dd1 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
@@ -14,7 +14,7 @@ CREATE SEQUENCE logging_event_id_seq MINVALUE 1 START 1;
CREATE TABLE logging_event
(
timestmp BIGINT NOT NULL,
- formatted_message TEXT NOT NULL,
+ formatted_message TEXT NOT NULL,
logger_name VARCHAR(254) NOT NULL,
level_string VARCHAR(254) NOT NULL,
thread_name VARCHAR(254),
@@ -23,12 +23,12 @@ CREATE TABLE logging_event
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
+ event_id BIGINT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY
);
CREATE TABLE logging_event_property
(
- event_id INT NOT NULL,
+ event_id BIGINT NOT NULL,
mapped_key VARCHAR(254) NOT NULL,
mapped_value VARCHAR(1024),
PRIMARY KEY(event_id, mapped_key),
@@ -37,7 +37,7 @@ CREATE TABLE logging_event_property
CREATE TABLE logging_event_exception
(
- event_id INT NOT NULL,
+ event_id BIGINT NOT NULL,
i SMALLINT NOT NULL,
trace_line VARCHAR(254) NOT NULL,
PRIMARY KEY(event_id, i),
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/names/DefaultDBNameResolver.java b/logback-classic/src/main/java/ch/qos/logback/classic/db/names/DefaultDBNameResolver.java
index db88a52..e7ce6c8 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/names/DefaultDBNameResolver.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/names/DefaultDBNameResolver.java
@@ -14,17 +14,21 @@
package ch.qos.logback.classic.db.names;
/**
+ * The default name resolver simply returns the enum passes as parameter
+ * as a lower case string.
+ *
* @author Tomasz Nurkiewicz
- * @since 2010-03-16
+ * @author Ceki Gulcu
+ * @since 0.9.19
*/
public class DefaultDBNameResolver implements DBNameResolver {
public <N extends Enum<?>> String getTableName(N tableName) {
- return tableName.toString();
+ return tableName.toString().toLowerCase();
}
public <N extends Enum<?>> String getColumnName(N columnName) {
- return columnName.toString();
+ return columnName.toString().toLowerCase();
}
}
diff --git a/logback-classic/src/test/input/integration/db/postgresql-with-driver.xml b/logback-classic/src/test/input/integration/db/postgresql-with-driver.xml
index 976ddc7..0bcade1 100644
--- a/logback-classic/src/test/input/integration/db/postgresql-with-driver.xml
+++ b/logback-classic/src/test/input/integration/db/postgresql-with-driver.xml
@@ -12,7 +12,7 @@
</appender>
<root>
- <level value="debug" />
+ <level value="DEBUG" />
<appender-ref ref="DB" />
</root>
</configuration>
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 ce0d3da..34c6001 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
@@ -14,9 +14,16 @@
package ch.qos.logback.classic.db;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.net.InetAddress;
-import java.util.Random;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.After;
import org.junit.AfterClass;
@@ -29,9 +36,11 @@ import org.slf4j.MDC;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.db.DriverManagerConnectionSource;
import ch.qos.logback.core.joran.spi.JoranException;
-import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusChecker;
import ch.qos.logback.core.testUtil.Env;
+import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.StatusPrinter;
public class DBAppenderIntegrationTest {
@@ -41,8 +50,8 @@ public class DBAppenderIntegrationTest {
static String[] POSTGRES_CONFORMING_HOST_LIST = new String[] { "haro" };
static String[] MYSQL_CONFORMING_HOST_LIST = new String[] { "haro" };
static String[] ORACLE_CONFORMING_HOST_LIST = new String[] { "haro" };
-
- int diff = new Random(System.nanoTime()).nextInt(10000);
+
+ int diff = RandomUtil.getPositiveInt();
LoggerContext lc = new LoggerContext();
@BeforeClass
@@ -66,7 +75,17 @@ public class DBAppenderIntegrationTest {
lc.stop();
}
- public void doTest(String configFile) throws JoranException {
+ DriverManagerConnectionSource getConnectionSource() {
+ ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) lc
+ .getLogger(Logger.ROOT_LOGGER_NAME);
+
+ DBAppender dbAppender = (DBAppender) root.getAppender("DB");
+ assertNotNull(dbAppender);
+ return (DriverManagerConnectionSource) dbAppender.getConnectionSource();
+
+ }
+
+ public void doTest(String configFile) throws JoranException, SQLException {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
configurator.doConfigure(configFile);
@@ -76,16 +95,86 @@ public class DBAppenderIntegrationTest {
MDC.put("userid", "user" + diff);
int runLength = 5;
for (int i = 1; i <= runLength; i++) {
- logger.debug("This is a debug message. Message number: " + i);
+ logger.debug("This is a debug message. Message number: " + (diff + i));
}
Exception e = new Exception("Just testing", getCause());
- logger
- .error("At last an error.", e);
+ logger.error("At last an error.", e);
+
+ long lastEventId = getLastEventId();
+ verify(lastEventId);
+
// check that there were no errors
- StatusPrinter.print(lc);
- assertEquals(Status.INFO, lc.getStatusManager().getLevel());
+ StatusChecker checker = new StatusChecker(lc);
+ assertTrue(checker.isErrorFree());
+ StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+ }
+
+ long getLastEventId() throws SQLException {
+ DriverManagerConnectionSource cs = getConnectionSource();
+
+ Connection con = cs.getConnection();
+ Statement statement = con.createStatement();
+ statement.setMaxRows(1);
+ ResultSet rs = statement
+ .executeQuery("select event_id from logging_event order by event_id desc");
+ rs.next();
+ long eventId = rs.getLong(1);
+ rs.close();
+ statement.close();
+ return eventId;
+ }
+
+ void verify(long lastEventId) throws SQLException {
+ verifyDebugMsg(lastEventId);
+ verifyException(lastEventId);
+ verifyProperty(lastEventId);
+
+ }
+
+ void verifyDebugMsg(long lastEventId) throws SQLException {
+ DriverManagerConnectionSource cs = getConnectionSource();
+ Connection con = cs.getConnection();
+ Statement statement = con.createStatement();
+ ResultSet rs = statement
+ .executeQuery("select formatted_message from logging_event where event_id='"
+ + (lastEventId - 1) + "'");
+ rs.next();
+ String msg = rs.getString(1);
+ assertEquals("This is a debug message. Message number: " + (diff + 5), msg);
+ }
+
+ void verifyProperty(long lastEventId) throws SQLException {
+ DriverManagerConnectionSource cs = getConnectionSource();
+ Connection con = cs.getConnection();
+ Statement statement = con.createStatement();
+ ResultSet rs = statement
+ .executeQuery("select mapped_key, mapped_value from logging_event_property where event_id='"
+ + (lastEventId - 1) + "'");
+
+ Map<String, String> witness = lc.getCopyOfPropertyMap();
+ witness.putAll(MDC.getCopyOfContextMap());
+
+ Map map = new HashMap();
+ while (rs.next()) {
+ String key = rs.getString(1);
+ String val = rs.getString(2);
+ map.put(key, val);
+ }
+
+ assertEquals(witness, map);
+ }
+ void verifyException(long lastEventId) throws SQLException {
+ DriverManagerConnectionSource cs = getConnectionSource();
+ Connection con = cs.getConnection();
+ Statement statement = con.createStatement();
+ ResultSet rs = statement
+ .executeQuery("select trace_line from logging_event_exception where event_id='"
+ + (lastEventId) + "' AND I='0'");
+ rs.next();
+ String traceLine = rs.getString(1);
+ assertEquals("java.lang.Exception: Just testing", traceLine);
}
Throwable getCause() {
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverterTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverterTest.java
index 8a2e364..3ccdd39 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverterTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverterTest.java
@@ -93,7 +93,7 @@ public class ExtendedThrowableProxyConverterTest {
ILoggingEvent le = createLoggingEvent(t);
String result = etpc.convert(le);
result = result.replace("common frames omitted", "more");
- result = result.replaceAll(" \\[.*\\]", "");
+ result = result.replaceAll(" ~?\\[.*\\]", "");
assertEquals(sw.toString(), result);
}
-----------------------------------------------------------------------
Summary of changes:
.../ch/qos/logback/access/db/dialect/hsqldb.sql | 4 +-
.../ch/qos/logback/access/db/dialect/mysql.sql | 8 +-
.../ch/qos/logback/access/db/dialect/oracle.sql | 6 +-
.../qos/logback/access/db/dialect/postgresql.sql | 6 +-
.../integration/db/postgresql-with-driver.xml | 18 ++--
.../java/ch/qos/logback/classic/db/DBAppender.java | 3 -
.../java/ch/qos/logback/classic/db/dialect/h2.sql | 54 +++++-----
.../ch/qos/logback/classic/db/dialect/hsqldb.sql | 54 +++++-----
.../ch/qos/logback/classic/db/dialect/mysql.sql | 54 +++++-----
.../ch/qos/logback/classic/db/dialect/oracle.sql | 2 +-
.../qos/logback/classic/db/dialect/postgresql.sql | 8 +-
.../classic/db/names/DefaultDBNameResolver.java | 10 ++-
.../integration/db/postgresql-with-driver.xml | 2 +-
.../classic/db/DBAppenderIntegrationTest.java | 109 ++++++++++++++++++--
.../ExtendedThrowableProxyConverterTest.java | 2 +-
15 files changed, 215 insertions(+), 125 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list