Class: Racknga::AccessLogParser — racknga - Ranguba

Class: Racknga::AccessLogParser

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/racknga/access_log_parser.rb

Overview

Supported formats:

* combined (nginx's default format)
* combined (Apache's predefined format)
* combined_with_time_nginx (custom format with runtime)
* combined_with_time_apache (custom format with runtime)

Configurations:

* combined
  * nginx
    log_format combined '$remote_addr - $remote_user [$time_local]  '
                        '"$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent"';
    access_log log/access.log combined
  * Apache
    CustomLog ${APACHE_LOG_DIR}/access.log combined

* combined_with_time_nginx
  * nginx
    log_format combined_with_time '$remote_addr - $remote_user '
                                  '[$time_local, $upstream_http_x_runtime, $request_time]  '
                                  '"$request" $status $body_bytes_sent '
                                  '"$http_referer" "$http_user_agent"';
    access_log log/access.log combined_with_time

* combined_with_time_apache
  * Apache
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %{X-Runtime}o %D" combined_with_time
    CustomLog ${APACHE_LOG_DIR}/access.log combined_with_time

Direct Known Subclasses

ReversedAccessLogParser

Defined Under Namespace

Classes: FormatError

Constant Summary

REMOTE_ADDRESS =
"[^\\x20]+"
REMOTE_USER =
"[^\\x20]+"
TIME_LOCAL =
"[^\\x20]+\\x20\\+\\d{4}"
RUNTIME =
"(?:[\\d.]+|-)"
REQUEST_TIME =
"[\\d.]+"
REQUEST =
".*?"
STATUS =
"\\d{3}"
BODY_BYTES_SENT =
"(?:\\d+|-)"
HTTP_REFERER =
".*?"
HTTP_USER_AGENT =
"(?:\\\"|[^\"])*?"
COMBINED_FORMAT =
/^(#{REMOTE_ADDRESS})\x20
-\x20
(#{REMOTE_USER})\x20
\[(#{TIME_LOCAL})(?:,\x20(.+))?\]\x20+
"(#{REQUEST})"\x20
(#{STATUS})\x20
(#{BODY_BYTES_SENT})\x20
"(#{HTTP_REFERER})"\x20
"(#{HTTP_USER_AGENT})"
(?:\x20(.+))?$/x

Instance Method Summary (collapse)

Constructor Details

- (AccessLogParser) initialize(line_reader)

A new instance of AccessLogParser



58
59
60
# File 'lib/racknga/access_log_parser.rb', line 58

def initialize(line_reader)
  @line_reader = line_reader
end

Instance Method Details

- (Object) each



62
63
64
65
66
67
# File 'lib/racknga/access_log_parser.rb', line 62

def each
  @line_reader.each do |line|
    line.force_encoding("UTF-8")
    yield(parse_line(line)) if line.valid_encoding?
  end
end