diff --git a/lib/fluentd/plugin/out_syslog.rb b/lib/fluentd/plugin/out_syslog.rb index 67fd248..391da4e 100644 --- a/lib/fluentd/plugin/out_syslog.rb +++ b/lib/fluentd/plugin/out_syslog.rb @@ -78,11 +78,15 @@ def emit(tag, es, chain) time = Time.now end @packet.time = time - @packet.tag = if tag_key - record[tag_key][0..31].gsub(/[\[\]]/,'') # tag is trimmed to 32 chars for syslog_protocol gem compatibility - else - tag[0..31] # tag is trimmed to 32 chars for syslog_protocol gem compatibility - end + @packet.tag = if @tag_key + begin + record[@tag_key][0..31].gsub(/[\[\]]/,'') # tag is trimmed to 32 chars for syslog_protocol gem compatibility + rescue + tag[0..31] # tag is trimmed to 32 chars for syslog_protocol gem compatibility + end + else + tag[0..31] # tag is trimmed to 32 chars for syslog_protocol gem compatibility + end packet = @packet.dup packet.content = record[@payload_key] @socket.send(packet.assemble, 0, @remote_syslog, @port) diff --git a/lib/fluentd/plugin/out_syslog_buffered.rb b/lib/fluentd/plugin/out_syslog_buffered.rb index 6f6f456..9044f85 100644 --- a/lib/fluentd/plugin/out_syslog_buffered.rb +++ b/lib/fluentd/plugin/out_syslog_buffered.rb @@ -102,11 +102,15 @@ def send_to_syslog(tag, time, record) time = Time.now end @packet.time = time - @packet.tag = if tag_key - record[tag_key][0..31].gsub(/[\[\]]/,'') # tag is trimmed to 32 chars for syslog_protocol gem compatibility - else - tag[0..31] # tag is trimmed to 32 chars for syslog_protocol gem compatibility - end + @packet.tag = if @tag_key + begin + record[@tag_key][0..31].gsub(/[\[\]]/,'') # tag is trimmed to 32 chars for syslog_protocol gem compatibility + rescue + tag[0..31] # tag is trimmed to 32 chars for syslog_protocol gem compatibility + end + else + tag[0..31] # tag is trimmed to 32 chars for syslog_protocol gem compatibility + end packet = @packet.dup packet.content = record[@payload_key] begin