Skip to content

Instantly share code, notes, and snippets.

@christianromney
Created June 3, 2009 15:59
Show Gist options
  • Save christianromney/123057 to your computer and use it in GitHub Desktop.
Save christianromney/123057 to your computer and use it in GitHub Desktop.
class Report
BLANK = "".freeze
class << self
def publish(server, options = {})
report = self.new
report.process(options[:log], server)
end
end
def initialize
@output = ""
end
def process(input, server)
@output = @header
open_log(input, server) do |log|
log.each_line do |line|
line.scan(@regex).each do |matched|
matched.each do |line_matched|
@output << line_matched + "|"
end
@output << "#{server}\n"
end
end
@output << "\n"
end
end
private
def open_log(log, server, &block)
if File.exists?(log)
open("#{LOGS_DIR}/#{server}/#{log}.#{PROCESS_DATE}.log", "r") do |f|
block.call(f)
end
else
STDERR.puts "Could not read #{log} on #{server}."
BLANK
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment