class NginxTail::LogLine
Constants
- APACHE_LOG_PATTERN
httpd.apache.org/docs/2.0/mod/mod_log_config.html - we currently only support the following custom log format…
“%V %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i" "%{Cookie}i" %I %O %D %{deflate_ratio}n%%”
- COMPONENTS
- NGINX_LOG_PATTERN
wiki.nginx.org/NginxHttpLogModule#log_format - we currently only support the default “combined” log format…
- NGINX_PROXY_PATTERN
- NGINX_REQUEST_PATTERN
- SUBCOMPONENTS
- UPSTREAM_LOG_PATTERN
wiki.nginx.org/NginxHttpLogModule#log_format - we currently only support the default “combined” log format…
Attributes
filename[R]
line_number[R]
parsable[R]
raw_line[R]
Public Class Methods
format=(format)
click to toggle source
# File lib/ntail/log_line.rb, line 152 def self.format= format unless @@result = @@parser.parse(@@format = format) raise @@parser.terminal_failures.join("\n") else def @@result.value(log_line, color) if @@output_format == :ansi elements.map { |element| element.value(log_line, color) }.join elsif @@output_format == :html line = elements.map { |element| element.value(log_line, nil) }.join "<span style=\"font-family: monospace; color: #{color}\">%s</span></br>" % line end end end end
new(line, filename = nil, line_number = nil)
click to toggle source
# File lib/ntail/log_line.rb, line 110 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) # counter example (ie. HTTP request that cannot by parsed) # 91.203.96.51 - - [21/Dec/2010:05:26:53 +0000] "-" 400 0 "-" "-" @http_method, @uri, @http_version = $~.captures end if @proxy_addresses and NGINX_PROXY_PATTERN.match(@proxy_addresses) @proxy_addresses = $~.captures.first.split(/, /) end true else false end end
set_output(output)
click to toggle source
# File lib/ntail/log_line.rb, line 144 def self.set_output(output) @@output_format = output end
set_pattern(pattern)
click to toggle source
# File lib/ntail/log_line.rb, line 99 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
Public Instance Methods
method_missing(method, *params)
click to toggle source
for now, until we make it fancier…
# File lib/ntail/log_line.rb, line 138 def method_missing(method, *params) raw_line.send method, *params end
to_s(options = {})
click to toggle source
# File lib/ntail/log_line.rb, line 169 def to_s(options = {}) # simple but boring: # raw_line.to_s # a bit less boring: color = options[:color] && if redirect_status? @@output_format == :ansi ? :yellow : :orange elsif !success_status? :red else :default end @@result.value(self, color) end