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 DBAppender.java
Date Mon, 10 May 2004 09:30:17 GMT
ceki        2004/05/10 02:30:17

  Modified:    src/java/org/apache/log4j/db/dialect postgresql.sql
                        mysql.sql oracle.sql
               src/java/org/apache/log4j/varia LogFilePatternReceiver.java
               src/java/org/apache/log4j/spi LoggingEvent.java
               src/java/org/apache/log4j/db DBAppender.java
  Log:
  - Continued work on DBAppender 
  - Addition of setter methods to LoggingEvent so that receivers can
  create an event piecemally.
  - Modified LogFilePatternReceiver to use the new LoggingEvent setter methods.
  
  Revision  Changes    Path
  1.3       +11 -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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- postgresql.sql	9 May 2004 18:37:56 -0000	1.2
  +++ postgresql.sql	10 May 2004 09:30:14 -0000	1.3
  @@ -16,12 +16,14 @@
       timestamp         BIGINT NOT NULL,
       rendered_message  TEXT NOT NULL,
       logger_name       VARCHAR(254) NOT NULL,
  +    level_string      VARCHAR(254) NOT NULL,
       ndc               TEXT,
       thread_name       VARCHAR(254),
  +    flag              SMALLINT,
       id                INT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY
     );
   
  -CREATE TABLE mdc
  +CREATE TABLE logging_event_property
     (
       event_id	      INT NOT NULL,
       mapped_key        VARCHAR(254) NOT NULL,
  @@ -30,3 +32,11 @@
       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.3       +16 -2     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- mysql.sql	9 May 2004 18:37:56 -0000	1.2
  +++ mysql.sql	10 May 2004 09:30:14 -0000	1.3
  @@ -1,7 +1,8 @@
   # This SQL script creates the required tables by org.apache.log4j.db.DBAppender and 
   # org.apache.log4j.db.DBReceiver.
   #
  -# It is intended for MySQL databases.
  +# It is intended for MySQL databases. It has been tested on MySQL 4.1.1 with 
  +# INNODB tables.
   
   
   BEGIN;
  @@ -17,14 +18,16 @@
       timestamp         BIGINT NOT NULL,
       rendered_message  TEXT NOT NULL,
       logger_name       VARCHAR(254) NOT NULL,
  +    level_string      VARCHAR(254) NOT NULL,
       ndc               TEXT,
       thread_name       VARCHAR(254),
  +    flag              SMALLINT,
       id                INT NOT NULL AUTO_INCREMENT PRIMARY KEY
     );
   COMMIT;
   
   BEGIN;
  -CREATE TABLE mdc
  +CREATE TABLE logging_event_property
     (
       event_id	      INT NOT NULL,
       mapped_key        VARCHAR(254) NOT NULL,
  @@ -33,3 +36,14 @@
       FOREIGN KEY (event_id) REFERENCES logging_event(id)
     );
   COMMIT;
  +
  +BEGIN;
  +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)
  +  );
  +COMMIT;
  \ No newline at end of file
  
  
  
  1.4       +2 -1      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- oracle.sql	9 May 2004 18:37:56 -0000	1.3
  +++ oracle.sql	10 May 2004 09:30:14 -0000	1.4
  @@ -17,6 +17,7 @@
       timestamp         BIGINT NOT NULL,
       rendered_message  TEXT NOT NULL,
       logger_name       VARCHAR(254) NOT NULL,
  +    level_string      VARCHAR(254) NOT NULL,
       ndc               TEXT,
       thread_name       VARCHAR(254),
       id                INT PRIMARY KEY
  @@ -31,7 +32,7 @@
       FROM   DUAL;  
     END logging_event_id_seq_trig;
   
  -CREATE TABLE mdc
  +CREATE TABLE logging_event_property
     (
       event_id	      INT NOT NULL,
       mapped_key        VARCHAR(254) NOT NULL,
  
  
  
  1.7       +11 -5     logging-log4j/src/java/org/apache/log4j/varia/LogFilePatternReceiver.java
  
  Index: LogFilePatternReceiver.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/varia/LogFilePatternReceiver.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LogFilePatternReceiver.java	28 Mar 2004 10:04:31 -0000	1.6
  +++ LogFilePatternReceiver.java	10 May 2004 09:30:15 -0000	1.7
  @@ -23,6 +23,7 @@
   import org.apache.log4j.plugins.Receiver;
   import org.apache.log4j.spi.LocationInfo;
   import org.apache.log4j.spi.LoggingEvent;
  +import org.apache.log4j.spi.ThrowableInformation;
   
   import java.io.BufferedReader;
   import java.io.File;
  @@ -584,11 +585,16 @@
       properties.put(Constants.HOSTNAME_KEY, "file");
       properties.put(Constants.APPLICATION_KEY, shortFileName);
   
  -    LoggingEvent event =
  -      new LoggingEvent(
  -        logger.getName(), logger, timeStamp, levelImpl, threadName, message,
  -        null, null, exception, info, properties);
  -
  +    LoggingEvent event = new LoggingEvent();
  +    event.setLogger(logger);
  +    event.setTimeStamp(timeStamp);
  +    event.setLevel(levelImpl);
  +    event.setThreadName(threadName);
  +    event.setMessage(message);
  +    event.setThrowableInformation(new ThrowableInformation(exception));
  +    event.setLocationInformation(info);
  +    event.setProperties(properties);
  +   
       return event;
     }
   
  
  
  
  1.55      +23 -0     logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
  
  Index: LoggingEvent.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- LoggingEvent.java	10 May 2004 09:12:25 -0000	1.54
  +++ LoggingEvent.java	10 May 2004 09:30:16 -0000	1.55
  @@ -341,6 +341,18 @@
       return locationInfo;
     }
   
  +  /**
  +   * Set the location information for this logging event. 
  +   * @since 1.3
  +   */
  +  public void setLocationInformation(LocationInfo li) {
  +    if (locationInfo != null) {
  +        throw new IllegalStateException("LocationInformation has been already set.");
  +    }
  +    locationInfo = li;
  +  }
  +    
  +  
   
     /**
      * Return the level of this event.
  @@ -752,6 +764,17 @@
       }
     }
   
  +  /**
  +   * Set this event's throwable information.
  +   * @since 1.3
  +   */
  +  public void setThrowableInformation(ThrowableInformation ti) {
  +    if (throwableInfo != null) {
  +      throw new IllegalStateException("ThrowableInformation has been already set.");
  +    } else {
  +      throwableInfo = ti;
  +    }
  +  }
   
     private void readLevel(ObjectInputStream ois)
            throws java.io.IOException, ClassNotFoundException {
  
  
  
  1.3       +21 -11    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DBAppender.java	4 May 2004 10:01:59 -0000	1.2
  +++ DBAppender.java	10 May 2004 09:30:17 -0000	1.3
  @@ -80,6 +80,9 @@
   
   
     protected void append(LoggingEvent event) {
  +    Set propertiesKeys = event.getPropertyKeySet();
  +    String[] throwableStrRep = event.getThrowableStrRep();
  +    
       try {
         Connection connection = connectionSource.getConnection();
         connection.setAutoCommit(false);
  @@ -88,23 +91,26 @@
   //      timestamp         BIGINT NOT NULL,
   //      rendered_message  TEXT NOT NULL,
   //      logger_name       VARCHAR(254) NOT NULL,
  +//      level_string      VARCHAR(254) NOT NULL,
   //      ndc               TEXT,
   //      thread_name       VARCHAR(254),
   //      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, ndc, thread_name) ");
  -      sql.append(" VALUES (?, ?, ? ,?, ?, ?)");
  +      sql.append("logger_name, level_string, ndc, thread_name, flag) ");
  +      sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?)");
   
         PreparedStatement insertStatement = connection.prepareStatement(sql.toString());
         insertStatement.setLong(1, event.getSequenceNumber());
         insertStatement.setLong(2, event.getTimeStamp());
         insertStatement.setString(3, event.getRenderedMessage());
         insertStatement.setString(4, event.getLoggerName());
  -      insertStatement.setString(5, event.getNDC());
  -      insertStatement.setString(6, event.getThreadName());
  -
  +      insertStatement.setString(5, event.getLevel().toString());
  +      insertStatement.setString(6, event.getNDC());
  +      insertStatement.setString(7, event.getThreadName());
  +      insertStatement.setString(8, computeFlag(event));
  +      
         int updateCount = insertStatement.executeUpdate();
   
         if (updateCount != 1) {
  @@ -123,15 +129,14 @@
   //      event_id        INT NOT NULL,
   //      mapped_key        VARCHAR(254) NOT NULL,
   //      mapped_value      VARCHAR(254),
  -      Set mdcKeys = event.getMDCKeySet();
   
  -      if (mdcKeys.size() > 0) {
  -        String insertMDCSQL = "INSERT INTO mdc (event_id, mapped_key, mapped_value) VALUES
(?, ?, ?)";
  -        PreparedStatement insertMDCStatement = connection.prepareStatement(insertMDCSQL);
  +      if (propertiesKeys.size() > 0) {
  +        String insertPropertiesSQL = "INSERT INTO  logging_event_property (event_id, mapped_key,
mapped_value) VALUES (?, ?, ?)";
  +        PreparedStatement insertMDCStatement = connection.prepareStatement(insertPropertiesSQL);
   
  -        for (Iterator i = mdcKeys.iterator(); i.hasNext();) {
  +        for (Iterator i = propertiesKeys.iterator(); i.hasNext();) {
             String key = (String)i.next();
  -          String value = (String)event.getMDC(key);
  +          String value = (String)event.getProperty(key);
             LogLog.debug("id " + eventId + ", key " + key + ", value " + value);
             insertMDCStatement.setInt(1, eventId);
             insertMDCStatement.setString(2, key);
  @@ -148,6 +153,11 @@
     }
   
   
  +  short computeFlag(LoggingEvent event) {
  +
  +    return 0;
  +  }
  +  
     public void close() {
       // TODO Auto-generated method st  
     }
  
  
  

---------------------------------------------------------------------
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