semantic_logger 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/lib/semantic_logger/ansi_colors.rb +11 -12
- data/lib/semantic_logger/appender.rb +4 -5
- data/lib/semantic_logger/appender/async.rb +24 -16
- data/lib/semantic_logger/appender/async_batch.rb +1 -4
- data/lib/semantic_logger/appender/bugsnag.rb +67 -63
- data/lib/semantic_logger/appender/elasticsearch.rb +154 -157
- data/lib/semantic_logger/appender/elasticsearch_http.rb +59 -55
- data/lib/semantic_logger/appender/file.rb +1 -3
- data/lib/semantic_logger/appender/graylog.rb +114 -110
- data/lib/semantic_logger/appender/honeybadger.rb +54 -51
- data/lib/semantic_logger/appender/http.rb +194 -190
- data/lib/semantic_logger/appender/kafka.rb +152 -149
- data/lib/semantic_logger/appender/mongodb.rb +3 -3
- data/lib/semantic_logger/appender/new_relic.rb +52 -49
- data/lib/semantic_logger/appender/sentry.rb +59 -54
- data/lib/semantic_logger/appender/splunk.rb +108 -103
- data/lib/semantic_logger/appender/splunk_http.rb +82 -79
- data/lib/semantic_logger/appender/syslog.rb +4 -5
- data/lib/semantic_logger/appender/tcp.rb +8 -29
- data/lib/semantic_logger/appender/udp.rb +2 -3
- data/lib/semantic_logger/appender/wrapper.rb +2 -2
- data/lib/semantic_logger/base.rb +18 -16
- data/lib/semantic_logger/concerns/compatibility.rb +0 -1
- data/lib/semantic_logger/core_ext/thread.rb +0 -1
- data/lib/semantic_logger/formatters.rb +3 -5
- data/lib/semantic_logger/formatters/base.rb +2 -3
- data/lib/semantic_logger/formatters/color.rb +29 -12
- data/lib/semantic_logger/formatters/default.rb +10 -10
- data/lib/semantic_logger/formatters/json.rb +0 -2
- data/lib/semantic_logger/formatters/one_line.rb +2 -2
- data/lib/semantic_logger/formatters/raw.rb +7 -10
- data/lib/semantic_logger/formatters/signalfx.rb +3 -5
- data/lib/semantic_logger/formatters/syslog.rb +2 -3
- data/lib/semantic_logger/formatters/syslog_cee.rb +2 -3
- data/lib/semantic_logger/jruby/garbage_collection_logger.rb +8 -5
- data/lib/semantic_logger/log.rb +17 -17
- data/lib/semantic_logger/loggable.rb +6 -9
- data/lib/semantic_logger/logger.rb +0 -1
- data/lib/semantic_logger/metric/new_relic.rb +58 -55
- data/lib/semantic_logger/metric/signalfx.rb +108 -106
- data/lib/semantic_logger/metric/statsd.rb +2 -3
- data/lib/semantic_logger/processor.rb +9 -9
- data/lib/semantic_logger/semantic_logger.rb +50 -30
- data/lib/semantic_logger/subscriber.rb +0 -1
- data/lib/semantic_logger/utils.rb +37 -37
- data/lib/semantic_logger/version.rb +2 -2
- data/test/appender/async_batch_test.rb +0 -1
- data/test/appender/async_test.rb +0 -1
- data/test/appender/bugsnag_test.rb +7 -8
- data/test/appender/elasticsearch_http_test.rb +5 -6
- data/test/appender/elasticsearch_test.rb +14 -10
- data/test/appender/file_test.rb +5 -6
- data/test/appender/graylog_test.rb +8 -8
- data/test/appender/honeybadger_test.rb +6 -7
- data/test/appender/http_test.rb +4 -5
- data/test/appender/kafka_test.rb +5 -6
- data/test/appender/mongodb_test.rb +11 -13
- data/test/appender/new_relic_test.rb +8 -9
- data/test/appender/newrelic_rpm.rb +1 -1
- data/test/appender/sentry_test.rb +7 -8
- data/test/appender/splunk_http_test.rb +4 -4
- data/test/appender/splunk_test.rb +1 -3
- data/test/appender/syslog_test.rb +3 -5
- data/test/appender/tcp_test.rb +4 -5
- data/test/appender/udp_test.rb +4 -5
- data/test/appender/wrapper_test.rb +2 -3
- data/test/concerns/compatibility_test.rb +0 -1
- data/test/debug_as_trace_logger_test.rb +0 -1
- data/test/formatters/color_test.rb +5 -6
- data/test/formatters/default_test.rb +16 -17
- data/test/formatters/one_line_test.rb +1 -2
- data/test/formatters/signalfx_test.rb +8 -11
- data/test/formatters_test.rb +3 -3
- data/test/in_memory_appender.rb +0 -1
- data/test/in_memory_appender_helper.rb +1 -1
- data/test/in_memory_batch_appender.rb +0 -1
- data/test/in_memory_metrics_appender.rb +0 -1
- data/test/loggable_test.rb +2 -3
- data/test/logger_test.rb +11 -14
- data/test/measure_test.rb +13 -15
- data/test/metric/new_relic_test.rb +2 -3
- data/test/metric/signalfx_test.rb +4 -5
- data/test/semantic_logger_test.rb +28 -3
- data/test/test_helper.rb +6 -7
- metadata +34 -34
@@ -12,89 +12,92 @@ require 'json'
|
|
12
12
|
# url: 'http://localhost:8080',
|
13
13
|
# token: '70CA900C-3D7E-42A4-9C79-7975D1C422A8'
|
14
14
|
# )
|
15
|
-
|
16
|
-
|
15
|
+
module SemanticLogger
|
16
|
+
module Appender
|
17
|
+
class SplunkHttp < SemanticLogger::Appender::Http
|
18
|
+
attr_accessor :source_type, :index
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
20
|
+
# Create Splunk appender over persistent HTTP(S)
|
21
|
+
#
|
22
|
+
# Parameters:
|
23
|
+
# token: [String]
|
24
|
+
# Token created in Splunk for this HTTP Appender
|
25
|
+
# Mandatory.
|
26
|
+
#
|
27
|
+
# source_type: [String]
|
28
|
+
# Optional: Source type to display in Splunk
|
29
|
+
#
|
30
|
+
# index: [String]
|
31
|
+
# Optional: Name of a valid index for this message in Splunk.
|
32
|
+
#
|
33
|
+
# url: [String]
|
34
|
+
# Valid URL to post to.
|
35
|
+
# Example: http://example.com
|
36
|
+
# To enable SSL include https in the URL.
|
37
|
+
# Example: https://example.com
|
38
|
+
# verify_mode will default: OpenSSL::SSL::VERIFY_PEER
|
39
|
+
#
|
40
|
+
# application: [String]
|
41
|
+
# Name of this application to appear in log messages.
|
42
|
+
# Default: SemanticLogger.application
|
43
|
+
#
|
44
|
+
# host: [String]
|
45
|
+
# Name of this host to appear in log messages.
|
46
|
+
# Default: SemanticLogger.host
|
47
|
+
#
|
48
|
+
# compress: [true|false]
|
49
|
+
# Splunk supports HTTP Compression, enable by default.
|
50
|
+
# Default: true
|
51
|
+
#
|
52
|
+
# ssl: [Hash]
|
53
|
+
# Specific SSL options: For more details see NET::HTTP.start
|
54
|
+
# ca_file, ca_path, cert, cert_store, ciphers, key, open_timeout, read_timeout, ssl_timeout,
|
55
|
+
# ssl_version, use_ssl, verify_callback, verify_depth and verify_mode.
|
56
|
+
#
|
57
|
+
# level: [:trace | :debug | :info | :warn | :error | :fatal]
|
58
|
+
# Override the log level for this appender.
|
59
|
+
# Default: SemanticLogger.default_level
|
60
|
+
#
|
61
|
+
# formatter: [Object|Proc]
|
62
|
+
# An instance of a class that implements #call, or a Proc to be used to format
|
63
|
+
# the output from this appender
|
64
|
+
# Default: Use the built-in formatter (See: #call)
|
65
|
+
#
|
66
|
+
# filter: [Regexp|Proc]
|
67
|
+
# RegExp: Only include log messages where the class name matches the supplied.
|
68
|
+
# regular expression. All other messages will be ignored.
|
69
|
+
# Proc: Only include log messages where the supplied Proc returns true
|
70
|
+
# The Proc must return true or false.
|
71
|
+
def initialize(token: nil, source_type: nil, index: nil,
|
72
|
+
url:, compress: true, ssl: {}, open_timeout: 2.0, read_timeout: 1.0, continue_timeout: 1.0,
|
73
|
+
level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
+
@source_type = source_type
|
76
|
+
@index = index
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
+
super(url: url, compress: compress, ssl: ssl, read_timeout: read_timeout, open_timeout: open_timeout, continue_timeout: continue_timeout,
|
79
|
+
level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
# Put splunk auth token in the header of every HTTP post.
|
82
|
+
@header['Authorization'] = "Splunk #{token}"
|
83
|
+
end
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
85
|
+
# Returns [String] JSON to send to Splunk.
|
86
|
+
#
|
87
|
+
# For splunk format requirements see:
|
88
|
+
# http://dev.splunk.com/view/event-collector/SP-CAAAE6P
|
89
|
+
def call(log, logger)
|
90
|
+
h = SemanticLogger::Formatters::Raw.new(time_format: :seconds).call(log, logger)
|
91
|
+
message = {
|
92
|
+
source: logger.application,
|
93
|
+
host: logger.host,
|
94
|
+
time: h.delete(:time),
|
95
|
+
event: h
|
96
|
+
}
|
97
|
+
message[:source_type] = source_type if source_type
|
98
|
+
message[:index] = index if index
|
99
|
+
message.to_json
|
100
|
+
end
|
101
|
+
end
|
98
102
|
end
|
99
|
-
|
100
103
|
end
|
@@ -120,7 +120,7 @@ module SemanticLogger
|
|
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
122
|
def initialize(url: 'syslog://localhost',
|
123
|
-
facility: ::Syslog::LOG_USER, level_map: SemanticLogger::Formatters::Syslog::LevelMap.new, options: ::Syslog::LOG_PID
|
123
|
+
facility: ::Syslog::LOG_USER, level_map: SemanticLogger::Formatters::Syslog::LevelMap.new, options: ::Syslog::LOG_PID| ::Syslog::LOG_CONS,
|
124
124
|
tcp_client: {},
|
125
125
|
level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
|
126
126
|
|
@@ -135,10 +135,10 @@ module SemanticLogger
|
|
135
135
|
@server = 'localhost' if @protocol == :syslog
|
136
136
|
@tcp_client_options = tcp_client
|
137
137
|
|
138
|
-
raise "Unknown protocol #{@protocol}!" unless [
|
138
|
+
raise "Unknown protocol #{@protocol}!" unless %i[syslog tcp udp].include?(@protocol)
|
139
139
|
|
140
140
|
# The syslog_protocol gem is required when logging over TCP or UDP.
|
141
|
-
if [
|
141
|
+
if %i[tcp udp].include?(@protocol)
|
142
142
|
begin
|
143
143
|
require 'syslog_protocol'
|
144
144
|
rescue LoadError
|
@@ -196,7 +196,7 @@ module SemanticLogger
|
|
196
196
|
|
197
197
|
# Flush is called by the semantic_logger during shutdown.
|
198
198
|
def flush
|
199
|
-
@remote_syslog.flush if @remote_syslog
|
199
|
+
@remote_syslog.flush if @remote_syslog&.respond_to?(:flush)
|
200
200
|
end
|
201
201
|
|
202
202
|
# Returns [SemanticLogger::Formatters::Base] default formatter for this Appender depending on the protocal selected
|
@@ -208,7 +208,6 @@ module SemanticLogger
|
|
208
208
|
SemanticLogger::Formatters::Syslog.new(facility: facility, level_map: level_map)
|
209
209
|
end
|
210
210
|
end
|
211
|
-
|
212
211
|
end
|
213
212
|
end
|
214
213
|
end
|
@@ -181,31 +181,11 @@ module SemanticLogger
|
|
181
181
|
# connect_retry_interval: 0.1,
|
182
182
|
# connect_retry_count: 5
|
183
183
|
# )
|
184
|
-
def initialize(
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block
|
190
|
-
)
|
191
|
-
@separator = separator
|
192
|
-
@options = {
|
193
|
-
server: server,
|
194
|
-
servers: servers,
|
195
|
-
policy: policy,
|
196
|
-
buffered: buffered,
|
197
|
-
#keepalive: keepalive,
|
198
|
-
connect_timeout: connect_timeout,
|
199
|
-
read_timeout: read_timeout,
|
200
|
-
write_timeout: write_timeout,
|
201
|
-
connect_retry_count: connect_retry_count,
|
202
|
-
retry_count: retry_count,
|
203
|
-
connect_retry_interval: connect_retry_interval,
|
204
|
-
close_on_error: close_on_error,
|
205
|
-
on_connect: on_connect,
|
206
|
-
proxy_server: proxy_server,
|
207
|
-
ssl: ssl
|
208
|
-
}
|
184
|
+
def initialize(separator: "\n",
|
185
|
+
level: nil, formatter: nil, filter: nil, application: nil, host: nil,
|
186
|
+
**tcp_client_args, &block)
|
187
|
+
@separator = separator
|
188
|
+
@tcp_client_args = tcp_client_args
|
209
189
|
|
210
190
|
# Use the internal logger so that errors with remote logging are only written locally.
|
211
191
|
Net::TCPClient.logger = logger
|
@@ -218,7 +198,7 @@ module SemanticLogger
|
|
218
198
|
# After forking an active process call #reopen to re-open the handles to resources.
|
219
199
|
def reopen
|
220
200
|
close
|
221
|
-
@tcp_client = Net::TCPClient.new(@
|
201
|
+
@tcp_client = Net::TCPClient.new(@tcp_client_args)
|
222
202
|
end
|
223
203
|
|
224
204
|
# Write the log using the specified protocol and server.
|
@@ -232,12 +212,12 @@ module SemanticLogger
|
|
232
212
|
|
233
213
|
# Flush is called by the semantic_logger during shutdown.
|
234
214
|
def flush
|
235
|
-
@tcp_client
|
215
|
+
@tcp_client&.flush
|
236
216
|
end
|
237
217
|
|
238
218
|
# Close is called during shutdown, or with reopen
|
239
219
|
def close
|
240
|
-
@tcp_client
|
220
|
+
@tcp_client&.close
|
241
221
|
end
|
242
222
|
|
243
223
|
private
|
@@ -246,7 +226,6 @@ module SemanticLogger
|
|
246
226
|
def default_formatter
|
247
227
|
SemanticLogger::Formatters::Json.new
|
248
228
|
end
|
249
|
-
|
250
229
|
end
|
251
230
|
end
|
252
231
|
end
|
@@ -82,12 +82,12 @@ module SemanticLogger
|
|
82
82
|
|
83
83
|
# Flush is called by the semantic_logger during shutdown.
|
84
84
|
def flush
|
85
|
-
@socket
|
85
|
+
@socket&.flush
|
86
86
|
end
|
87
87
|
|
88
88
|
# Close is called during shutdown, or with reopen
|
89
89
|
def close
|
90
|
-
@socket
|
90
|
+
@socket&.close
|
91
91
|
end
|
92
92
|
|
93
93
|
private
|
@@ -96,7 +96,6 @@ module SemanticLogger
|
|
96
96
|
def default_formatter
|
97
97
|
SemanticLogger::Formatters::Json.new
|
98
98
|
end
|
99
|
-
|
100
99
|
end
|
101
100
|
end
|
102
101
|
end
|
@@ -43,7 +43,8 @@ module SemanticLogger
|
|
43
43
|
@logger = logger
|
44
44
|
|
45
45
|
# Check if the custom appender responds to all the log levels. For example Ruby ::Logger
|
46
|
-
|
46
|
+
does_not_implement = LEVELS[1..-1].find { |i| !@logger.respond_to?(i) }
|
47
|
+
if does_not_implement
|
47
48
|
raise(ArgumentError, "Supplied logger does not implement:#{does_not_implement}. It must implement all of #{LEVELS[1..-1].inspect}")
|
48
49
|
end
|
49
50
|
|
@@ -63,7 +64,6 @@ module SemanticLogger
|
|
63
64
|
def flush
|
64
65
|
@logger.flush if @logger.respond_to?(:flush)
|
65
66
|
end
|
66
|
-
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/lib/semantic_logger/base.rb
CHANGED
@@ -23,7 +23,7 @@ module SemanticLogger
|
|
23
23
|
@level_index = nil
|
24
24
|
@level = nil
|
25
25
|
else
|
26
|
-
@level_index = SemanticLogger.level_to_index
|
26
|
+
@level_index = SemanticLogger.send(:level_to_index, level)
|
27
27
|
@level = SemanticLogger.send(:index_to_level, @level_index)
|
28
28
|
end
|
29
29
|
end
|
@@ -78,7 +78,7 @@ module SemanticLogger
|
|
78
78
|
# logger.info("Parsing received XML", exc)
|
79
79
|
#
|
80
80
|
SemanticLogger::LEVELS.each_with_index do |level, index|
|
81
|
-
class_eval
|
81
|
+
class_eval <<~METHODS, __FILE__, __LINE__ + 1
|
82
82
|
def #{level}(message=nil, payload=nil, exception=nil, &block)
|
83
83
|
if level_index <= #{index}
|
84
84
|
log_internal(:#{level}, #{index}, message, payload, exception, &block)
|
@@ -107,7 +107,7 @@ module SemanticLogger
|
|
107
107
|
block.call(params) if block
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
110
|
+
METHODS
|
111
111
|
end
|
112
112
|
|
113
113
|
# Dynamically supply the log level with every measurement call
|
@@ -115,13 +115,13 @@ module SemanticLogger
|
|
115
115
|
index = SemanticLogger.level_to_index(level)
|
116
116
|
if level_index <= index
|
117
117
|
measure_internal(level, index, message, params, &block)
|
118
|
-
|
119
|
-
|
118
|
+
elsif block
|
119
|
+
yield(params)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
# Backward compatibility
|
124
|
-
|
124
|
+
alias benchmark measure
|
125
125
|
|
126
126
|
# Log a thread backtrace
|
127
127
|
def backtrace(thread: Thread.current,
|
@@ -150,7 +150,11 @@ module SemanticLogger
|
|
150
150
|
message << backtrace.join("\n")
|
151
151
|
end
|
152
152
|
|
153
|
-
if log.assign(message:
|
153
|
+
if log.assign(message: message,
|
154
|
+
backtrace: backtrace,
|
155
|
+
payload: payload,
|
156
|
+
metric: metric,
|
157
|
+
metric_amount: metric_amount) && !filtered?(log)
|
154
158
|
self.log(log)
|
155
159
|
else
|
156
160
|
false
|
@@ -196,7 +200,7 @@ module SemanticLogger
|
|
196
200
|
end
|
197
201
|
|
198
202
|
# :nodoc:
|
199
|
-
|
203
|
+
alias with_tags tagged
|
200
204
|
|
201
205
|
# :nodoc:
|
202
206
|
def tags
|
@@ -243,8 +247,8 @@ module SemanticLogger
|
|
243
247
|
end
|
244
248
|
|
245
249
|
# Write log data to underlying data storage
|
246
|
-
def log(
|
247
|
-
raise NotImplementedError
|
250
|
+
def log(_log_)
|
251
|
+
raise NotImplementedError, 'Logging Appender must implement #log(log)'
|
248
252
|
end
|
249
253
|
|
250
254
|
# Whether this log entry meets the criteria to be logged by this appender.
|
@@ -298,7 +302,7 @@ module SemanticLogger
|
|
298
302
|
return false if @filter.nil?
|
299
303
|
|
300
304
|
if @filter.is_a?(Regexp)
|
301
|
-
(@filter =~ log.name)
|
305
|
+
(@filter =~ log.name).nil?
|
302
306
|
elsif @filter.is_a?(Proc)
|
303
307
|
@filter.call(log) != true
|
304
308
|
else
|
@@ -317,7 +321,7 @@ module SemanticLogger
|
|
317
321
|
should_log =
|
318
322
|
if payload.nil? && exception.nil? && message.is_a?(Hash)
|
319
323
|
# Check if someone just logged a hash payload instead of meaning to call semantic logger
|
320
|
-
if message.
|
324
|
+
if message.key?(:message) || message.key?(:payload) || message.key?(:exception) || message.key?(:metric)
|
321
325
|
log.assign(message)
|
322
326
|
else
|
323
327
|
log.assign_positional(nil, message, nil, &block)
|
@@ -343,7 +347,7 @@ module SemanticLogger
|
|
343
347
|
begin
|
344
348
|
if block_given?
|
345
349
|
result =
|
346
|
-
if silence_level = params[:silence]
|
350
|
+
if (silence_level = params[:silence])
|
347
351
|
# In case someone accidentally sets `silence: true` instead of `silence: :error`
|
348
352
|
silence_level = :error if silence_level == true
|
349
353
|
silence(silence_level) { yield(params) }
|
@@ -395,8 +399,7 @@ module SemanticLogger
|
|
395
399
|
min_duration:,
|
396
400
|
metric:,
|
397
401
|
log_exception:,
|
398
|
-
on_exception_level
|
399
|
-
&block)
|
402
|
+
on_exception_level:)
|
400
403
|
|
401
404
|
# Ignores filter, silence, payload
|
402
405
|
exception = nil
|
@@ -423,6 +426,5 @@ module SemanticLogger
|
|
423
426
|
raise exception if exception
|
424
427
|
end
|
425
428
|
end
|
426
|
-
|
427
429
|
end
|
428
430
|
end
|