org.apache.log4j.chainsaw.vfs
Class VFSLogFilePatternReceiver

java.lang.Object
  extended by org.apache.log4j.spi.ComponentBase
      extended by org.apache.log4j.plugins.PluginSkeleton
          extended by org.apache.log4j.plugins.Receiver
              extended by org.apache.log4j.varia.LogFilePatternReceiver
                  extended by org.apache.log4j.chainsaw.vfs.VFSLogFilePatternReceiver
All Implemented Interfaces:
VisualReceiver, org.apache.log4j.plugins.Plugin, org.apache.log4j.spi.Component, org.apache.log4j.spi.OptionHandler, org.apache.log4j.spi.Thresholdable

public class VFSLogFilePatternReceiver
extends org.apache.log4j.varia.LogFilePatternReceiver
implements VisualReceiver

A VFS-enabled version of org.apache.log4j.varia.LogFilePatternReceiver. VFSLogFilePatternReceiver can parse and tail log files, converting entries into LoggingEvents. If the file doesn't exist when the receiver is initialized, the receiver will look for the file once every 10 seconds.

See the Chainsaw page (http://logging.apache.org/log4j/docs/chainsaw.html) for information on how to set up Chainsaw with VFS.

See http://jakarta.apache.org/commons/vfs/filesystems.html for a list of VFS-supported file systems and the URIs needed to access the file systems.

Because some VFS file systems allow you to provide username/password, this receiver provides an optional GUI dialog for entering the username/password fields instead of requiring you to hard code usernames and passwords into the URI.

If the 'promptForUserInfo' param is set to true (default is false), the receiver will wait for a call to 'setContainer', and then display a username/password dialog.

If you are using this receiver without a GUI, don't set promptForUserInfo to true - it will block indefinitely waiting for a visual component.

If the 'promptForUserInfo' param is set to true, the fileURL should -leave out- the username/password portion of the VFS-supported URI. Examples:

An sftp URI that would be used with promptForUserInfo=true: sftp://192.168.1.100:22/home/thisuser/logfile.txt

An sftp URI that would be used with promptForUserInfo=false: sftp://username:password@192.168.1.100:22/home/thisuser/logfile.txt

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 a glob-style wildcard used to ignore fields in the log file if needed. All other fields are parsed by using the supplied keywords.

Features:
- specify the URL of the log file to be processed
- specify the timestamp format in the file (if one exists)
- specify the pattern (logFormat) used in the log file using keywords, a wildcard character (*) and fixed text
- 'tail' the file (allows the contents of the file to be continually read and new events processed)
- supports the parsing of multi-line messages and exceptions - to access

Keywords:
TIMESTAMP
LOGGER
LEVEL
THREAD
CLASS
FILE
LINE
METHOD
RELATIVETIME
MESSAGE
NDC
PROP(key)

Use a * to ignore portions of the log format that should be ignored

Example:
If your file's patternlayout is this:
%d %-5p [%t] %C{2} (%F:%L) - %m%n

specify this as the log format:
TIMESTAMP LEVEL [THREAD] CLASS (FILE:LINE) - MESSAGE

To define a PROPERTY field, use PROP(key)

Example:
If you used the RELATIVETIME pattern layout character in the file, you can use PROP(RELATIVETIME) in the logFormat definition to assign the RELATIVETIME field as a property on the event.

If your file's patternlayout is this:
%r [%t] %-5p %c %x - %m%n

specify this as the log format:
PROP(RELATIVETIME) [THREAD] LEVEL LOGGER * - MESSAGE

Note the * - it can be used to ignore a single word or sequence of words in the log file (in order for the wildcard to ignore a sequence of words, the text being ignored must be followed by some delimiter, like '-' or '[') - ndc is being ignored in this example.

Assign a filterExpression in order to only process events which match a filter. If a filterExpression is not assigned, all events are processed.

Limitations:
- no support for the single-line version of throwable supported by patternlayout
(this version of throwable will be included as the last line of the message)
- the relativetime patternLayout character must be set as a property: PROP(RELATIVETIME)
- messages should appear as the last field of the logFormat because the variability in message content
- exceptions are converted if the exception stack trace (other than the first line of the exception)
is stored in the log file with a tab followed by the word 'at' as the first characters in the line
- tailing may fail if the file rolls over.

Example receiver configuration settings (add these as params, specifying a LogFilePatternReceiver 'plugin'):
param: "timestampFormat" value="yyyy-MM-d HH:mm:ss,SSS"
param: "logFormat" value="RELATIVETIME [THREAD] LEVEL LOGGER * - MESSAGE"
param: "fileURL" value="file:///c:/events.log"
param: "tailing" value="true" param: "promptForUserInfo" value="false"

This configuration will be able to process these sample events:
710 [ Thread-0] DEBUG first.logger first - something here something else
880 [ Thread-2] DEBUG first.logger third - something here something else
880 [ Thread-0] INFO first.logger first - infomsg-0
java.lang.Exception: someexception-first
at Generator2.run(Generator2.java:102)

Author:
Scott Deboy

Nested Class Summary
 class VFSLogFilePatternReceiver.MyUserInfo
          UserInfo class used to automatically log in if needed - also implemements UIKeyboardInteractive (UserInfo methods not used, just UIKeyboardInteractive)
 class VFSLogFilePatternReceiver.UserNamePasswordDialog
           
 
Field Summary
 
Fields inherited from class org.apache.log4j.plugins.Receiver
thresholdLevel
 
Fields inherited from class org.apache.log4j.plugins.PluginSkeleton
active, name
 
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
 
Constructor Summary
VFSLogFilePatternReceiver()
           
 
Method Summary
 void activateOptions()
          Read and process the log file.
 boolean isPromptForUserInfo()
           
 void setContainer(java.awt.Container container)
          Implementation of VisualReceiver interface - allows this receiver to provide a username/password dialog.
 void setPromptForUserInfo(boolean promptForUserInfo)
          If set to true, will cause the receiver to block indefinitely until 'setContainer' has been called, at which point a username/password dialog will appear.
 void shutdown()
           
 
Methods inherited from class org.apache.log4j.varia.LogFilePatternReceiver
createPattern, getFileURL, getFilterExpression, getLogFormat, getTimestampFormat, initialize, isTailing, isUseCurrentThread, main, process, setFileURL, setFilterExpression, setHost, setLogFormat, setPath, setTailing, setTimestampFormat, setUseCurrentThread
 
Methods inherited from class org.apache.log4j.plugins.Receiver
doPost, getThreshold, isAsSevereAsThreshold, setThreshold
 
Methods inherited from class org.apache.log4j.plugins.PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, isEquivalent, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setName
 
Methods inherited from class org.apache.log4j.spi.ComponentBase
getLogger, getNonFloodingLogger, resetErrorCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VFSLogFilePatternReceiver

public VFSLogFilePatternReceiver()
Method Detail

shutdown

public void shutdown()
Specified by:
shutdown in interface org.apache.log4j.plugins.Plugin
Overrides:
shutdown in class org.apache.log4j.varia.LogFilePatternReceiver

setPromptForUserInfo

public void setPromptForUserInfo(boolean promptForUserInfo)
If set to true, will cause the receiver to block indefinitely until 'setContainer' has been called, at which point a username/password dialog will appear.

Parameters:
promptForUserInfo -

isPromptForUserInfo

public boolean isPromptForUserInfo()

setContainer

public void setContainer(java.awt.Container container)
Implementation of VisualReceiver interface - allows this receiver to provide a username/password dialog.

Specified by:
setContainer in interface VisualReceiver

activateOptions

public void activateOptions()
Read and process the log file.

Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler
Overrides:
activateOptions in class org.apache.log4j.varia.LogFilePatternReceiver


Copyright © 2007 Apache Software Foundation. All Rights Reserved.