lib/semantic_logger/appender/graylog.rb in semantic_logger-4.6.1 vs lib/semantic_logger/appender/graylog.rb in semantic_logger-4.7.0

- old
+ new

@@ -1,10 +1,10 @@ -require 'uri' +require "uri" begin - require 'gelf' + require "gelf" rescue LoadError - raise LoadError.new('Gem gelf is required for logging to Graylog. Please add the gem "gelf" to your Gemfile.') + raise LoadError, 'Gem gelf is required for logging to Graylog. Please add the gem "gelf" to your Gemfile.' end # Forward log entries to a Graylog server. # # Example: @@ -80,12 +80,12 @@ # Default: SemanticLogger.host # # application: [String] # Name of this application to appear in log messages. # Default: SemanticLogger.application - def initialize(url: 'udp://localhost:12201', - max_size: 'WAN', + def initialize(url: "udp://localhost:12201", + max_size: "WAN", gelf_options: {}, level_map: LevelMap.new, **args, &block) @@ -103,11 +103,13 @@ uri = URI.parse(@url) @server = uri.host @port = uri.port @protocol = uri.scheme.to_sym - raise(ArgumentError, "Invalid protocol value: #{@protocol}. Must be :udp or :tcp") unless %i[udp tcp].include?(@protocol) + unless %i[udp tcp].include?(@protocol) + raise(ArgumentError, "Invalid protocol value: #{@protocol}. Must be :udp or :tcp") + end gelf_options[:protocol] ||= (@protocol == :tcp ? GELF::Protocol::TCP : GELF::Protocol::UDP) gelf_options[:facility] ||= application @notifier = GELF::Notifier.new(server, port, max_size, gelf_options) @@ -118,14 +120,14 @@ def call(log, logger) h = default_formatter.call(log, logger) h[:short_message] = h.delete(:message) if h[:short_message].nil? - h[:short_message] = log.exception.nil? ? '<no-exception-message>' : log.exception.message + h[:short_message] = log.exception.nil? ? "<no-exception-message>" : log.exception.message end - h[:level] = logger.level_map[log.level] - h[:level_str] = log.level.to_s - h[:duration_str] = h.delete(:duration) + h[:level] = logger.level_map[log.level] + h[:level_str] = log.level.to_s + h[:duration_str] = h.delete(:duration) h end # Forward log messages def log(log)