lib/ntail/log_line.rb in ntail-1.0.0 vs lib/ntail/log_line.rb in ntail-1.0.2
- old
+ new
@@ -23,10 +23,15 @@
:body_bytes_sent, # %b
:http_referer, # %R
:http_user_agent, # %U
:proxy_addresses, # %p
+ # UPSTREAM = NGINX + ...
+
+ :upstream_response_time, # %?
+ :request_time, # %D
+
# APACHE
:server_name, # %V
# :remote_addr, # %h
:remote_log_name, # %l
@@ -73,10 +78,16 @@
#
# http://wiki.nginx.org/NginxHttpLogModule#log_format - we currently only support the default "combined" log format...
#
+ UPSTREAM_LOG_PATTERN = Regexp.compile(/\A(\S+) - (\S+) \[([^\]]+)\] "([^"]+)" (\S+) (\S+) "([^"]*?)" "([^"]*?)"( "([^"]*?)")? - ([\d]+\.[\d]+) ([\d]+\.[\d]+)\Z/)
+
+ #
+ # http://wiki.nginx.org/NginxHttpLogModule#log_format - we currently only support the default "combined" log format...
+ #
+
NGINX_LOG_PATTERN = Regexp.compile(/\A(\S+) - (\S+) \[([^\]]+)\] "([^"]+)" (\S+) (\S+) "([^"]*?)" "([^"]*?)"( "([^"]*?)")?\Z/)
#
# the actual pattern used for line matching, either nginx (default) or apache
#
@@ -84,10 +95,11 @@
@@log_pattern = NGINX_LOG_PATTERN
def self.set_pattern(pattern)
@@log_pattern = case pattern
when :nginx then NGINX_LOG_PATTERN
+ when :upstream then UPSTREAM_LOG_PATTERN
when :apache then APACHE_LOG_PATTERN
end
end
NGINX_REQUEST_PATTERN = Regexp.compile(/\A(\S+) (.*?) (\S+)\Z/)
@@ -96,9 +108,11 @@
def initialize(line, filename = nil, line_number = nil)
@filename = filename ; @line_number = line_number
@parsable = if @@log_pattern.match(@raw_line = line)
if @@log_pattern == NGINX_LOG_PATTERN
@remote_addr, @remote_user, @time_local, @request, @status, @body_bytes_sent, @http_referer, @http_user_agent, @proxy_addresses = $~.captures
+ elsif @@log_pattern == UPSTREAM_LOG_PATTERN
+ @remote_addr, @remote_user, @time_local, @request, @status, @body_bytes_sent, @http_referer, @http_user_agent, @proxy_addresses, _, @upstream_response_time, @request_time = $~.captures
elsif @@log_pattern == APACHE_LOG_PATTERN
@server_name, @remote_addr, @remote_log_name, @remote_user, @time_local, @request, @status, @body_bytes_sent, @http_referer, @http_user_agent, @http_cookie, @time_taken = $~.captures
@proxy_addresses = nil
end
if NGINX_REQUEST_PATTERN.match(@request)