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.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#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
Returns a new instance of Log.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 if parts.size > 2 @tag = parts[2] end 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 |
#tag ⇒ Object
Returns the value of attribute tag.
17 18 19 |
# File 'lib/logmerge.rb', line 17 def tag @tag end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
17 18 19 |
# File 'lib/logmerge.rb', line 17 def @timestamp end |
Instance Method Details
#buffer ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/logmerge.rb', line 49 def buffer begin @line = file.readline.strip @timestamp = parseTimestamp(line) line.prepend("[#{@tag}]") if @tag rescue Date::Error @timestamp = nil end rescue EOFError @line = nil @finished = true @timestamp = nil end |
#parseTimestamp(line) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/logmerge.rb', line 33 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
63 64 65 66 67 |
# File 'lib/logmerge.rb', line 63 def take ret = line buffer ret end |