Created
June 3, 2009 15:59
-
-
Save christianromney/123057 to your computer and use it in GitHub Desktop.
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
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