nginxのデフォルトログ形式のファイルをapacheのデフォルトログ形式に変換する
使い捨てコード
# nginx2apache.rb def self.log_pattern / ^ (\S+) # ip_address \s+ (\S+) # identity_check \s+ (\S+) # user \s+ \[ (.*?) \] # date \s+ " (.*?) " # request \s+ (\S+) # status \s+ (\S+) # size \s+ " (.*?) " # referer \s+ " (.*?) " # user_agent \s+ " (.*?) " # forwarded_for $ /x end src_f = ARGV[0] dst_f = ARGV[1] puts "src: #{src_f}" puts "dst: #{dst_f}" open(dst_f, "w") do |dst| open(src_f) do |src| while line = src.gets match = line.match(log_pattern) line = line.chomp if match.nil? line += ' "-"' end dst.puts line end end end
使い方
$ ruby nginx2apache.rb nginx.access.log apache.access.log