Sha256: 1f48f4acf14bbabc4ecfde92c67d974ceed2c89e2e74d805e01fc4436115b3bc

Contents?: true

Size: 1.39 KB

Versions: 8

Compression:

Stored size: 1.39 KB

Contents

# Copyright (C) 2014  Kouhei Sutou <kou@clear-code.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require "grntest/log-entry"

module Grntest
  class LogParser
    def parse(log)
      timestamp = nil
      log_level = nil
      message = nil
      emit_entry = lambda do
        if timestamp
          entry = LogEntry.new(timestamp, log_level, message.chomp)
          yield(entry)
        end
      end
      log.each_line do |line|
        case line
        when /\A(\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}\.\d+)\|
                ([a-zA-Z])\|
                (?:\d+:)?
                \s*/x
          emit_entry.call
          timestamp = $1
          log_level = $2
          message = $POSTMATCH
        else
          message ||= ""
          message << line
        end
      end
      emit_entry.call
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
grntest-1.3.1 lib/grntest/log-parser.rb
grntest-1.3.0 lib/grntest/log-parser.rb
grntest-1.2.9 lib/grntest/log-parser.rb
grntest-1.2.8 lib/grntest/log-parser.rb
grntest-1.2.7 lib/grntest/log-parser.rb
grntest-1.2.6 lib/grntest/log-parser.rb
grntest-1.2.5 lib/grntest/log-parser.rb
grntest-1.2.4 lib/grntest/log-parser.rb