logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: logging-log4j/src/java/org/apache/log4j/db DBHelper.java DBAppender.java
Date Mon, 10 May 2004 17:26:58 GMT
ceki        2004/05/10 10:26:58

  Modified:    src/java/org/apache/log4j/db/dialect postgresql.sql
                        mysql.sql oracle.sql
               src/java/org/apache/log4j/db DBAppender.java
  Added:       src/java/org/apache/log4j/db DBHelper.java
  Log:
  Added support for exceptions (stack traces) in their own table.
  
  Revision  Changes    Path
  1.4       +1 -1      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- postgresql.sql	10 May 2004 09:30:14 -0000	1.3
  +++ postgresql.sql	10 May 2004 17:26:58 -0000	1.4
  @@ -19,7 +19,7 @@
       level_string      VARCHAR(254) NOT NULL,
       ndc               TEXT,
       thread_name       VARCHAR(254),
  -    flag              SMALLINT,
  +    reference_flag    SMALLINT,
       id                INT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY
     );
   
  
  
  
  1.4       +4 -3      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- mysql.sql	10 May 2004 09:30:14 -0000	1.3
  +++ mysql.sql	10 May 2004 17:26:58 -0000	1.4
  @@ -6,8 +6,9 @@
   
   
   BEGIN;
  -DROP TABLE IF EXISTS loggging_event;
  -DROP TABLE IF EXISTS mdc;
  +DROP TABLE IF EXISTS logging_event;
  +DROP TABLE IF EXISTS logging_event_property;
  +DROP TABLE IF EXISTS logging_event_exception;
   COMMIT;
   
   
  @@ -21,7 +22,7 @@
       level_string      VARCHAR(254) NOT NULL,
       ndc               TEXT,
       thread_name       VARCHAR(254),
  -    flag              SMALLINT,
  +    reference_flag    SMALLINT,
       id                INT NOT NULL AUTO_INCREMENT PRIMARY KEY
     );
   COMMIT;
  
  
  
  1.5       +11 -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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- oracle.sql	10 May 2004 09:30:14 -0000	1.4
  +++ oracle.sql	10 May 2004 17:26:58 -0000	1.5
  @@ -20,6 +20,7 @@
       level_string      VARCHAR(254) NOT NULL,
       ndc               TEXT,
       thread_name       VARCHAR(254),
  +    reference_flag    SMALLINT,
       id                INT PRIMARY KEY
     );
   
  @@ -40,6 +41,16 @@
       PRIMARY KEY(event_id, mapped_key),
       FOREIGN KEY (event_id) REFERENCES logging_event(id)
     );
  +  
  +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(id)
  +  );
  +  
   
   
   
  
  
  
  1.5       +29 -16    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DBAppender.java	10 May 2004 09:40:08 -0000	1.4
  +++ DBAppender.java	10 May 2004 17:26:58 -0000	1.5
  @@ -80,9 +80,7 @@
   
   
     protected void append(LoggingEvent event) {
  -    Set propertiesKeys = event.getPropertyKeySet();
  -    String[] throwableStrRep = event.getThrowableStrRep();
  -    
  + 
       try {
         Connection connection = connectionSource.getConnection();
         connection.setAutoCommit(false);
  @@ -98,8 +96,8 @@
         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, flag) ");
  -      sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?)");
  +      sql.append("logger_name, level_string, ndc, thread_name, reference_flag) ");
  +      sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?)");
   
         PreparedStatement insertStatement = connection.prepareStatement(sql.toString());
         insertStatement.setLong(1, event.getSequenceNumber());
  @@ -109,7 +107,7 @@
         insertStatement.setString(5, event.getLevel().toString());
         insertStatement.setString(6, event.getNDC());
         insertStatement.setString(7, event.getThreadName());
  -      insertStatement.setShort(8, computeFlag(event, propertiesKeys, throwableStrRep));
  +      insertStatement.setShort(8, DBHelper.computeReferenceMask(event));
         
         int updateCount = insertStatement.executeUpdate();
   
  @@ -130,22 +128,41 @@
   //      mapped_key        VARCHAR(254) NOT NULL,
   //      mapped_value      VARCHAR(254),
   
  +      Set propertiesKeys = event.getPropertyKeySet();
         if (propertiesKeys.size() > 0) {
           String insertPropertiesSQL = "INSERT INTO  logging_event_property (event_id, mapped_key,
mapped_value) VALUES (?, ?, ?)";
  -        PreparedStatement insertMDCStatement = connection.prepareStatement(insertPropertiesSQL);
  +        PreparedStatement insertPropertiesStatement = connection.prepareStatement(insertPropertiesSQL);
   
           for (Iterator i = propertiesKeys.iterator(); i.hasNext();) {
             String key = (String)i.next();
             String value = (String)event.getProperty(key);
             LogLog.debug("id " + eventId + ", key " + key + ", value " + value);
  -          insertMDCStatement.setInt(1, eventId);
  -          insertMDCStatement.setString(2, key);
  -          insertMDCStatement.setString(3, value);
  -          insertMDCStatement.addBatch();
  +          insertPropertiesStatement.setInt(1, eventId);
  +          insertPropertiesStatement.setString(2, key);
  +          insertPropertiesStatement.setString(3, value);
  +          insertPropertiesStatement.addBatch();
           }
  -        insertMDCStatement.executeBatch();
  +        insertPropertiesStatement.executeBatch();
         }
   
  +      String[] strRep = event.getThrowableStrRep();
  +      if(strRep != null) {
  +        LogLog.info("Logging an exception");
  +//        CREATE TABLE logging_event_exception (
  +//          event_id         INT NOT NULL,
  +//          i                SMALLINT NOT NULL,
  +//          trace_line       VARCHAR(254) NOT NULL)
  +        String insertExceptionSQL = "INSERT INTO  logging_event_exception (event_id, i,
trace_line) VALUES (?, ?, ?)";
  +        PreparedStatement insertExceptionStatement = connection.prepareStatement(insertExceptionSQL);
  +        
  +        for (short i = 0; i < strRep.length; i++) {
  +          insertExceptionStatement.setInt(1, eventId);
  +          insertExceptionStatement.setShort(2, i);
  +          insertExceptionStatement.setString(3, strRep[i]);
  +          insertExceptionStatement.addBatch();
  +        }
  +        insertExceptionStatement.executeBatch();
  +      }
         connection.commit();
       } catch (SQLException sqle) {
         LogLog.error("problem appending event", sqle);
  @@ -153,11 +170,7 @@
     }
   
   
  -  short computeFlag(LoggingEvent event, Set propertyJeys, String[] strRep) {
   
  -    return 0;
  -  }
  -  
     public void close() {
       // TODO Auto-generated method st  
     }
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/db/DBHelper.java
  
  Index: DBHelper.java
  ===================================================================
  /*
   * Created on May 10, 2004
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.log4j.db;
  
  import java.util.Set;
  
  import org.apache.log4j.spi.LoggingEvent;
  
  /**
   * @author Ceki G&uuml;lc&uuml;
   *
   */
  public class DBHelper {
    
    static short PROPERTIES_EXIST = 0x01;
    static short EXCEPTION_EXISTS = 0x02;
    
    static short computeReferenceMask(LoggingEvent event) {
      short mask = 0;
      Set propertiesKeys = event.getPropertyKeySet();
      if(propertiesKeys.size() > 0) {
        mask = PROPERTIES_EXIST;
      }
      String[] strRep = event.getThrowableStrRep();
      if(strRep != null) {
        mask |= EXCEPTION_EXISTS;
      }
      return mask;
    }
    
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message