lib/semantic_logger/appender/tcp.rb in semantic_logger-3.4.1 vs lib/semantic_logger/appender/tcp.rb in semantic_logger-4.0.0.beta1
- old
+ new
@@ -180,16 +180,17 @@
# server: 'server:3300',
# connect_retry_interval: 0.1,
# connect_retry_count: 5
# )
def initialize(options = {}, &block)
- @options = options.dup
- @separator = @options.delete(:separator) || "\n"
+ @tcp_client = nil
+ @options = options.dup
+ @separator = @options.delete(:separator) || "\n"
# Use the internal logger so that errors with remote logging are only written locally.
- Net::TCPClient.logger = SemanticLogger::Logger.logger.dup
- Net::TCPClient.logger.name = 'Net::TCPClient'
+ Net::TCPClient.logger = SemanticLogger::Processor.logger.clone
+ Net::TCPClient.logger.name = 'Net::TCPClient'
options = extract_subscriber_options!(@options)
super(options, &block)
reopen
end
@@ -203,10 +204,13 @@
# Write the log using the specified protocol and server.
def log(log)
return false unless should_log?(log)
- @tcp_client.retry_on_connection_failure { @tcp_client.write("#{formatter.call(log, self)}#{separator}") }
+ message = formatter.call(log, self)
+ @tcp_client.retry_on_connection_failure do
+ @tcp_client.write("#{message}#{separator}")
+ end
true
end
# Flush is called by the semantic_logger during shutdown.
def flush