Skip to content

Instantly share code, notes, and snippets.

@bradland
Created February 17, 2012 19:47
Show Gist options
  • Save bradland/1855093 to your computer and use it in GitHub Desktop.
Save bradland/1855093 to your computer and use it in GitHub Desktop.
RLA wrapper
#!/usr/bin/env ruby -wKU
rvm_result = `source "$HOME/.rvm/scripts/rvm" && rvm use ruby-1.9.3-p0@log-examiner`
puts rvm_result
require 'date'
# Example: ./report_day.rb production.log 2012-02-18
class App
RLA_DATE_FMT = "%Y-%m-%d %H:%M:%S" # The date format expected by request-log-analyzer
def initialize
unless RUBY_VERSION.scan('1.9.3').length > 0
$stderr.puts red("ERROR: This will run much faster under 1.9.3 because of the improved date methods. Check out RVM or rbenv for easy management of Ruby versions.")
exit 1
end
if ARGV.length < 2
$stderr.puts red("ERROR: This script expects at least two arguments")
exit 1
end
@infile = ARGV[0]
@after = DateTime.parse(ARGV[1]).strftime(RLA_DATE_FMT)
@before = (DateTime.parse(ARGV[1]) + 1).strftime(RLA_DATE_FMT)
@outfile = "rla-#{DateTime.parse(ARGV[1]).strftime("%Y-%m-%d")}.html"
end
def start
cmd = %Q{request-log-analyzer --after "#{@after}" --before "#{@before}" --output html #{@infile} > #{@outfile}}
$stderr.puts cmd
`#{cmd}`
end
# Color methods are borrowed from: http://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/
def colorize(text, color_code)
"#{color_code}#{text}\e[0m"
end
def red(text); colorize(text, "\e[31m"); end
def green(text); colorize(text, "\e[32m"); end
end # end App class
App.new.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment