semantic_logger 4.5.0 → 4.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +7 -7
- data/lib/semantic_logger.rb +23 -22
- data/lib/semantic_logger/ansi_colors.rb +0 -10
- data/lib/semantic_logger/appender.rb +54 -64
- data/lib/semantic_logger/appender/async.rb +10 -8
- data/lib/semantic_logger/appender/async_batch.rb +4 -2
- data/lib/semantic_logger/appender/bugsnag.rb +7 -7
- data/lib/semantic_logger/appender/elasticsearch.rb +12 -11
- data/lib/semantic_logger/appender/elasticsearch_http.rb +4 -4
- data/lib/semantic_logger/appender/file.rb +2 -1
- data/lib/semantic_logger/appender/graylog.rb +15 -10
- data/lib/semantic_logger/appender/honeybadger.rb +3 -3
- data/lib/semantic_logger/appender/http.rb +20 -18
- data/lib/semantic_logger/appender/kafka.rb +5 -5
- data/lib/semantic_logger/appender/mongodb.rb +6 -6
- data/lib/semantic_logger/appender/new_relic.rb +2 -2
- data/lib/semantic_logger/appender/rabbitmq.rb +5 -5
- data/lib/semantic_logger/appender/sentry.rb +7 -7
- data/lib/semantic_logger/appender/splunk.rb +6 -5
- data/lib/semantic_logger/appender/splunk_http.rb +3 -3
- data/lib/semantic_logger/appender/syslog.rb +12 -12
- data/lib/semantic_logger/appender/tcp.rb +9 -9
- data/lib/semantic_logger/appender/udp.rb +2 -2
- data/lib/semantic_logger/appenders.rb +13 -34
- data/lib/semantic_logger/base.rb +43 -31
- data/lib/semantic_logger/formatters.rb +11 -11
- data/lib/semantic_logger/formatters/base.rb +15 -6
- data/lib/semantic_logger/formatters/color.rb +12 -13
- data/lib/semantic_logger/formatters/default.rb +18 -5
- data/lib/semantic_logger/formatters/fluentd.rb +7 -18
- data/lib/semantic_logger/formatters/json.rb +3 -5
- data/lib/semantic_logger/formatters/raw.rb +39 -10
- data/lib/semantic_logger/formatters/signalfx.rb +14 -21
- data/lib/semantic_logger/formatters/syslog.rb +3 -3
- data/lib/semantic_logger/formatters/syslog_cee.rb +3 -3
- data/lib/semantic_logger/jruby/garbage_collection_logger.rb +4 -2
- data/lib/semantic_logger/levels.rb +9 -7
- data/lib/semantic_logger/log.rb +49 -73
- data/lib/semantic_logger/logger.rb +6 -8
- data/lib/semantic_logger/metric/new_relic.rb +3 -3
- data/lib/semantic_logger/metric/signalfx.rb +3 -3
- data/lib/semantic_logger/metric/statsd.rb +7 -7
- data/lib/semantic_logger/processor.rb +7 -5
- data/lib/semantic_logger/reporters/minitest.rb +4 -4
- data/lib/semantic_logger/semantic_logger.rb +37 -12
- data/lib/semantic_logger/subscriber.rb +14 -7
- data/lib/semantic_logger/sync.rb +12 -0
- data/lib/semantic_logger/sync_processor.rb +43 -0
- data/lib/semantic_logger/utils.rb +6 -6
- data/lib/semantic_logger/version.rb +1 -1
- metadata +5 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "date"
|
2
2
|
# Forward all log messages to Elasticsearch one at a time via a HTTP post.
|
3
3
|
#
|
4
4
|
# Note:
|
@@ -50,9 +50,9 @@ module SemanticLogger
|
|
50
50
|
# application: [String]
|
51
51
|
# Name of this application to appear in log messages.
|
52
52
|
# Default: SemanticLogger.application
|
53
|
-
def initialize(index:
|
54
|
-
type:
|
55
|
-
url:
|
53
|
+
def initialize(index: "semantic_logger",
|
54
|
+
type: "log",
|
55
|
+
url: "http://localhost:9200",
|
56
56
|
**http_args,
|
57
57
|
&block)
|
58
58
|
|
@@ -64,7 +64,8 @@ module SemanticLogger
|
|
64
64
|
@log = io
|
65
65
|
else
|
66
66
|
@file_name = file_name
|
67
|
-
raise
|
67
|
+
raise "SemanticLogging::Appender::File missing mandatory parameter :file_name or :io" unless file_name
|
68
|
+
|
68
69
|
reopen
|
69
70
|
end
|
70
71
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "uri"
|
2
2
|
begin
|
3
|
-
require
|
3
|
+
require "gelf"
|
4
4
|
rescue LoadError
|
5
|
-
raise 'Gem gelf is required for logging to Graylog. Please add the gem "gelf" to your Gemfile.'
|
5
|
+
raise LoadError, 'Gem gelf is required for logging to Graylog. Please add the gem "gelf" to your Gemfile.'
|
6
6
|
end
|
7
7
|
|
8
8
|
# Forward log entries to a Graylog server.
|
@@ -82,8 +82,8 @@ module SemanticLogger
|
|
82
82
|
# application: [String]
|
83
83
|
# Name of this application to appear in log messages.
|
84
84
|
# Default: SemanticLogger.application
|
85
|
-
def initialize(url:
|
86
|
-
max_size:
|
85
|
+
def initialize(url: "udp://localhost:12201",
|
86
|
+
max_size: "WAN",
|
87
87
|
gelf_options: {},
|
88
88
|
level_map: LevelMap.new,
|
89
89
|
**args,
|
@@ -105,7 +105,9 @@ module SemanticLogger
|
|
105
105
|
@port = uri.port
|
106
106
|
@protocol = uri.scheme.to_sym
|
107
107
|
|
108
|
-
|
108
|
+
unless %i[udp tcp].include?(@protocol)
|
109
|
+
raise(ArgumentError, "Invalid protocol value: #{@protocol}. Must be :udp or :tcp")
|
110
|
+
end
|
109
111
|
|
110
112
|
gelf_options[:protocol] ||= (@protocol == :tcp ? GELF::Protocol::TCP : GELF::Protocol::UDP)
|
111
113
|
gelf_options[:facility] ||= application
|
@@ -118,10 +120,13 @@ module SemanticLogger
|
|
118
120
|
def call(log, logger)
|
119
121
|
h = default_formatter.call(log, logger)
|
120
122
|
|
121
|
-
h[:short_message] = h.delete(:message)
|
122
|
-
h[:
|
123
|
-
|
124
|
-
|
123
|
+
h[:short_message] = h.delete(:message)
|
124
|
+
if h[:short_message].nil?
|
125
|
+
h[:short_message] = log.exception.nil? ? "<no-exception-message>" : log.exception.message
|
126
|
+
end
|
127
|
+
h[:level] = logger.level_map[log.level]
|
128
|
+
h[:level_str] = log.level.to_s
|
129
|
+
h[:duration_str] = h.delete(:duration)
|
125
130
|
h
|
126
131
|
end
|
127
132
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "honeybadger"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem honeybadger is required for logging purposes. Please add the gem "honeybadger" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem honeybadger is required for logging purposes. Please add the gem "honeybadger" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# Send log messages to honeybadger
|
@@ -48,7 +48,7 @@ module SemanticLogger
|
|
48
48
|
context.delete(:exception)
|
49
49
|
::Honeybadger.notify(log.exception, context)
|
50
50
|
else
|
51
|
-
message
|
51
|
+
message = {
|
52
52
|
error_class: context.delete(:name),
|
53
53
|
error_message: context.delete(:message),
|
54
54
|
context: context
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require "socket"
|
4
|
+
require "json"
|
5
|
+
require "openssl"
|
6
6
|
|
7
7
|
# Log to any HTTP(S) server that accepts log messages in JSON form
|
8
8
|
#
|
@@ -101,27 +101,29 @@ module SemanticLogger
|
|
101
101
|
@continue_timeout = continue_timeout
|
102
102
|
|
103
103
|
# On Ruby v2.0 and greater, Net::HTTP.new already uses a persistent connection if the server allows it
|
104
|
-
@header
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
@header = {
|
105
|
+
"Accept" => "application/json",
|
106
|
+
"Content-Type" => "application/json",
|
107
|
+
"Connection" => "keep-alive",
|
108
|
+
"Keep-Alive" => "300"
|
109
109
|
}
|
110
|
-
@header[
|
110
|
+
@header["Content-Encoding"] = "gzip" if @compress
|
111
111
|
|
112
112
|
uri = URI.parse(@url)
|
113
113
|
@server = uri.host
|
114
|
-
|
114
|
+
unless @server
|
115
|
+
raise(ArgumentError, "Invalid format for :url: #{@url.inspect}. Should be similar to: 'http://hostname:port/path'")
|
116
|
+
end
|
115
117
|
|
116
118
|
@port = uri.port
|
117
119
|
@username = uri.user if !@username && uri.user
|
118
120
|
@password = uri.password if !@password && uri.password
|
119
121
|
@path = uri.path
|
120
122
|
# Path cannot be empty
|
121
|
-
@path =
|
123
|
+
@path = "/" if @path == ""
|
122
124
|
|
123
|
-
if uri.scheme ==
|
124
|
-
@ssl_options[:use_ssl]
|
125
|
+
if uri.scheme == "https"
|
126
|
+
@ssl_options[:use_ssl] = true
|
125
127
|
@ssl_options[:verify_mode] ||= OpenSSL::SSL::VERIFY_PEER
|
126
128
|
@port ||= HTTP.https_default_port
|
127
129
|
else
|
@@ -205,16 +207,16 @@ module SemanticLogger
|
|
205
207
|
end
|
206
208
|
request.basic_auth(@username, @password) if @username
|
207
209
|
response = @http.request(request)
|
208
|
-
if response.code ==
|
210
|
+
if response.code == "200" || response.code == "201"
|
209
211
|
true
|
210
212
|
else
|
211
213
|
# Failures are logged to the global semantic logger failsafe logger (Usually stderr or file)
|
212
214
|
logger.error("Bad HTTP response from: #{url} code: #{response.code}, #{response.body}")
|
213
215
|
false
|
214
216
|
end
|
215
|
-
rescue RuntimeError =>
|
217
|
+
rescue RuntimeError => e
|
216
218
|
reopen
|
217
|
-
raise
|
219
|
+
raise e
|
218
220
|
end
|
219
221
|
end
|
220
222
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "kafka"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem ruby-kafka is required for logging to Elasticsearch. Please add the gem "ruby-kafka" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem ruby-kafka is required for logging to Elasticsearch. Please add the gem "ruby-kafka" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
|
-
require
|
7
|
+
require "date"
|
8
8
|
|
9
9
|
# Forward all log messages to Apache Kafka.
|
10
10
|
#
|
@@ -115,9 +115,9 @@ module SemanticLogger
|
|
115
115
|
# metrics: [Boolean]
|
116
116
|
# Send metrics only events to kafka.
|
117
117
|
# Default: true
|
118
|
-
def initialize(seed_brokers:, client_id:
|
118
|
+
def initialize(seed_brokers:, client_id: "semantic-logger", connect_timeout: nil, socket_timeout: nil,
|
119
119
|
ssl_ca_cert: nil, ssl_client_cert: nil, ssl_client_cert_key: nil,
|
120
|
-
topic:
|
120
|
+
topic: "log_messages", partition: nil, partition_key: nil, key: nil,
|
121
121
|
delivery_threshold: 100, delivery_interval: 10,
|
122
122
|
metrics: true, **args, &block)
|
123
123
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "socket"
|
2
2
|
begin
|
3
|
-
require
|
3
|
+
require "mongo"
|
4
4
|
rescue LoadError
|
5
|
-
raise 'Gem mongo is required for logging to MongoDB. Please add the gem "mongo" v2.0 or greater to your Gemfile.'
|
5
|
+
raise LoadError, 'Gem mongo is required for logging to MongoDB. Please add the gem "mongo" v2.0 or greater to your Gemfile.'
|
6
6
|
end
|
7
7
|
|
8
8
|
module SemanticLogger
|
@@ -104,9 +104,9 @@ module SemanticLogger
|
|
104
104
|
# Name of this application to appear in log messages.
|
105
105
|
# Default: SemanticLogger.application
|
106
106
|
def initialize(uri:,
|
107
|
-
collection_name:
|
107
|
+
collection_name: "semantic_logger",
|
108
108
|
write_concern: 0,
|
109
|
-
collection_size: 1024
|
109
|
+
collection_size: 1024**3,
|
110
110
|
collection_max: nil,
|
111
111
|
**args,
|
112
112
|
&block)
|
@@ -118,7 +118,7 @@ module SemanticLogger
|
|
118
118
|
size: collection_size,
|
119
119
|
write: {w: write_concern}
|
120
120
|
}
|
121
|
-
@options[:max]
|
121
|
+
@options[:max] = collection_max if collection_max
|
122
122
|
|
123
123
|
reopen
|
124
124
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "newrelic_rpm"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem newrelic_rpm is required for logging to New Relic. Please add the gem "newrelic_rpm" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem newrelic_rpm is required for logging to New Relic. Please add the gem "newrelic_rpm" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# Send log messages to NewRelic
|
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "bunny"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem bunny is required for logging to RabbitMQ. Please add the gem "bunny" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem bunny is required for logging to RabbitMQ. Please add the gem "bunny" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# Forward all log messages to RabbitMQ.
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
# # Name of the queue in RabbitMQ where to publish the logs. This queue will be bound to "amqp.direct" exchange.
|
15
15
|
# queue: 'semantic_logger',
|
16
16
|
#
|
17
|
-
# # This host will be used for RabbitMQ connection.
|
17
|
+
# # This host will be used for RabbitMQ connection.
|
18
18
|
# # NOTE this is different than :host option which is used by the logger directly.
|
19
19
|
# rabbitmq_host: '127.0.0.1',
|
20
20
|
#
|
@@ -63,7 +63,7 @@ module SemanticLogger
|
|
63
63
|
# RabbitMQ Parameters:
|
64
64
|
#
|
65
65
|
# rabbitmq_host: [String]
|
66
|
-
# Host for AMQP connection. in Bunny this is called :host but here it has
|
66
|
+
# Host for AMQP connection. in Bunny this is called :host but here it has
|
67
67
|
# been remapped to avoid conflicting with SemanticLogger's :host param.
|
68
68
|
# Default: localhost
|
69
69
|
#
|
@@ -76,7 +76,7 @@ module SemanticLogger
|
|
76
76
|
# Default: nil
|
77
77
|
#
|
78
78
|
# more parameters supported by Bunny: http://rubybunny.info/articles/connecting.html
|
79
|
-
def initialize(queue_name:
|
79
|
+
def initialize(queue_name: "semantic_logger", rabbitmq_host: nil, metrics: false, **args, &block)
|
80
80
|
@queue_name = queue_name
|
81
81
|
@rabbitmq_args = args.dup
|
82
82
|
@rabbitmq_args[:host] = rabbitmq_host
|
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "sentry-raven"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem sentry-raven is required for logging purposes. Please add the gem "sentry-raven" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem sentry-raven is required for logging purposes. Please add the gem "sentry-raven" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# Send log messages to sentry
|
@@ -46,12 +46,12 @@ module SemanticLogger
|
|
46
46
|
# Send an error notification to sentry
|
47
47
|
def log(log)
|
48
48
|
# Ignore logs coming from Raven itself
|
49
|
-
return false if log.name ==
|
49
|
+
return false if log.name == "Raven"
|
50
50
|
|
51
|
-
context
|
52
|
-
user
|
53
|
-
tags
|
54
|
-
attrs
|
51
|
+
context = formatter.call(log, self)
|
52
|
+
user = context.delete(:user)
|
53
|
+
tags = context.delete(:tags)
|
54
|
+
attrs = {
|
55
55
|
level: context.delete(:level),
|
56
56
|
extra: context
|
57
57
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "splunk-sdk-ruby"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem splunk-sdk-ruby is required for logging to Splunk. Please add the gem "splunk-sdk-ruby" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem splunk-sdk-ruby is required for logging to Splunk. Please add the gem "splunk-sdk-ruby" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# Splunk log appender.
|
@@ -88,7 +88,7 @@ module SemanticLogger
|
|
88
88
|
# regular expression. All other messages will be ignored.
|
89
89
|
# Proc: Only include log messages where the supplied Proc returns true
|
90
90
|
# The Proc must return true or false.
|
91
|
-
def initialize(index:
|
91
|
+
def initialize(index: "main", source_type: nil, **args, &block)
|
92
92
|
@index = index
|
93
93
|
@source_type = source_type
|
94
94
|
|
@@ -120,14 +120,15 @@ module SemanticLogger
|
|
120
120
|
def call(log, logger)
|
121
121
|
h = SemanticLogger::Formatters::Raw.new.call(log, logger)
|
122
122
|
h.delete(:time)
|
123
|
-
message
|
123
|
+
message = {
|
124
124
|
source: logger.application,
|
125
125
|
host: logger.host,
|
126
126
|
time: log.time.utc.to_f,
|
127
127
|
message: h.delete(:message),
|
128
128
|
event: h
|
129
129
|
}
|
130
|
-
message[:
|
130
|
+
message[:environment] = logger.environment if logger.environment
|
131
|
+
message[:sourcetype] = source_type if source_type
|
131
132
|
message
|
132
133
|
end
|
133
134
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "json"
|
2
2
|
# Splunk log appender using the Splunk HTTP(S) listener.
|
3
3
|
#
|
4
4
|
# Use the newer, faster and more complete JSON over HTTP interface for Splunk.
|
@@ -81,13 +81,13 @@ module SemanticLogger
|
|
81
81
|
super(compress: compress, **args, &block)
|
82
82
|
|
83
83
|
# Put splunk auth token in the header of every HTTP post.
|
84
|
-
@header[
|
84
|
+
@header["Authorization"] = "Splunk #{token}"
|
85
85
|
end
|
86
86
|
|
87
87
|
# Returns [String] JSON to send to Splunk.
|
88
88
|
#
|
89
89
|
# For splunk format requirements see:
|
90
|
-
#
|
90
|
+
# https://docs.splunk.com/Documentation/Splunk/latest/Data/FormateventsforHTTPEventCollector
|
91
91
|
def call(log, logger)
|
92
92
|
h = SemanticLogger::Formatters::Raw.new(time_format: :seconds).call(log, logger)
|
93
93
|
message = {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "syslog"
|
2
|
+
require "uri"
|
3
|
+
require "socket"
|
4
4
|
# Send log messages to local syslog, or remote syslog servers over TCP or UDP.
|
5
5
|
#
|
6
6
|
# Example:
|
@@ -119,7 +119,7 @@ module SemanticLogger
|
|
119
119
|
# Example:
|
120
120
|
# # Change the warn level to LOG_NOTICE level instead of a the default of LOG_WARNING.
|
121
121
|
# SemanticLogger.add_appender(appender: :syslog, level_map: {warn: ::Syslog::LOG_NOTICE})
|
122
|
-
def initialize(url:
|
122
|
+
def initialize(url: "syslog://localhost",
|
123
123
|
facility: ::Syslog::LOG_USER,
|
124
124
|
level_map: SemanticLogger::Formatters::Syslog::LevelMap.new,
|
125
125
|
options: ::Syslog::LOG_PID | ::Syslog::LOG_CONS,
|
@@ -132,10 +132,10 @@ module SemanticLogger
|
|
132
132
|
@level_map = level_map
|
133
133
|
@url = url
|
134
134
|
uri = URI(@url)
|
135
|
-
@server = uri.host ||
|
135
|
+
@server = uri.host || "localhost"
|
136
136
|
@protocol = (uri.scheme || :syslog).to_sym
|
137
137
|
@port = uri.port || 514
|
138
|
-
@server =
|
138
|
+
@server = "localhost" if @protocol == :syslog
|
139
139
|
@tcp_client_options = tcp_client
|
140
140
|
|
141
141
|
raise "Unknown protocol #{@protocol}!" unless %i[syslog tcp udp].include?(@protocol)
|
@@ -143,17 +143,17 @@ module SemanticLogger
|
|
143
143
|
# The syslog_protocol gem is required when logging over TCP or UDP.
|
144
144
|
if %i[tcp udp].include?(@protocol)
|
145
145
|
begin
|
146
|
-
require
|
146
|
+
require "syslog_protocol"
|
147
147
|
rescue LoadError
|
148
|
-
raise
|
148
|
+
raise LoadError, "Missing gem: syslog_protocol. This gem is required when logging over TCP or UDP. To fix this error: gem install syslog_protocol"
|
149
149
|
end
|
150
150
|
|
151
151
|
# The net_tcp_client gem is required when logging over TCP.
|
152
152
|
if protocol == :tcp
|
153
153
|
begin
|
154
|
-
require
|
154
|
+
require "net/tcp_client"
|
155
155
|
rescue LoadError
|
156
|
-
raise
|
156
|
+
raise LoadError, "Missing gem: net_tcp_client. This gem is required when logging over TCP. To fix this error: gem install net_tcp_client"
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
@@ -171,7 +171,7 @@ module SemanticLogger
|
|
171
171
|
::Syslog.send(method, application, options, facility)
|
172
172
|
when :tcp
|
173
173
|
@tcp_client_options[:server] = "#{@server}:#{@port}"
|
174
|
-
@remote_syslog = Net::TCPClient.new(
|
174
|
+
@remote_syslog = Net::TCPClient.new(**@tcp_client_options)
|
175
175
|
# Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
|
176
176
|
@remote_syslog.logger = logger
|
177
177
|
when :udp
|
@@ -186,7 +186,7 @@ module SemanticLogger
|
|
186
186
|
case @protocol
|
187
187
|
when :syslog
|
188
188
|
# Since the Ruby Syslog API supports sprintf format strings, double up all existing '%'
|
189
|
-
message = formatter.call(log, self).gsub
|
189
|
+
message = formatter.call(log, self).gsub "%", "%%"
|
190
190
|
::Syslog.log @level_map[log.level], message
|
191
191
|
when :tcp
|
192
192
|
@remote_syslog.retry_on_connection_failure { @remote_syslog.write("#{formatter.call(log, self)}\r\n") }
|
@@ -1,10 +1,10 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "net/tcp_client"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem net_tcp_client is required for logging over TCP. Please add the gem "net_tcp_client" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem net_tcp_client is required for logging over TCP. Please add the gem "net_tcp_client" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
|
-
raise
|
7
|
+
raise "Net::TCPClient v2.0 or greater is required to log over TCP" unless Net::TCPClient::VERSION.to_f >= 2.0
|
8
8
|
|
9
9
|
module SemanticLogger
|
10
10
|
module Appender
|
@@ -89,7 +89,7 @@ module SemanticLogger
|
|
89
89
|
# where multiple sends are expected during a single response
|
90
90
|
# Default: true
|
91
91
|
#
|
92
|
-
# :connect_retry_count [
|
92
|
+
# :connect_retry_count [Integer]
|
93
93
|
# Number of times to retry connecting when a connection fails
|
94
94
|
# Default: 10
|
95
95
|
#
|
@@ -97,7 +97,7 @@ module SemanticLogger
|
|
97
97
|
# Number of seconds between connection retry attempts after the first failed attempt
|
98
98
|
# Default: 0.5
|
99
99
|
#
|
100
|
-
# :retry_count [
|
100
|
+
# :retry_count [Integer]
|
101
101
|
# Number of times to retry when calling #retry_on_connection_failure
|
102
102
|
# This is independent of :connect_retry_count which still applies with
|
103
103
|
# connection failures. This retry controls upto how many times to retry the
|
@@ -182,23 +182,23 @@ module SemanticLogger
|
|
182
182
|
# connect_retry_count: 5
|
183
183
|
# )
|
184
184
|
def initialize(separator: "\n",
|
185
|
-
level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false,
|
185
|
+
level: nil, formatter: nil, filter: nil, application: nil, environment: nil, host: nil, metrics: false,
|
186
186
|
**tcp_client_args, &block)
|
187
187
|
@separator = separator
|
188
188
|
@tcp_client_args = tcp_client_args
|
189
189
|
|
190
190
|
# Use the internal logger so that errors with remote logging are only written locally.
|
191
191
|
Net::TCPClient.logger = logger
|
192
|
-
Net::TCPClient.logger.name =
|
192
|
+
Net::TCPClient.logger.name = "Net::TCPClient"
|
193
193
|
|
194
|
-
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
194
|
+
super(level: level, formatter: formatter, filter: filter, application: application, environment: environment, host: host, &block)
|
195
195
|
reopen
|
196
196
|
end
|
197
197
|
|
198
198
|
# After forking an active process call #reopen to re-open the handles to resources.
|
199
199
|
def reopen
|
200
200
|
close
|
201
|
-
@tcp_client = Net::TCPClient.new(
|
201
|
+
@tcp_client = Net::TCPClient.new(**@tcp_client_args)
|
202
202
|
end
|
203
203
|
|
204
204
|
# Write the log using the specified protocol and server.
|