sdeboy      2004/12/09 23:05:24

  Modified:    src/java/org/apache/log4j/varia LogFilePatternReceiver.java
  Log:
  If the file doesn't exist when the receiver is initialized, the receiver will 
look for the file once every 10 seconds.
  
  Revision  Changes    Path
  1.23      +20 -7     
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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- LogFilePatternReceiver.java       9 Dec 2004 09:08:55 -0000       1.22
  +++ LogFilePatternReceiver.java       10 Dec 2004 07:05:24 -0000      1.23
  @@ -17,6 +17,7 @@
   package org.apache.log4j.varia;
   
   import java.io.BufferedReader;
  +import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.InputStreamReader;
   import java.io.Reader;
  @@ -49,7 +50,8 @@
   
   /**
    * LogFilePatternReceiver can parse and tail log files, converting entries 
into
  - * LoggingEvents.
  + * LoggingEvents.  If the file doesn't exist when the receiver is 
initialized, the
  + * receiver will look for the file once every 10 seconds.
    * <p>
    * This receiver relies on ORO Perl5 features to perform the parsing of text 
in the 
    * log file, however the only regular expression field explicitly supported 
is 
  @@ -754,6 +756,7 @@
       try {
         if (reader != null) {
           reader.close();
  +        reader = null;
         }
       } catch (IOException ioe) {
         ioe.printStackTrace();
  @@ -767,12 +770,22 @@
       new Thread(new Runnable() {
         public void run() {
           initialize();
  -        try {
  -          reader = new InputStreamReader(new URL(getFileURL()).openStream());
  -        } catch (IOException ioe) {
  -          getLogger().warn("exception", ioe);
  -          return;
  -        }
  +        while (reader == null) {
  +          getLogger().info("attempting to load file: " + getFileURL());
  +             try {
  +               reader = new InputStreamReader(new 
URL(getFileURL()).openStream());
  +             } catch (FileNotFoundException fnfe) {
  +               getLogger().info("file not available - will try again in 10 
seconds");
  +               synchronized(this) {
  +                 try {
  +                   wait(10000);
  +                 } catch (InterruptedException ie){}
  +               }
  +             } catch (IOException ioe) {
  +               getLogger().warn("unable to load file", ioe);
  +               return;
  +             }
  +        } 
           try {
             process(reader);
           } catch (IOException ioe) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to