Link to home
Create AccountLog in
Avatar of rbwin
rbwin

asked on

I have ruby program that reads an error log txt file

This is a question I  introduced on Saturday.I have anywhere from 1 to X number of error logs that are text files. It is to the point where it recognizes the error log. It is then suppose to read the file and find how many times the word WARNING is listed and how many times the word ERROR is listed. As I said it finds the file and does not give an error but it also reports WARNING = 0 and ERROR = 0.
I have pasted the code and the result when it is run below and I have attached the text file I have been using to test with.

# fill in the path of the input files here
my_path = "C:\\Ruby\\Text\\"
 
warning = 0
error = 0
 
d = Dir.new(my_path)
d.each do |fl|
   unless fl == '.' or fl == '..' then
 puts my_path + fl
  File.open(my_path + fl, "r").each do |line|
    if line =~ /error/ then
      error += 1
    elsif line =~ /warning/ then
       warning += 1
    end
   end
   
  end
end
puts warning.to_s
puts error.to_s

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Brad>cd c:\ruby

C:\Ruby>ruby 1.rb
C:\Ruby\Text\log_file_20090227_030614.txt
0
0

C:\Ruby>
log-file-20090227-030614.txt
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account