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/dialect postgresql.sql mysql.sql
Date Wed, 12 May 2004 13:21:41 GMT
ceki        2004/05/12 06:21:41

  Modified:    src/java/org/apache/log4j/db DBReceiver.java DBAppender.java
               src/java/org/apache/log4j/db/dialect postgresql.sql
                        mysql.sql
  Log:
  renamed id as event_id
  
  Revision  Changes    Path
  1.2       +36 -8     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DBReceiver.java	10 May 2004 19:38:58 -0000	1.1
  +++ DBReceiver.java	12 May 2004 13:21:41 -0000	1.2
  @@ -22,11 +22,13 @@
   import java.sql.Statement;
   
   import org.apache.log4j.Level;
  +import org.apache.log4j.LogManager;
   import org.apache.log4j.Logger;
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.plugins.Pauseable;
   import org.apache.log4j.plugins.Receiver;
   import org.apache.log4j.scheduler.Job;
  +import org.apache.log4j.scheduler.Scheduler;
   import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.LoggingEvent;
   import org.apache.log4j.spi.ThrowableInformation;
  @@ -41,8 +43,15 @@
   public class DBReceiver
          extends Receiver
          implements Pauseable {
  +  
  +  /**
  +   * By default we refresh data every 1000 milliseconds.
  +   * @see #setRefreshMillis
  +   */
  +  static int DEFAULT_REFRESH_MILLIS = 1000;
  +  
     ConnectionSource connectionSource;
  -  int refreshMillis;
  +  int refreshMillis = DEFAULT_REFRESH_MILLIS;
     DBReceiverJob receiverJob;
     boolean paused = false;
     
  @@ -51,6 +60,9 @@
         LogLog.info("activating connectionSource");
         connectionSource.activateOptions();
         receiverJob = new DBReceiverJob();
  +      Scheduler scheduler = LogManager.getSchedulerInstance();
  +      scheduler.schedule(receiverJob, System.currentTimeMillis()+500, refreshMillis);
  +      
       } else {
         throw new IllegalStateException("DBAppender cannot function without a connection
source");
       }
  @@ -87,7 +99,9 @@
      * @see org.apache.log4j.plugins.Plugin#shutdown()
      */
     public void shutdown() {
  -    // TODO Auto-generated method stub
  +    LogLog.info("removing receiverJob from the Scheduler.");
  +    Scheduler scheduler = LogManager.getSchedulerInstance();
  +    scheduler.delete(receiverJob);
     }
   
   
  @@ -105,10 +119,19 @@
       return paused;
     }
   
  -  class DBReceiverJob
  -         implements Job {
  +  /**
  +   * Actual retrieval of data is made by the instance of DBReceiverJob associated
  +   * with DBReceiver.
  +   * 
  +   * @author Ceki Gülcü
  +   */
  +  class DBReceiverJob implements Job {
  +    
  +    long lastId = 0;
  +    
  +   
       public void execute() {
  -      LogLog.info("in DBReceiverJob.execute()");
  +      LogLog.info("DBReceiverJob.execute() called");
         try {
           Logger logger;
           LoggerRepository loggerRepository = getLoggerRepository();
  @@ -116,8 +139,11 @@
           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, id from logging_event");
  -
  +        sql.append("reference_flag, event_id 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");
  +        
           Statement statement = connection.createStatement();
           ResultSet rs = statement.executeQuery(sql.toString());
           rs.first();
  @@ -141,7 +167,8 @@
             short mask = rs.getShort(8);
   
             id = rs.getLong(9);
  -
  +          lastId = id;
  +          
             //event.setProperty("id", Long.toString(id));
             if ((mask & DBHelper.PROPERTIES_EXIST) != 0) {
               getProperties(connection, id, event);
  @@ -154,6 +181,7 @@
             if (! DBReceiver.this.isPaused()) {
               DBReceiver.this.doPost(event);
             }
  +          
           }
         } catch (SQLException sqle) {
           LogLog.error("Problem receiving events", sqle);
  
  
  
  1.6       +1 -1      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DBAppender.java	10 May 2004 17:26:58 -0000	1.5
  +++ DBAppender.java	12 May 2004 13:21:41 -0000	1.6
  @@ -122,7 +122,7 @@
         rs.first();
   
         int eventId = rs.getInt(1);
  -      LogLog.info("inserted id is " + eventId);
  +//      LogLog.info("inserted id is " + eventId);
   
   //      event_id        INT NOT NULL,
   //      mapped_key        VARCHAR(254) NOT NULL,
  
  
  
  1.5       +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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- postgresql.sql	10 May 2004 17:26:58 -0000	1.4
  +++ postgresql.sql	12 May 2004 13:21:41 -0000	1.5
  @@ -20,7 +20,7 @@
       ndc               TEXT,
       thread_name       VARCHAR(254),
       reference_flag    SMALLINT,
  -    id                INT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY
  +    event_id          INT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY
     );
   
   CREATE TABLE logging_event_property
  
  
  
  1.5       +1 -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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- mysql.sql	10 May 2004 17:26:58 -0000	1.4
  +++ mysql.sql	12 May 2004 13:21:41 -0000	1.5
  @@ -23,7 +23,7 @@
       ndc               TEXT,
       thread_name       VARCHAR(254),
       reference_flag    SMALLINT,
  -    id                INT NOT NULL AUTO_INCREMENT PRIMARY KEY
  +    event_id          INT NOT NULL AUTO_INCREMENT PRIMARY KEY
     );
   COMMIT;
   
  
  
  

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