logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r774218 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs: VFSLogFilePatternReceiver.java VFSLogFilePatternReceiverBeanInfo.java
Date Wed, 13 May 2009 05:54:49 GMT
Author: sdeboy
Date: Wed May 13 05:54:49 2009
New Revision: 774218

URL: http://svn.apache.org/viewvc?rev=774218&view=rev
Log:
Added two new parameters to LogFilePatternReceiver:
 - waitmillis (configurable delay between checks for updates to a file - used when tailing=true)
 - appendNonMatches (if true, append non-matching lines to the log, associated with the logger
'Unknown')

Added one new parameter to VFSLogFilePatternReceiver (extends LogFilePatternReceiver, so it

inherits the waitMillis and appendNonMatches params): 
 - autoReconnect (if true, when a file is truncated, begin processing the file contents from
the beginning of the file - supports continuous tailing of a file even when the file is recreated)
 

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiver.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiverBeanInfo.java

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiver.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiver.java?rev=774218&r1=774217&r2=774218&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiver.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiver.java
Wed May 13 05:54:49 2009
@@ -38,6 +38,9 @@
 import javax.swing.JTextField;
 import javax.swing.SwingUtilities;
 
+import com.jcraft.jsch.UIKeyboardInteractive;
+import com.jcraft.jsch.UserInfo;
+
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileSystemManager;
@@ -50,9 +53,6 @@
 import org.apache.log4j.chainsaw.receivers.VisualReceiver;
 import org.apache.log4j.varia.LogFilePatternReceiver;
 
-import com.jcraft.jsch.UIKeyboardInteractive;
-import com.jcraft.jsch.UserInfo;
-
 /**
  * A VFS-enabled version of org.apache.log4j.varia.LogFilePatternReceiver.
  * 
@@ -174,8 +174,9 @@
   private Container container;
   private Object waitForContainerLock = new Object();
   private String password;
-  
-  public VFSLogFilePatternReceiver() {
+  private boolean autoReconnect;
+
+    public VFSLogFilePatternReceiver() {
     super();
   }
 
@@ -205,6 +206,22 @@
 	  return promptForUserInfo;
   }
 
+    /**
+     * Accessor
+     * @return
+     */
+    public boolean isAutoReconnect() {
+      return autoReconnect;
+    }
+
+    /**
+     * Mutator
+     * @param autoReconnect
+     */
+    public void setAutoReconnect(boolean autoReconnect) {
+        this.autoReconnect = autoReconnect;
+    }
+
   /**
    * Implementation of VisualReceiver interface - allows this receiver to provide
    * a username/password dialog.
@@ -334,63 +351,80 @@
                     getLogger().info("file not available - may be due to incorrect credentials,
but will re-attempt to load in 10 seconds", fse);
                     synchronized (this) {
                         try {
-                            wait(10000);
+                            wait(MISSING_FILE_RETRY_MILLIS);
                         } catch (InterruptedException ie) {}
                     }
                 }
             }
             initialize();
 
-            try {
+
+            do {
                 long lastFilePointer = 0;
                 long lastFileSize = 0;
                 BufferedReader bufferedReader;
                 createPattern();
                 getLogger().debug("tailing file: " + isTailing());
+                try {
+                    do {
+                        FileSystemManager fileSystemManager = VFS.getManager();
+                        FileSystemOptions opts = new FileSystemOptions();
+                        //if jsch not in classpath, can get NoClassDefFoundError here
+                        try {
+                            SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts,
"no");
+                            SftpFileSystemConfigBuilder.getInstance().setUserInfo(opts, new
MyUserInfo(password));
+                        } catch (NoClassDefFoundError ncdfe) {
+                            getLogger().warn("JSch not on classpath!", ncdfe);
+                        }
 
-                do {
-                    FileSystemManager fileSystemManager = VFS.getManager();
-                    FileSystemOptions opts = new FileSystemOptions();
-                    //if jsch not in classpath, can get NoClassDefFoundError here
-                    try {
-                    	SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts,
"no");
-                    	SftpFileSystemConfigBuilder.getInstance().setUserInfo(opts, new MyUserInfo(password));
-                    } catch (NoClassDefFoundError ncdfe) {
-                    	getLogger().warn("JSch not on classpath!", ncdfe);
-                    }
-
-                    fileObject = fileSystemManager.resolveFile(getFileURL(), opts);
-                    reader = new InputStreamReader(fileObject.getContent().getInputStream());
+                        fileObject = fileSystemManager.resolveFile(getFileURL(), opts);
+                        reader = new InputStreamReader(fileObject.getContent().getInputStream());
+                        //could have been truncated or appended to
+                        if (fileObject.getContent().getSize() < lastFileSize) {
+                            lastFileSize = 0; //seek to beginning of file
+                            lastFilePointer = 0; 
+                        }
+                        if (fileObject.getContent().getSize() > lastFileSize) {
+                            RandomAccessContent rac = fileObject.getContent().getRandomAccessContent(RandomAccessMode.READ);
+                            reader = new InputStreamReader(rac.getInputStream());
+                            bufferedReader = new BufferedReader(reader);
+                            rac.seek(lastFilePointer);
+                            process(bufferedReader);
+                            lastFilePointer = rac.getFilePointer();
+                            lastFileSize = fileObject.getContent().getSize();
+                            rac.close();
+                        }
 
-                    if (fileObject.getContent().getSize() > lastFileSize) {
-                        RandomAccessContent rac = fileObject.getContent().getRandomAccessContent(RandomAccessMode.READ);
-                        rac.seek(lastFilePointer);
-                        reader = new InputStreamReader(rac.getInputStream());
-                        bufferedReader = new BufferedReader(reader);
-                        process(bufferedReader);
-                        lastFilePointer = rac.getFilePointer();
-                        lastFileSize = fileObject.getContent().getSize();
-                        rac.close();
-                    }
+                        try {
+                            synchronized (this) {
+                                wait(getWaitMillis());
+                            }
+                        } catch (InterruptedException ie) {
+                        }
+                        try {
+                            //available in vfs as of 30 Mar 2006 - will load but not tail
if not available
+                            fileObject.refresh();
+                        } catch (Error err) {
+                            getLogger().info("Unable to refresh fileobject", err);
+                        }
 
+                    } while (isTailing());
+                } catch (IOException ioe) {
+                    getLogger().info("stream closed", ioe);
                     try {
-                        synchronized (this) {
-                            wait(5000);
+                        if (fileObject != null) {
+                            fileObject.close();
                         }
-                    } catch (InterruptedException ie) {
+                    } catch (FileSystemException e) {
+                        e.printStackTrace();
                     }
                     try {
-                    	//available in vfs as of 30 Mar 2006 - will load but not tail if not
available
-                    	fileObject.refresh();
-                    } catch (Error err) {
-                    	getLogger().info("Unable to refresh fileobject", err);
-                    }
-
-                } while (isTailing());
-
-            } catch (IOException ioe) {
-                getLogger().info("stream closed", ioe);
-            }
+                        synchronized(this) {
+                            wait(getWaitMillis());
+                        }
+                    } catch (InterruptedException ie) {}
+                }
+            } while (isAutoReconnect());
             getLogger().debug("processing complete");
             shutdown();
         }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiverBeanInfo.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiverBeanInfo.java?rev=774218&r1=774217&r2=774218&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiverBeanInfo.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiverBeanInfo.java
Wed May 13 05:54:49 2009
@@ -38,6 +38,9 @@
         new PropertyDescriptor("logFormat", VFSLogFilePatternReceiver.class),
         new PropertyDescriptor("name", VFSLogFilePatternReceiver.class),
         new PropertyDescriptor("tailing", VFSLogFilePatternReceiver.class),
+        new PropertyDescriptor("autoReconnect", VFSLogFilePatternReceiver.class),
+        new PropertyDescriptor("waitMillis", VFSLogFilePatternReceiver.class),
+        new PropertyDescriptor("appendNonMatches", VFSLogFilePatternReceiver.class),
         new PropertyDescriptor(
           "filterExpression", VFSLogFilePatternReceiver.class),
           new PropertyDescriptor(



Mime
View raw message