Sha256: 0ca9a6755e28ea62fe34a176f98ac3140cdaa0715b64bd539bf5fd552185e047

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 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])\|\s*/
          emit_entry.call
          timestamp = $1
          log_level = $2
          message = $POSTMATCH
        else
          message << line
        end
      end
      emit_entry.call
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grntest-1.2.3 lib/grntest/log-parser.rb
grntest-1.2.2 lib/grntest/log-parser.rb
grntest-1.2.1 lib/grntest/log-parser.rb
grntest-1.2.0 lib/grntest/log-parser.rb
grntest-1.1.9 lib/grntest/log-parser.rb
grntest-1.1.8 lib/grntest/log-parser.rb
grntest-1.1.7 lib/grntest/log-parser.rb
grntest-1.1.6 lib/grntest/log-parser.rb
grntest-1.1.5 lib/grntest/log-parser.rb
grntest-1.1.4 lib/grntest/log-parser.rb
grntest-1.1.3 lib/grntest/log-parser.rb
grntest-1.1.2 lib/grntest/log-parser.rb
grntest-1.1.1 lib/grntest/log-parser.rb
grntest-1.1.0 lib/grntest/log-parser.rb
grntest-1.0.9 lib/grntest/log-parser.rb