Skip to content

Commit

Permalink
Merge pull request #182 from sonots/raw_parser
Browse files Browse the repository at this point in the history
PROPOSE: add format raw
  • Loading branch information
repeatedly committed Sep 7, 2013
2 parents 555e90a + 1924537 commit 55aab1f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/fluent/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ def call(text)
end
end

class NoneParser
include Configurable

config_param :message_key, :string, :default => 'message'

def call(text)
record = {}
record[@message_key] = text
return Engine.now, record
end
end

class ApacheParser
include Configurable

Expand Down Expand Up @@ -229,6 +241,7 @@ def call(text)
'ltsv' => Proc.new { LabeledTSVParser.new },
'csv' => Proc.new { CSVParser.new },
'nginx' => Proc.new { RegexpParser.new(/^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/, {'time_format'=>"%d/%b/%Y:%H:%M:%S %z"}) },
'none' => Proc.new { NoneParser.new },
}

def self.register_template(name, regexp_or_proc, time_format=nil)
Expand Down
28 changes: 28 additions & 0 deletions test/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,32 @@ def test_call_with_customized_time_format
}, record)
end
end

class NoneParserTest < ::Test::Unit::TestCase
include ParserTest

def test_config_params
parser = TextParser::NoneParser.new
assert_equal "message", parser.message_key

parser.configure('message_key' => 'foobar')
assert_equal "foobar", parser.message_key
end

def test_call
parser = TextParser::TEMPLATE_FACTORIES['none'].call
time, record = parser.call('log message!')

assert_equal({'message' => 'log message!'}, record)
end

def test_call_with_message_key
parser = TextParser::NoneParser.new
parser.configure('message_key' => 'foobar')
time, record = parser.call('log message!')

assert_equal({'foobar' => 'log message!'}, record)
end
end

end

0 comments on commit 55aab1f

Please sign in to comment.