ApacheLogAnalyzer2Feed
[ class tree: ApacheLogAnalyzer2Feed ] [ index: ApacheLogAnalyzer2Feed ] [ all elements ]

Class: ApacheLogAnalyzer2Feed

Source Location: /ApacheLogAnalyzer2Feed.php

Class Overview


ApacheLogAnalyzer2Feed


Author(s):

Version:

  • SVN: $Id$

Copyright:

  • 2007 The Authors

Variables

Constants

Methods



Class Details

[line 68]
ApacheLogAnalyzer2Feed

ApacheLogAnalyzer2Feed is a really powerful class to analyze Apache Web Server log files. Analysis results are converted into a feed to let users subscribe with a feed reader.

Each log file can be analyzed/filtered with a filter chain based on log data. For instance, you can select only rows where IP is 123.123.123.123, user agent contains the word 'GoogleBot' (regular expression pattern), request is made for page 'mt-search.cgi' and so on.

You can appen how many filter you need and run log parsing.

Results are converted into a feed. The feed can be generated on the fly or stored into a static XML file (recommended).

This class is extensible. You can extends it via PHP5 object oriented architecture. For instance, you can adds more filter callbacks or change feed generator handler.




Tags:

author:  Simone Carletti <weppos@weppos.net>
version:  SVN: $Id$
copyright:  2007 The Authors
link:  http://www.simonecarletti.com/code/sesit2007 ApacheLogAnalyzer2Feed Site
license:  LGPL License 2.1


[ Top ]


Class Variables

$_apacheLogParser =  null

[line 172]

ApacheLogParser instance



Tags:

access:  protected

Type:   ApacheLogParser


[ Top ]

$_fileIterator =  null

[line 164]

FileIterator instance



Tags:

access:  protected

Type:   FileIterator


[ Top ]

$_filterCallback =  self::FILTER_MODE_AND

[line 139]

Log filter callback function



Tags:

access:  protected

Type:   string


[ Top ]

$_filters = array()

[line 131]

Log filters



Tags:

access:  protected

Type:   array


[ Top ]

$_logFormat =  null

[line 148]

Apache Log Format



Tags:


Type:   null|string


[ Top ]

$_logLimit =  100000

[line 156]

Log limit, the maximum nuber of rows to be processes



Tags:

access:  protected

Type:   int


[ Top ]

$_source =

[line 115]

Path to source log file



Tags:

access:  protected

Type:   string


[ Top ]

$_target =  null

[line 123]

Path to target file



Tags:

access:  protected

Type:   null|string


[ Top ]



Class Methods


constructor __construct [line 185]

ApacheLogAnalyzer2Feed __construct( string $source, [null|string $target = null], [null|string $logFormat = null])

ApacheLogAnalyzer2Feed constructor

This constructor uses internal functions to sets given arguments. Please note that some of these functions may throw an exception.




Tags:

access:  public


Parameters:

string   $source  
null|string   $target  
null|string   $logFormat  

[ Top ]

method addFilter [line 200]

void addFilter( string $field, string $value, [string $comparison = null])

Add a new filter



Tags:

access:  public


Parameters:

string   $field  
string   $value  
string   $comparison  

[ Top ]

method getFilters [line 214]

mixed getFilters( null|string $index)

Returns log filters



Tags:

access:  public


Parameters:

null|string   $index  

[ Top ]

method getLogFormat [line 229]

string getLogFormat( )

Returns log format



Tags:

access:  public


[ Top ]

method getLogLimit [line 239]

int getLogLimit( )

Returns log limit



Tags:

access:  public


[ Top ]

method getSource [line 249]

string getSource( )

Returns log source filename



Tags:

access:  public


[ Top ]

method getTarget [line 259]

null|string getTarget( )

Returns target filename



Tags:

access:  public


[ Top ]

method run [line 269]

void run( )

Run parse/filter/generation batch



Tags:

access:  public


[ Top ]

method setFilterCallback [line 355]

void setFilterCallback( string $callback)

Sets filter callback function



Tags:

throws:  Exception
access:  public


Parameters:

string   $callback  

[ Top ]

method setLogFormat [line 311]

void setLogFormat( string $format)

Sets Apache Log formats

The log format is one of the most important thing to bear in mind when using this tool. If the log format is invalid the parser will not be able to analyze log data.




Tags:

access:  public


Parameters:

string   $format  

[ Top ]

method setLogLimit [line 323]

void setLogLimit( int $limit)

Sets log limit



Tags:

throws:  Exception
access:  public


Parameters:

int   $limit  

[ Top ]

method setSource [line 340]

void setSource( string $fileName)

Sets source log file



Tags:

throws:  Exception
access:  public


Parameters:

string   $fileName  

[ Top ]

method setTarget [line 369]

void setTarget( string $fileName)

Sets target file



Tags:

access:  public


Parameters:

string   $fileName  

[ Top ]

method _addFeedItem [line 586]

void _addFeedItem( mixed $feedHandler, array $data)

Append a feed item to current feed handler

This method can easily be extended with a custom feed handler.




Tags:

access:  protected


Parameters:

mixed   $feedHandler  
array   $data  

[ Top ]

method _displayFeed [line 630]

void _displayFeed( mixed $feedHandler)

Prints out the feed

This method can easily be extended with a custom feed handler.




Tags:

access:  protected


Parameters:

mixed   $feedHandler  

[ Top ]

method _generateItemHash [line 385]

string _generateItemHash( string $data)

Generates an unique hash for a single item

This function is useful to generate an unique log row identifier. Can be used, for example, to compose feed item GUID string.




Tags:

return:  Unique hash
access:  protected


Parameters:

string   $data  

[ Top ]

method _getApacheLogParser [line 416]

ApacheLogParser _getApacheLogParser( )

Returns ApacheLogParser instance



Tags:

return:  ApacheLogParser instance
access:  protected


[ Top ]

method _getFeedHandler [line 558]

mixed _getFeedHandler( )

Create and returns a feed handler

This method can easily be extended with a custom feed handler.




Tags:

return:  Feed handler instance/reference
access:  protected


[ Top ]

method _getFileIterator [line 396]

FileIterator _getFileIterator( )

Returns FileIterator instance



Tags:

return:  FileIterator instance
access:  protected


[ Top ]

method _getFilterMethodName [line 438]

string _getFilterMethodName( )

Returns filter method name to be called according to filter mode.



Tags:

access:  protected


[ Top ]

method _saveFeed [line 616]

void _saveFeed( mixed $feedHandler)

Creates the feed and saves it

This method can easily be extended with a custom feed handler.




Tags:

access:  protected


Parameters:

mixed   $feedHandler  

[ Top ]

method _testFilter [line 461]

bool _testFilter( array $parsedLogData, array $filter)

Tests current log row against a single filter

This method currently tests only a simple string or regexp pattern.




Tags:

throws:  Exception
access:  protected


Parameters:

array   $parsedLogData  
array   $filter  

[ Top ]

method _testFiltersModeAnd [line 532]

bool _testFiltersModeAnd( array $parsedLogData, int $filterIndex)

Tests current log row against all given filters.

Filters are joined according to AND logic operator.




Tags:

return:  TRUE if any filter returned TRUE, FALSE otherwise.
internal:  Need to be improved for huge log files
access:  protected


Parameters:

array   $parsedLogData  
int   $filterIndex  

[ Top ]

method _testFiltersModeOr [line 503]

bool _testFiltersModeOr( array $parsedLogData)

Tests current log row against all given filters.

Filters are joined according to OR logic operator.




Tags:

return:  TRUE if at least one filter returned TRUE, FALSE otherwise.
internal:  Need to be improved for huge log files
access:  protected


Parameters:

array   $parsedLogData  

[ Top ]


Class Constants

AUTHOR =  'Simone Carletti <weppos@weppos.net>'

[line 94]

Author


[ Top ]

BUILD =  '$Rev$'

[line 100]

Build


[ Top ]

COMPARISON_IS =  'IS'

[line 76]

X == Y


[ Top ]

COMPARISON_ISNOT =  'ISNOT'

[line 78]

X != Y


[ Top ]

COMPARISON_LIKE =  'INC'

[line 80]

X includes Y


[ Top ]

COMPARISON_NOTLIKE =  'EXC'

[line 82]

X doesn't include Y


[ Top ]

FILTER_MODE_AND =  '_testFiltersModeAnd'

[line 71]

AND mode


[ Top ]

FILTER_MODE_OR =  '_testFiltersModeOr'

[line 73]

OR mode


[ Top ]

ID =  '$Id$'

[line 103]

SVN ID


[ Top ]

LOG_FORMAT_COMBINED =  '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"'

[line 87]

Combined Apache Log Format


[ Top ]

LOG_FORMAT_COMMON =  '%h %l %u %t \"%r\" %>s %b'

[line 85]

Common Apache Log Format


[ Top ]

NAME =  'ApacheLogAnalyzer2Feed'

[line 90]

Name


[ Top ]

PACKAGE =  'Tools'

[line 92]

Package


[ Top ]

STATUS =  'beta'

[line 98]

Status


[ Top ]

SVN_DATE =  '$Date$'

[line 107]

SVN Date


[ Top ]

SVN_REVISION =  '$Rev$'

[line 105]

SVN Revision


[ Top ]

VERSION =  '0.1.0'

[line 96]

Version


[ Top ]



Documentation generated on Mon, 28 May 2007 16:14:31 +0200 by phpDocumentor 1.3.2