Created
August 24, 2011 08:51
-
-
Save simple/1167611 to your computer and use it in GitHub Desktop.
Preprocessing Apache Log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'date' | |
require 'apachelogregex' | |
# apache log format | |
parser = ApacheLogRegex.new('%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %I %b %D') | |
File.open(ARGV[0]).readlines.each do | line | | |
p = parser.parse(line) | |
next if p.nil? | |
# prepare needed columns | |
path = p['%r'].split(' ')[1] | |
# from zend log default to YYYY-MM-DD H:i:S | |
date = DateTime.strptime(p['%t'], '[%d/%b/%Y:%H:%M:%S %Z]').strftime('%Y-%m-%d %H:%M:%S') | |
puts "#{date}\t#{p['%h']}\t#{path}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment