Class: CamTool::LogBreaker

Inherits:
Object
  • Object
show all
Defined in:
lib/camtool/log_breaker.rb

Direct Known Subclasses

MQTTBreaker

Instance Method Summary collapse

Instance Method Details

#break_log_file(filename) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/camtool/log_breaker.rb', line 3

def break_log_file filename
  if filename != nil
    open(filename) do |file|
      @i=0
      file.each_line do |line|
        ok = true
        line = line.sub /\[[0-9 :-]*\]\t[A-Z]*[ ]*:[ ]*/, ''
        line = line.gsub "\n", ''
        begin
          JSON.parse(line)
        rescue JSON::ParserError
          abort "Error #{ex.class}, message: #{ex.message}"
        end
        self.new_entry line unless !ok
      end
    end unless !File.file?(filename)
    print "File does not exist\n" unless File.file?(filename)
  end
  self
end

#new_entry(entry) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/camtool/log_breaker.rb', line 24

def new_entry entry
  fname="./#{@i}.break"
  @i=@i+1
  File.open(fname, 'w+') do |f|
    f.write entry
  end
end