Class | XhochY::Drossellog::LogLine |
In: |
xhochy/drossellog/logline.rb
|
Parent: | Object |
Represents a line in a Apache combined-style logfile
agent | [R] | The requesting user agent |
day | [R] | The day where the request was made |
hour | [R] | The hour where the request was made |
http_code | [R] | The answered HTTP code form the server |
ip | [R] | The IP which made the request |
line | [R] | The whole line |
method | [R] | The method used to make the request |
minute | [R] | The minute where the request was made |
month | [R] | The month where the request was made |
path | [R] | The requested path |
referrer | [R] | The referrer which took the client to this point |
second | [R] | The second where the request was made |
size | [R] | The size of the content sent back to the client |
timezone | [R] | The timezone of the server at the time of the request |
year | [R] | The year where the request was made |
return the regular expression for parsing a apache-combined logfile line
# File xhochy/drossellog/logline.rb, line 49 49: def self.get_rxp 50: @@rxp 51: end
check if the line is a valid apache-combined logfile line
# File xhochy/drossellog/logline.rb, line 44 44: def self.matches?(line) 45: return ('line' =~ @@rxp) 46: end
Create a new instance of a XYLogLine object
# File xhochy/drossellog/logline.rb, line 54 54: def initialize(line) 55: @line = line 56: matches = @@rxp.match(line) 57: @ip = matches[1] 58: # matches[2] -> user .. 59: # matches[3] -> user .. 60: @day = matches[4].to_i 61: @month = matches[5] 62: @year = matches[6].to_i 63: @hour = matches[7].to_i 64: @minute = matches[8].to_i 65: @second = matches[9].to_i 66: @timezone = matches[10] 67: @method = matches[11] 68: @path = matches[12] 69: @http_code = matches[13] 70: @size = matches[14].to_i 71: @referrer = matches[15] 72: @agent = matches[16] 73: end
Returns this line as a Hash object
# File xhochy/drossellog/logline.rb, line 156 156: def to_hash(strip_tags) 157: hash = {} 158: 159: if !strip_tags.include?('ip') 160: hash['ip'] = @ip 161: end 162: 163: if !strip_tags.include?('day') 164: hash['day'] = @day 165: end 166: 167: if !strip_tags.include?('month') 168: hash['month'] << @month 169: end 170: 171: if !strip_tags.include?('year') 172: hash['year'] = @year 173: end 174: 175: if !strip_tags.include?('hour') 176: hash['hour'] = @hour 177: end 178: 179: if !strip_tags.include?('minute') 180: hash['minute'] = @minute 181: end 182: 183: if !strip_tags.include?('second') 184: hash['second'] = @second 185: end 186: 187: if !strip_tags.include?('timezone') 188: hash['timezone'] = @timezone 189: end 190: 191: if !strip_tags.include?('method') 192: hash['method'] = @method 193: end 194: 195: if !strip_tags.include?('path') 196: hash['path'] = @path 197: end 198: 199: if !strip_tags.include?('http_code') 200: hash['http_code'] = @http_code 201: end 202: 203: if !strip_tags.include?('size') 204: hash['size'] = @size 205: end 206: 207: if !strip_tags.include?('referrer') 208: hash['referrer'] = @referrer 209: end 210: 211: if !strip_tags.include?('agent') 212: hash['agent'] = @agent 213: end 214: 215: return hash 216: end
Return this object as a (Lib)XML-Node
In strip_tags we define which information should not be included into the node
# File xhochy/drossellog/logline.rb, line 79 79: def to_xml_node(strip_tags) 80: node = XML::Node.new('line') 81: 82: if !strip_tags.include?('ip') 83: node << ip_node = XML::Node.new('ip') 84: ip_node << @ip 85: end 86: 87: if !strip_tags.include?('day') 88: node << day_node = XML::Node.new('day') 89: day_node << @day 90: end 91: 92: if !strip_tags.include?('month') 93: node << month_node = XML::Node.new('month') 94: month_node << @month 95: end 96: 97: if !strip_tags.include?('year') 98: node << year_node = XML::Node.new('year') 99: year_node << @year 100: end 101: 102: if !strip_tags.include?('hour') 103: node << hour_node = XML::Node.new('hour') 104: hour_node << @hour 105: end 106: 107: if !strip_tags.include?('minute') 108: node << minute_node = XML::Node.new('minute') 109: minute_node << @minute 110: end 111: 112: if !strip_tags.include?('second') 113: node << second_node = XML::Node.new('second') 114: second_node << @second 115: end 116: 117: if !strip_tags.include?('timezone') 118: node << timezone_node = XML::Node.new('timezone') 119: timezone_node << @timezone 120: end 121: 122: if !strip_tags.include?('method') 123: node << method_node = XML::Node.new('method') 124: method_node << @method 125: end 126: 127: if !strip_tags.include?('path') 128: node << path_node = XML::Node.new('path') 129: path_node << @path 130: end 131: 132: if !strip_tags.include?('http_code') 133: node << http_code_node = XML::Node.new('http_code') 134: http_code_node << @http_code 135: end 136: 137: if !strip_tags.include?('size') 138: node << size_node = XML::Node.new('size') 139: size_node << @size 140: end 141: 142: if !strip_tags.include?('referrer') 143: node << referrer_node = XML::Node.new('referrer') 144: referrer_node << @referrer 145: end 146: 147: if !strip_tags.include?('agent') 148: node << agent_node = XML::Node.new('agent') 149: agent_node << @agent 150: end 151: 152: return node 153: end