be.unamur.inference.web.apache
Class ApacheLogFormatPatternBuilder

java.lang.Object
  extended by be.unamur.inference.web.apache.ApacheLogFormatPatternBuilder

public class ApacheLogFormatPatternBuilder
extends Object

This class is used to generate regular expression Patterns to parse Apache web log entries. The patterns are built using groups names by the different static Strings declared in this class. The usage of this class is to get the singleton instance using getInstance() method and to call the buildPattern method on this object using one of the constants defining a format: COMMON_LOG_FORMAT, COMBINED_LOG_FORMAT, REQUEST_FORMAT, or DATE_FORMAT. The returned Pattern is used to match a given string and the resulting Matcher object may return the different groups of the used pattern using the names defined in the _DIRECTIVE constants (see http://httpd.apache.org/docs/ for the different log formats). Example:

 {
        @code
        Pattern pattern = getInstance().buildPattern(COMMON_LOG_FORMAT);
        Matcher match = pattern.matcher(logLine);
        String request = match.group(REQUEST_DIRECTIVE);
        String host = match.group(HOST_DIRECTIVE);
 }
 

Author:
Xavier Devroey - xavier.devroey@unamur.be

Field Summary
static String COMBINED_LOG_FORMAT
          The combined Apache web log format regular expression.
static String COMMON_LOG_FORMAT
          The common Apache web log format regular expression.
static String DATE_FORMAT
          Date format used in Apache logs.
static Locale DATE_LOCALE
          The Locale value used in the dates of the log.
static String HOST_DIRECTIVE
          The host directive group name.
static String IDENTITY_DIRECTIVE
          The identity directive group name.
static String REFERRER_DIRECTIVE
          The referrer directive group name.
static String REQUEST_DIRECTIVE
          The request directive groupe name.
static String REQUEST_FORMAT
          The Apache request format regular expression.
static String REQUEST_METHOD_DIRECTIVE
          The request method directive group name.
static String REQUEST_PROTOCOL_DIRECTIVE
          The request protocole directive group name.
static String REQUEST_QUERY_PARAMETERS_DIRECTIVE
          The request query parameters directive group name.
static String REQUEST_QUERY_PATH_DIRECTIVE
          The request query path directive group name.
static String SIZE_DIRECTIVE
          The size directive group name.
static String STATUS_CODE_DIRECTIVE
          The status code directive group name.
static String TIME_DIRECTIVE
          The time directive group name.
static String USER_AGENT_DIRECTIVE
          The user agent directive group name.
static String USER_DIRECTIVE
          The user directive group name.
 
Method Summary
 com.google.code.regexp.Pattern buildPattern(String format)
          Return a pattern corresponding to the given regular expression string.
static ApacheLogFormatPatternBuilder getInstance()
          Return the instance of this singleton class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOST_DIRECTIVE

public static final String HOST_DIRECTIVE
The host directive group name.

See Also:
Constant Field Values

IDENTITY_DIRECTIVE

public static final String IDENTITY_DIRECTIVE
The identity directive group name.

See Also:
Constant Field Values

USER_DIRECTIVE

public static final String USER_DIRECTIVE
The user directive group name.

See Also:
Constant Field Values

TIME_DIRECTIVE

public static final String TIME_DIRECTIVE
The time directive group name.

See Also:
Constant Field Values

REQUEST_DIRECTIVE

public static final String REQUEST_DIRECTIVE
The request directive groupe name.

See Also:
Constant Field Values

STATUS_CODE_DIRECTIVE

public static final String STATUS_CODE_DIRECTIVE
The status code directive group name.

See Also:
Constant Field Values

SIZE_DIRECTIVE

public static final String SIZE_DIRECTIVE
The size directive group name.

See Also:
Constant Field Values

REFERRER_DIRECTIVE

public static final String REFERRER_DIRECTIVE
The referrer directive group name.

See Also:
Constant Field Values

USER_AGENT_DIRECTIVE

public static final String USER_AGENT_DIRECTIVE
The user agent directive group name.

See Also:
Constant Field Values

REQUEST_METHOD_DIRECTIVE

public static final String REQUEST_METHOD_DIRECTIVE
The request method directive group name.

See Also:
Constant Field Values

REQUEST_QUERY_PATH_DIRECTIVE

public static final String REQUEST_QUERY_PATH_DIRECTIVE
The request query path directive group name.

See Also:
Constant Field Values

REQUEST_QUERY_PARAMETERS_DIRECTIVE

public static final String REQUEST_QUERY_PARAMETERS_DIRECTIVE
The request query parameters directive group name.

See Also:
Constant Field Values

REQUEST_PROTOCOL_DIRECTIVE

public static final String REQUEST_PROTOCOL_DIRECTIVE
The request protocole directive group name.

See Also:
Constant Field Values

COMMON_LOG_FORMAT

public static final String COMMON_LOG_FORMAT
The common Apache web log format regular expression.


COMBINED_LOG_FORMAT

public static final String COMBINED_LOG_FORMAT
The combined Apache web log format regular expression.


REQUEST_FORMAT

public static final String REQUEST_FORMAT
The Apache request format regular expression.


DATE_FORMAT

public static final String DATE_FORMAT
Date format used in Apache logs.

See Also:
Constant Field Values

DATE_LOCALE

public static final Locale DATE_LOCALE
The Locale value used in the dates of the log. This value has to be provided to DateParser objects.

Method Detail

getInstance

public static ApacheLogFormatPatternBuilder getInstance()
Return the instance of this singleton class.


buildPattern

public com.google.code.regexp.Pattern buildPattern(String format)
Return a pattern corresponding to the given regular expression string.

Parameters:
format - The format of the regular expression.
Returns:
A Pattern corresponding tot the given regular expression string.


Copyright © 2014 PReCISE, University of Namur. All rights reserved.