Class: Dexter::LogParser
- Inherits:
-
Object
- Object
- Dexter::LogParser
- Defined in:
- lib/dexter/log_parser.rb
Direct Known Subclasses
Constant Summary collapse
- REGEX =
/duration: (\d+\.\d+) ms (statement|execute <unnamed>): (.+)/- LINE_SEPERATOR =
": ".freeze
- DETAIL_LINE =
"DETAIL: ".freeze
Instance Method Summary collapse
-
#initialize(logfile, collector) ⇒ LogParser
constructor
A new instance of LogParser.
- #perform ⇒ Object
Constructor Details
#initialize(logfile, collector) ⇒ LogParser
Returns a new instance of LogParser.
7 8 9 10 |
# File 'lib/dexter/log_parser.rb', line 7 def initialize(logfile, collector) @logfile = logfile @collector = collector end |
Instance Method Details
#perform ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dexter/log_parser.rb', line 12 def perform active_line = nil duration = nil @logfile.each_line do |line| if active_line if line.include?(DETAIL_LINE) add_parameters(active_line, line.chomp.split(DETAIL_LINE)[1]) elsif line.include?(LINE_SEPERATOR) process_entry(active_line, duration) active_line = nil else active_line << line end end if !active_line && (m = REGEX.match(line.chomp)) duration = m[1].to_f active_line = m[3] end end process_entry(active_line, duration) if active_line end |