Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bypass gelf library level mapping #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions lib/fluent/plugin/out_gelf.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module Fluent

class GELFOutput < BufferedOutput
class IdentityMap
def self.[](x)
x
end
end

Plugin.register_output("gelf", self)

Expand Down Expand Up @@ -37,7 +42,7 @@ def start
@conn = GELF::Notifier.new(@host, @port, 'WAN', {:facility => 'fluentd', :protocol => @proto})

# Errors are not coming from Ruby so we use direct mapping
@conn.level_mapping = 'direct'
@conn.level_mapping = IdentityMap
# file and line from Ruby are in this class, not relevant
@conn.collect_file_and_line = false
end
Expand Down Expand Up @@ -68,18 +73,19 @@ def format(tag, time, record)
if @use_record_host then gelfentry[:host] = v
else gelfentry[:_host] = v end
when 'level' then
case "#{v}".downcase
# emergency and alert aren't supported by gelf-rb
when '0', 'emergency' then gelfentry[:level] = GELF::UNKNOWN
when '1', 'alert' then gelfentry[:level] = GELF::UNKNOWN
when '2', 'critical', 'crit' then gelfentry[:level] = GELF::FATAL
when '3', 'error', 'err' then gelfentry[:level] = GELF::ERROR
when '4', 'warning', 'warn' then gelfentry[:level] = GELF::WARN
# gelf-rb also skips notice
when '5', 'notice' then gelfentry[:level] = GELF::INFO
when '6', 'informational', 'info' then gelfentry[:level] = GELF::INFO
when '7', 'debug' then gelfentry[:level] = GELF::DEBUG
else gelfentry[:_level] = v
if v.is_a? Fixnum then gelfentry[:level] = v
else
case v.to_s.downcase
when 'emergency' then gelfentry[:level] = 0
when 'alert' then gelfentry[:level] = 1
when 'critical', 'crit' then gelfentry[:level] = 2
when 'error', 'err' then gelfentry[:level] = 3
when 'warning', 'warn' then gelfentry[:level] = 4
when 'notice' then gelfentry[:level] = 5
when 'informational', 'info' then gelfentry[:level] = 6
when 'debug' then gelfentry[:level] = 7
else gelfentry[:_level] = v
end
end
when 'msec' then
# msec must be three digits (leading/trailing zeroes)
Expand Down