Skip to content

Commit

Permalink
Add desc for parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tajima authored and Tobias Lütke committed Oct 31, 2009
1 parent 604c39e commit ee28e7d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
10 changes: 7 additions & 3 deletions lib/parsers/hostname_parser.rb
@@ -1,12 +1,16 @@

class HostnameParser

# sample log output
# given a string in format:
#
# app3 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
# or
# 129.123.2.1 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
#
# strips out the hostname/IP and appname
#
# result => [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]


# parse out ip/hostapp : line
LineRegexp = /^([\w-]+|\d+\.\d+\.\d+\.\d+)\s([^:]*):\s*(.*)/

attr_accessor :elements, :next_parser
Expand Down
11 changes: 9 additions & 2 deletions lib/parsers/shop_parser.rb
@@ -1,8 +1,15 @@
class ShopParser

# given a string in format:
#
# [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]

# parse out the shop name
#
# strips out the shop name
#
# result => :shop => wadedemt.myshopify.com
# :line => Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]


LineRegexp = /^\s*\[([a-zA-Z0-9\-.]+)\]\s*(.*)/

attr_accessor :elements
Expand Down
30 changes: 19 additions & 11 deletions lib/parsers/time_parser.rb
@@ -1,18 +1,26 @@

class TimeParser

# sample log output
# Jul 24 14:58:21 app3 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
# 1 date
# 2 app
# 3 shop
# 4 line

# parse out :timestamp, :line
# strips out timestamp and if start/end times are defined, will reject lines that don't fall within proper time periods
#
# entry format:
# Jul 24 14:58:21 app3 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
#
# params = {
# 'sh' => start hour
# 'sm' => start minute
# 'ss' => start second
# 'eh' => end hour
# 'em' => end minute
# 'es' => end second
# }
#
# if 'sh' is defined, reject any lines where timestamp is earlier than start time
# if 'eh' is defined, reject any lines where timestamp is later than end time
# if 'sh' && 'eh' is defined, reject any lines where timestamp is not between start time and end time

LineRegexp = /^(\w+\s+\d+\s\d\d:\d\d:\d\d)\s(.*)/

OFFSET = 4 * 60 * 60 # est offset


attr_accessor :elements, :params

def initialize(next_renderer = nil, params = {})
Expand Down

0 comments on commit ee28e7d

Please sign in to comment.