lib/semantic_logger/appender/syslog.rb in semantic_logger-4.6.1 vs lib/semantic_logger/appender/syslog.rb in semantic_logger-4.7.0
- old
+ new
@@ -1,8 +1,8 @@
-require 'syslog'
-require 'uri'
-require 'socket'
+require "syslog"
+require "uri"
+require "socket"
# Send log messages to local syslog, or remote syslog servers over TCP or UDP.
#
# Example:
# # Log to a local Syslog daemon
# SemanticLogger.add_appender(appender: :syslog)
@@ -117,11 +117,11 @@
# Supply a custom map of SemanticLogger levels to syslog levels.
#
# Example:
# # Change the warn level to LOG_NOTICE level instead of a the default of LOG_WARNING.
# SemanticLogger.add_appender(appender: :syslog, level_map: {warn: ::Syslog::LOG_NOTICE})
- def initialize(url: 'syslog://localhost',
+ def initialize(url: "syslog://localhost",
facility: ::Syslog::LOG_USER,
level_map: SemanticLogger::Formatters::Syslog::LevelMap.new,
options: ::Syslog::LOG_PID | ::Syslog::LOG_CONS,
tcp_client: {},
**args,
@@ -130,32 +130,32 @@
@options = options
@facility = facility
@level_map = level_map
@url = url
uri = URI(@url)
- @server = uri.host || 'localhost'
+ @server = uri.host || "localhost"
@protocol = (uri.scheme || :syslog).to_sym
@port = uri.port || 514
- @server = 'localhost' if @protocol == :syslog
+ @server = "localhost" if @protocol == :syslog
@tcp_client_options = tcp_client
raise "Unknown protocol #{@protocol}!" unless %i[syslog tcp udp].include?(@protocol)
# The syslog_protocol gem is required when logging over TCP or UDP.
if %i[tcp udp].include?(@protocol)
begin
- require 'syslog_protocol'
+ require "syslog_protocol"
rescue LoadError
- raise LoadError.new('Missing gem: syslog_protocol. This gem is required when logging over TCP or UDP. To fix this error: gem install syslog_protocol')
+ raise LoadError, "Missing gem: syslog_protocol. This gem is required when logging over TCP or UDP. To fix this error: gem install syslog_protocol"
end
# The net_tcp_client gem is required when logging over TCP.
if protocol == :tcp
begin
- require 'net/tcp_client'
+ require "net/tcp_client"
rescue LoadError
- raise LoadError.new('Missing gem: net_tcp_client. This gem is required when logging over TCP. To fix this error: gem install net_tcp_client')
+ raise LoadError, "Missing gem: net_tcp_client. This gem is required when logging over TCP. To fix this error: gem install net_tcp_client"
end
end
end
super(**args, &block)
@@ -169,11 +169,11 @@
when :syslog
method = ::Syslog.opened? ? :reopen : :open
::Syslog.send(method, application, options, facility)
when :tcp
@tcp_client_options[:server] = "#{@server}:#{@port}"
- @remote_syslog = Net::TCPClient.new(@tcp_client_options)
+ @remote_syslog = Net::TCPClient.new(**@tcp_client_options)
# Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
@remote_syslog.logger = logger
when :udp
@remote_syslog = UDPSocket.new
else
@@ -184,10 +184,10 @@
# Write the log using the specified protocol and server.
def log(log)
case @protocol
when :syslog
# Since the Ruby Syslog API supports sprintf format strings, double up all existing '%'
- message = formatter.call(log, self).gsub '%', '%%'
+ message = formatter.call(log, self).gsub "%", "%%"
::Syslog.log @level_map[log.level], message
when :tcp
@remote_syslog.retry_on_connection_failure { @remote_syslog.write("#{formatter.call(log, self)}\r\n") }
when :udp
@remote_syslog.send(formatter.call(log, self), 0, @server, @port)