Class: Peephole::Logline

Inherits:
Object
  • Object
show all
Defined in:
app/models/peephole/logline.rb

Defined Under Namespace

Modules: TYPE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, num) ⇒ Logline

Returns a new instance of Logline.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/peephole/logline.rb', line 122

def initialize(line, num)
  self.num = num

  case line
  when / Started (\w+) "(.+)" .+ at (.+)/
    self.method = $1
    self.target = $2
    self.started_at = Time.parse($3)
    self.type = TYPE::STARTED
  when /   Parameters: ({.+})/
    params = JSON.parse($1.gsub('=>', ':'))
    params.dup.each do |k, v|
      if v.is_a?(Hash)
        v.each do |k2, v2|
          params["#{k}[#{k2}]"] = v2
        end
        params.delete(k)
      end
    end
    self.params = params
    self.type = TYPE::PARAMS
  when / Completed (\d+) .+ in (.+ms) \(/
    self.status = $1
    self.duration = $2
    self.type = TYPE::COMPLETED
  end
  if line =~ /\[(\w+\-\w+\-\w+\-\w+\-\w+)\] /
    self.uuid = $1
  end
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



6
7
8
# File 'app/models/peephole/logline.rb', line 6

def duration
  @duration
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'app/models/peephole/logline.rb', line 4

def method
  @method
end

#numObject

Returns the value of attribute num.



3
4
5
# File 'app/models/peephole/logline.rb', line 3

def num
  @num
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'app/models/peephole/logline.rb', line 5

def params
  @params
end

#started_atObject

Returns the value of attribute started_at.



4
5
6
# File 'app/models/peephole/logline.rb', line 4

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'app/models/peephole/logline.rb', line 6

def status
  @status
end

#targetObject

Returns the value of attribute target.



4
5
6
# File 'app/models/peephole/logline.rb', line 4

def target
  @target
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'app/models/peephole/logline.rb', line 3

def type
  @type
end

#uuidObject

Returns the value of attribute uuid.



3
4
5
# File 'app/models/peephole/logline.rb', line 3

def uuid
  @uuid
end

Class Method Details

.bytes(path, page) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'app/models/peephole/logline.rb', line 46

def bytes(path, page)
  raw, eof = case path.to_s
             when /\.gz\z/
               raw_gz(path, page)
             else
               raw_txt(path, page)
             end
  [raw, eof]
end

.first_byte(page) ⇒ Object



38
39
40
# File 'app/models/peephole/logline.rb', line 38

def first_byte(page)
  first(page, :byte)
end

.first_line(page) ⇒ Object



15
16
17
# File 'app/models/peephole/logline.rb', line 15

def first_line(page)
  first(page, :line)
end

.last_byte(page) ⇒ Object



42
43
44
# File 'app/models/peephole/logline.rb', line 42

def last_byte(page)
  last(page, :byte)
end

.last_line(page) ⇒ Object



19
20
21
# File 'app/models/peephole/logline.rb', line 19

def last_line(page)
  last(page, :line)
end

.lines(path, page) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/peephole/logline.rb', line 23

def lines(path, page)
  loglines = []
  logmap = {}
  eof = true
  each(path, page) do |line, i|
    next if i < first_line(page)
    if i >= last_line(page)
      eof = false
      break
    end
    parse(line, i + 1, loglines, logmap)
  end
  [loglines, eof]
end