mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
- make the plain codec line-terminator aware
This commit is contained in:
parent
2f3c6ec4fa
commit
ed95a7a532
2 changed files with 19 additions and 10 deletions
|
@ -17,14 +17,22 @@ class LogStash::Codecs::Plain < LogStash::Codecs::Base
|
|||
# This only affects "plain" format logs since json is UTF-8 already.
|
||||
config :charset, :validate => ::Encoding.name_list, :default => "UTF-8"
|
||||
|
||||
public
|
||||
def register
|
||||
require "logstash/util/buftok"
|
||||
@buffer = FileWatch::BufferedTokenizer.new
|
||||
end
|
||||
|
||||
public
|
||||
def decode(data)
|
||||
data.force_encoding(@charset)
|
||||
if @charset != "UTF-8"
|
||||
# Convert to UTF-8 if not in that character set.
|
||||
data = data.encode("UTF-8", :invalid => :replace, :undef => :replace)
|
||||
@buffer.extract(data).each do |line|
|
||||
line.force_encoding(@charset)
|
||||
if @charset != "UTF-8"
|
||||
# Convert to UTF-8 if not in that character set.
|
||||
line = line.encode("UTF-8", :invalid => :replace, :undef => :replace)
|
||||
end
|
||||
yield LogStash::Event.new({"message" => line})
|
||||
end
|
||||
yield LogStash::Event.new({"message" => data})
|
||||
end # def decode
|
||||
|
||||
public
|
||||
|
|
|
@ -16,18 +16,19 @@ class LogStash::Inputs::Stdin < LogStash::Inputs::Base
|
|||
end # def register
|
||||
|
||||
def run(queue)
|
||||
require "ap"
|
||||
while true
|
||||
begin
|
||||
line = $stdin.readline.chomp
|
||||
@codec.decode(line) do |event|
|
||||
# Based on some testing, there is no way to interrupt an IO.sysread nor
|
||||
# IO.select call in JRuby. Bummer :(
|
||||
data = $stdin.sysread(16384)
|
||||
@codec.decode(data) do |event|
|
||||
event["source"] = @host
|
||||
event["type"] = @type if @type
|
||||
@tags && @tags.each { |t| event.tag(t) }
|
||||
queue << event
|
||||
end
|
||||
rescue EOFError => ex
|
||||
# stdin closed, finish
|
||||
rescue EOFError, LogStash::ShutdownSignal
|
||||
# stdin closed or a requested shutdown
|
||||
break
|
||||
end
|
||||
end # while true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue