org.polliwog
Class LogCreator

java.lang.Object
  extended by org.polliwog.LogCreator

public class LogCreator
extends java.lang.Object

Provides some utilities to handling log files. Note: it is likely that the methods in this class will be split into separate tools.

 Last Modified By: $Author: barrygently $
 Last Modified On: $Date: 2005/07/04 14:00:00 $
 Current Revision: $Revision: 1.6 $
 


Field Summary
static java.lang.String DEFAULT_PAGE_EXTENSIONS
          Defines a set of default page extensions.
static java.lang.String MONTH
          Defines a value to be used in the splitLog(File,File,String,File,String) method to split the log file by months.
static java.lang.String TXT
           
 
Constructor Summary
LogCreator()
           
 
Method Summary
static void createSubLog(java.io.File logFile, java.io.File configFile, java.util.Date from, java.util.Date to, java.io.File outputFile)
          Create a sub-log file from the parent log file for entries between the particular dates.
static Weblog createWeblog(java.io.File logFile, java.io.File configFile)
          Create a new instance of Weblog from the specified logfile with the specified log spec (defined in configFile).
static Weblog createWeblog(java.io.File logFile, java.io.File configFile, int lineCount)
          Create a new instance of Weblog from the specified logfile with the specified log spec (defined in configFile) and limit to the specified number of lines (lineCount).
static int cycleOverLog(java.io.File logFile, java.io.File configFile, LogEntryListener lel, java.lang.Class cl)
          Cycle over the specified logFile and for each entry in the log create an instance of cl (which must be an extend LogEntry), this entry is then passed to lel via the LogEntryListener.processEntry(LogEntry) method.
static void splitLog(java.io.File logFile, java.io.File configFile, java.lang.String by, java.io.File outputDir, java.lang.String fileExt)
          Split a log file in a particular way.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAGE_EXTENSIONS

public static final java.lang.String DEFAULT_PAGE_EXTENSIONS
Defines a set of default page extensions.

See Also:
Constant Field Values

MONTH

public static final java.lang.String MONTH
Defines a value to be used in the splitLog(File,File,String,File,String) method to split the log file by months.

See Also:
Constant Field Values

TXT

public static final java.lang.String TXT
See Also:
Constant Field Values
Constructor Detail

LogCreator

public LogCreator()
Method Detail

splitLog

public static void splitLog(java.io.File logFile,
                            java.io.File configFile,
                            java.lang.String by,
                            java.io.File outputDir,
                            java.lang.String fileExt)
                     throws java.io.IOException,
                            WeblogException,
                            org.jdom.JDOMException
Split a log file in a particular way. Currently this method only supports a by value of MONTH. It should be noted that: The name of the output file will be: "MMM-yy.fileExt". Also, lines starting with # or lengths that are empty are ignored.

Parameters:
logFile - The log file that should be split.
configFile - The file (xml format) that contains the log spec.
by - Should be MONTH.
outputDir - The directory where the separate logs should be created. If the directory does not exist then it is created.
fileExt - The file extension to give the split logs.
Throws:
java.io.IOException - If logFile or configFile do not exist, or if the logFile cannot be read.
WeblogException - If something goes wrong with reading a log entry and/or converting it to a Java representation.
org.jdom.JDOMException - If there is a problem with the XML format of configFile.
See Also:
LogEntryFormat, Hit

createSubLog

public static void createSubLog(java.io.File logFile,
                                java.io.File configFile,
                                java.util.Date from,
                                java.util.Date to,
                                java.io.File outputFile)
                         throws java.io.IOException,
                                WeblogException,
                                org.jdom.JDOMException
Create a sub-log file from the parent log file for entries between the particular dates. It should be noted that: The name of the output file will be: "MMM-yy.fileExt". Also, lines starting with # or lengths that are empty are ignored.

Parameters:
logFile - The log file that should be split.
configFile - The file (xml format) that contains the log spec.
from - The start date.
to - The end date.
outputFile - The file to write the sub-log to. The file is overwritten if it already exists.
Throws:
java.io.IOException - If logFile or configFile do not exist, or if the logFile cannot be read.
WeblogException - If something goes wrong with reading a log entry and/or converting it to a Java representation.
org.jdom.JDOMException - If there is a problem with the XML format of configFile.
See Also:
LogEntryFormat, Hit

createWeblog

public static Weblog createWeblog(java.io.File logFile,
                                  java.io.File configFile)
                           throws java.io.IOException,
                                  WeblogException,
                                  org.jdom.JDOMException
Create a new instance of Weblog from the specified logfile with the specified log spec (defined in configFile). The Weblog is created using the default page extensions DEFAULT_PAGE_EXTENSIONS. For each Hit created it is added to the Weblog via a call to: Weblog.addToStats(Hit). It should be noted that this method DOES NOT add the entry to the log, it only increments the statistics.

Parameters:
logFile - The log file.
configFile - The file (xml format) that contains the log spec.
Throws:
java.io.IOException - If the log file or config file cannot be found or read.
WeblogException - If the log entries cannot be converted to a Hit.
org.jdom.JDOMException - If the configFile XML format is invalid.
See Also:
LogEntryFormat, Hit, Weblog

createWeblog

public static Weblog createWeblog(java.io.File logFile,
                                  java.io.File configFile,
                                  int lineCount)
                           throws java.io.IOException,
                                  WeblogException,
                                  org.jdom.JDOMException
Create a new instance of Weblog from the specified logfile with the specified log spec (defined in configFile) and limit to the specified number of lines (lineCount). The Weblog is created using the default page extensions DEFAULT_PAGE_EXTENSIONS. For each Hit created it is added to the Weblog via a call to: Weblog.addHit(Hit). This means that the Weblog created could be VERY large, use this method with care.

Parameters:
logFile - The log file.
configFile - The file (xml format) that contains the log spec.
lineCount - Limit the number of entries added to the specified number, set to -1 to add all.
Throws:
java.io.IOException - If the log file or config file cannot be found or read.
WeblogException - If the log entries cannot be converted to a Hit.
org.jdom.JDOMException - If the configFile XML format is invalid.
See Also:
LogEntryFormat, Hit, Weblog

cycleOverLog

public static int cycleOverLog(java.io.File logFile,
                               java.io.File configFile,
                               LogEntryListener lel,
                               java.lang.Class cl)
                        throws java.io.IOException,
                               WeblogException,
                               org.jdom.JDOMException
Cycle over the specified logFile and for each entry in the log create an instance of cl (which must be an extend LogEntry), this entry is then passed to lel via the LogEntryListener.processEntry(LogEntry) method.

Parameters:
logFile - The log file.
configFile - The file (xml format) that contains the log spec.
lel - The LogEntryListener that is used to process the entry.
cl - The class created as a LogEntry.
Throws:
java.io.IOException - If the log file or config file cannot be found or read.
WeblogException - If the log entries cannot be converted to a Hit.
org.jdom.JDOMException - If the configFile XML format is invalid.
See Also:
LogEntryFormat, Hit, LogEntry, Log, Weblog


  Copyright © 2007 Gary Bentley. All Rights Reserved.