Skip to content

Commit

Permalink
Truncate large string values
Browse files Browse the repository at this point in the history
Resolves #26.
  • Loading branch information
emsearcy committed Nov 11, 2016
1 parent d7e6550 commit 592a571
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/fluent/plugin/out_gelf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class GELFOutput < BufferedOutput
config_param :host, :string, :default => nil
config_param :port, :integer, :default => 12201
config_param :protocol, :string, :default => 'udp'
# Default max_bytes is set to avoid Elasticsearch indexing errors.
config_param :max_bytes, :integer, :default => 32000

def initialize
super
Expand Down Expand Up @@ -54,6 +56,9 @@ def format(tag, time, record)
gelfentry = { :timestamp => timestamp, :_tag => tag }

record.each_pair do |k,v|
# Truncate values longer than configured maximum
v = v.bytesize > @max_bytes ? "#{v.byteslice(0, @max_bytes - 3)}..." : v

case k
when 'version' then
gelfentry[:_version] = v
Expand Down

1 comment on commit 592a571

@poom
Copy link

@poom poom commented on 592a571 Nov 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emsearcy I got this error

2016-11-23 04:14:50.000000000 +0000 fluent.warn: {"error":"#<NoMethodError: undefined method bitesize' for 0:Fixnum>","tag":"production.log_request","message":"emit transaction failed: error_class=NoMethodError error=\"undefined method bitesize' for 0:Fixnum" tag="production.log_request""}

Thanks

Please sign in to comment.