Class: Log
- Inherits:
-
Object
- Object
- Log
- Defined in:
- lib/logmerge.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#finished ⇒ Object
Returns the value of attribute finished.
-
#line ⇒ Object
Returns the value of attribute line.
-
#offet ⇒ Object
Returns the value of attribute offet.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #buffer ⇒ Object
-
#initialize(path) ⇒ Log
constructor
A new instance of Log.
- #parseTimestamp(line) ⇒ Object
- #take ⇒ Object
Constructor Details
#initialize(path) ⇒ Log
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/logmerge.rb', line 18 def initialize(path) @offset = 0 if path.include?(':') parts = path.split(':') path = parts[0] @offset = parts[1].to_i end @file = File.open(path) @finished = false buffer end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
17 18 19 |
# File 'lib/logmerge.rb', line 17 def file @file end |
#finished ⇒ Object
Returns the value of attribute finished.
17 18 19 |
# File 'lib/logmerge.rb', line 17 def finished @finished end |
#line ⇒ Object
Returns the value of attribute line.
17 18 19 |
# File 'lib/logmerge.rb', line 17 def line @line end |
#offet ⇒ Object
Returns the value of attribute offet.
17 18 19 |
# File 'lib/logmerge.rb', line 17 def offet @offet end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
17 18 19 |
# File 'lib/logmerge.rb', line 17 def end |
Instance Method Details
#buffer ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/logmerge.rb', line 46 def buffer begin @line = file.readline.strip = parseTimestamp(line) rescue Date::Error = nil end rescue EOFError @line = nil @finished = true = nil end |
#parseTimestamp(line) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/logmerge.rb', line 30 def parseTimestamp(line) # would be great to generalize this more if line[0] == '[' # agent logs ts = DateTime.parse(line[1...24]) ts = ts + @offset.seconds line[1...24] = ts.to_s else #mms logs ts = DateTime.parse(line[0...28]) ts = ts + @offset.seconds line[0...28] = "[#{ts.to_s}]" end ts end |
#take ⇒ Object
59 60 61 62 63 |
# File 'lib/logmerge.rb', line 59 def take ret = line buffer ret end |