semantic_logger 4.2.2 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -5
- data/lib/semantic_logger/appender/async.rb +1 -0
- data/lib/semantic_logger/appender/bugsnag.rb +2 -2
- data/lib/semantic_logger/appender/elasticsearch.rb +2 -1
- data/lib/semantic_logger/appender/file.rb +2 -2
- data/lib/semantic_logger/appender/graylog.rb +7 -3
- data/lib/semantic_logger/appender/honeybadger.rb +2 -2
- data/lib/semantic_logger/appender/http.rb +2 -6
- data/lib/semantic_logger/appender/kafka.rb +6 -2
- data/lib/semantic_logger/appender/mongodb.rb +8 -3
- data/lib/semantic_logger/appender/new_relic.rb +2 -8
- data/lib/semantic_logger/appender/sentry.rb +7 -5
- data/lib/semantic_logger/appender/splunk.rb +2 -3
- data/lib/semantic_logger/appender/splunk_http.rb +7 -5
- data/lib/semantic_logger/appender/syslog.rb +8 -4
- data/lib/semantic_logger/appender/tcp.rb +1 -1
- data/lib/semantic_logger/appender/udp.rb +6 -2
- data/lib/semantic_logger/appender/wrapper.rb +2 -2
- data/lib/semantic_logger/base.rb +1 -1
- data/lib/semantic_logger/log.rb +5 -5
- data/lib/semantic_logger/metric/new_relic.rb +2 -9
- data/lib/semantic_logger/metric/signalfx.rb +2 -17
- data/lib/semantic_logger/subscriber.rb +13 -3
- data/lib/semantic_logger/utils.rb +18 -1
- data/lib/semantic_logger/version.rb +1 -1
- data/test/appender/bugsnag_test.rb +9 -0
- data/test/appender/file_test.rb +10 -0
- data/test/appender/new_relic_test.rb +9 -0
- data/test/logger_test.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 951b7e0fc762a3801a11ccf9d3ca9cc503742453f39490ddd41112895d677fe7
|
4
|
+
data.tar.gz: 25c47bbee6b929b1f23fcc56ee6f34164066af52fb130ff238877d833538cb62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9553643ca1faf2f9d124cd05333f648f4770f1249a46ec92c21b2cb41856d9d0ee62d65cb59bf097548a10b22f91b6530fe48a2138ecdca5ee997e69fd4da3ca
|
7
|
+
data.tar.gz: 25e1949848b10937692ea12fbab2d83a090c36c09cc9a005cc64a4263b8838cba9d712e628bd4f311b58ac6b416963ae759609864935faaf0efdc73501cd397c
|
data/README.md
CHANGED
@@ -50,11 +50,7 @@ Checkout the sister project [Rocket Job](http://rocketjob.io): Ruby's missing ba
|
|
50
50
|
Fully supports Semantic Logger when running jobs in the background. Complete support for job metrics
|
51
51
|
sent via Semantic Logger to your favorite dashboards.
|
52
52
|
|
53
|
-
##
|
54
|
-
|
55
|
-
Semantic Logger is tested and supported on the following Ruby platforms:
|
56
|
-
- Ruby 2.1 and higher.
|
57
|
-
- JRuby 9.1 and higher.
|
53
|
+
## Optional Dependencies
|
58
54
|
|
59
55
|
The following gems are only required when their corresponding appenders are being used,
|
60
56
|
and are therefore not automatically included by this gem:
|
@@ -29,13 +29,13 @@ module SemanticLogger
|
|
29
29
|
# regular expression. All other messages will be ignored.
|
30
30
|
# Proc: Only include log messages where the supplied Proc returns true
|
31
31
|
# The Proc must return true or false.
|
32
|
-
def initialize(level: :error,
|
32
|
+
def initialize(level: :error, **args, &block)
|
33
33
|
raise 'Bugsnag only supports :info, :warn, or :error log levels' unless %i[info warn error fatal].include?(level)
|
34
34
|
|
35
35
|
# Replace the Bugsnag logger so that we can identify its log messages and not forward them to Bugsnag
|
36
36
|
::Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] }
|
37
37
|
|
38
|
-
super(level: level,
|
38
|
+
super(level: level, **args, &block)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Returns [Hash] of parameters to send to Bugsnag.
|
@@ -126,6 +126,7 @@ module SemanticLogger
|
|
126
126
|
filter: nil,
|
127
127
|
application: nil,
|
128
128
|
host: nil,
|
129
|
+
metrics: false,
|
129
130
|
**elasticsearch_args,
|
130
131
|
&block)
|
131
132
|
|
@@ -136,7 +137,7 @@ module SemanticLogger
|
|
136
137
|
@elasticsearch_args[:url] = url if url && !elasticsearch_args[:hosts]
|
137
138
|
@elasticsearch_args[:logger] = logger
|
138
139
|
|
139
|
-
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
140
|
+
super(level: level, formatter: formatter, filter: filter, application: application, host: host, metrics: false, &block)
|
140
141
|
reopen
|
141
142
|
end
|
142
143
|
|
@@ -59,7 +59,7 @@ module SemanticLogger
|
|
59
59
|
#
|
60
60
|
# logger = SemanticLogger['test']
|
61
61
|
# logger.info 'Hello World'
|
62
|
-
def initialize(io: nil, file_name: nil,
|
62
|
+
def initialize(io: nil, file_name: nil, **args, &block)
|
63
63
|
if io
|
64
64
|
@log = io
|
65
65
|
else
|
@@ -68,7 +68,7 @@ module SemanticLogger
|
|
68
68
|
reopen
|
69
69
|
end
|
70
70
|
|
71
|
-
super(
|
71
|
+
super(**args, &block)
|
72
72
|
end
|
73
73
|
|
74
74
|
# After forking an active process call #reopen to re-open
|
@@ -82,15 +82,19 @@ 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: 'udp://localhost:12201',
|
86
|
-
|
85
|
+
def initialize(url: 'udp://localhost:12201',
|
86
|
+
max_size: 'WAN',
|
87
|
+
gelf_options: {},
|
88
|
+
level_map: LevelMap.new,
|
89
|
+
**args,
|
90
|
+
&block)
|
87
91
|
|
88
92
|
@url = url
|
89
93
|
@max_size = max_size
|
90
94
|
@gelf_options = gelf_options
|
91
95
|
@level_map = level_map.is_a?(LevelMap) ? level_map : LevelMap.new(level_map)
|
92
96
|
|
93
|
-
super(
|
97
|
+
super(**args, &block)
|
94
98
|
reopen
|
95
99
|
end
|
96
100
|
|
@@ -37,8 +37,8 @@ module SemanticLogger
|
|
37
37
|
# application: [String]
|
38
38
|
# Name of this application to appear in log messages.
|
39
39
|
# Default: SemanticLogger.application
|
40
|
-
def initialize(level: :error,
|
41
|
-
super(level: level,
|
40
|
+
def initialize(level: :error, **args, &block)
|
41
|
+
super(level: level, **args, &block)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Send an error notification to honeybadger
|
@@ -88,11 +88,7 @@ module SemanticLogger
|
|
88
88
|
open_timeout: 2.0,
|
89
89
|
read_timeout: 1.0,
|
90
90
|
continue_timeout: 1.0,
|
91
|
-
|
92
|
-
formatter: nil,
|
93
|
-
filter: nil,
|
94
|
-
application: nil,
|
95
|
-
host: nil,
|
91
|
+
**args,
|
96
92
|
&block)
|
97
93
|
|
98
94
|
@url = url
|
@@ -133,7 +129,7 @@ module SemanticLogger
|
|
133
129
|
end
|
134
130
|
@http = nil
|
135
131
|
|
136
|
-
super(
|
132
|
+
super(**args, &block)
|
137
133
|
reopen
|
138
134
|
end
|
139
135
|
|
@@ -111,11 +111,15 @@ module SemanticLogger
|
|
111
111
|
# application: [String]
|
112
112
|
# Name of this application to appear in log messages.
|
113
113
|
# Default: SemanticLogger.application
|
114
|
+
#
|
115
|
+
# metrics: [Boolean]
|
116
|
+
# Send metrics only events to kafka.
|
117
|
+
# Default: true
|
114
118
|
def initialize(seed_brokers:, client_id: 'semantic-logger', connect_timeout: nil, socket_timeout: nil,
|
115
119
|
ssl_ca_cert: nil, ssl_client_cert: nil, ssl_client_cert_key: nil,
|
116
120
|
topic: 'log_messages', partition: nil, partition_key: nil, key: nil,
|
117
121
|
delivery_threshold: 100, delivery_interval: 10,
|
118
|
-
|
122
|
+
metrics: true, **args, &block)
|
119
123
|
|
120
124
|
@seed_brokers = seed_brokers
|
121
125
|
@client_id = client_id
|
@@ -131,7 +135,7 @@ module SemanticLogger
|
|
131
135
|
@delivery_threshold = delivery_threshold
|
132
136
|
@delivery_interval = delivery_interval
|
133
137
|
|
134
|
-
super(
|
138
|
+
super(metrics: metrics, **args, &block)
|
135
139
|
reopen
|
136
140
|
end
|
137
141
|
|
@@ -103,8 +103,13 @@ module SemanticLogger
|
|
103
103
|
# application: [String]
|
104
104
|
# Name of this application to appear in log messages.
|
105
105
|
# Default: SemanticLogger.application
|
106
|
-
def initialize(uri:,
|
107
|
-
|
106
|
+
def initialize(uri:,
|
107
|
+
collection_name: 'semantic_logger',
|
108
|
+
write_concern: 0,
|
109
|
+
collection_size: 1024 ** 3,
|
110
|
+
collection_max: nil,
|
111
|
+
**args,
|
112
|
+
&block)
|
108
113
|
|
109
114
|
@client = Mongo::Client.new(uri, logger: logger)
|
110
115
|
@collection_name = collection_name
|
@@ -120,7 +125,7 @@ module SemanticLogger
|
|
120
125
|
# Create the collection and necessary indexes
|
121
126
|
create_indexes
|
122
127
|
|
123
|
-
super(
|
128
|
+
super(**args, &block)
|
124
129
|
end
|
125
130
|
|
126
131
|
# After forking an active process call #reopen to re-open
|
@@ -31,14 +31,8 @@ module SemanticLogger
|
|
31
31
|
# regular expression. All other messages will be ignored.
|
32
32
|
# Proc: Only include log messages where the supplied Proc returns true
|
33
33
|
# The Proc must return true or false.
|
34
|
-
def initialize(level: :error,
|
35
|
-
|
36
|
-
filter: nil,
|
37
|
-
application: nil,
|
38
|
-
host: nil,
|
39
|
-
&block)
|
40
|
-
|
41
|
-
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
34
|
+
def initialize(level: :error, **args, &block)
|
35
|
+
super(level: level, **args, &block)
|
42
36
|
end
|
43
37
|
|
44
38
|
# Returns [Hash] of parameters to send to New Relic.
|
@@ -37,10 +37,10 @@ module SemanticLogger
|
|
37
37
|
# application: [String]
|
38
38
|
# Name of this application to appear in log messages.
|
39
39
|
# Default: SemanticLogger.application
|
40
|
-
def initialize(level: :error,
|
40
|
+
def initialize(level: :error, **args, &block)
|
41
41
|
# Replace the Sentry Raven logger so that we can identify its log messages and not forward them to Sentry
|
42
42
|
Raven.configure { |config| config.logger = SemanticLogger[Raven] }
|
43
|
-
super(level: level,
|
43
|
+
super(level: level, **args, &block)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Send an error notification to sentry
|
@@ -49,12 +49,14 @@ module SemanticLogger
|
|
49
49
|
return false if log.name == 'Raven'
|
50
50
|
|
51
51
|
context = formatter.call(log, self)
|
52
|
-
|
52
|
+
user = context.delete(:user)
|
53
|
+
tags = context.delete(:tags)
|
54
|
+
attrs = {
|
53
55
|
level: context.delete(:level),
|
54
|
-
user: context.delete(:user),
|
55
|
-
tags: context.delete(:tags),
|
56
56
|
extra: context
|
57
57
|
}
|
58
|
+
attrs[:user] = user if user
|
59
|
+
attrs[:tags] = tags if tags
|
58
60
|
if log.exception
|
59
61
|
context.delete(:exception)
|
60
62
|
Raven.capture_exception(log.exception, attrs)
|
@@ -88,12 +88,11 @@ 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: 'main', source_type: nil,
|
92
|
-
level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
|
91
|
+
def initialize(index: 'main', source_type: nil, **args, &block)
|
93
92
|
@index = index
|
94
93
|
@source_type = source_type
|
95
94
|
|
96
|
-
super(
|
95
|
+
super(**args, &block)
|
97
96
|
reopen
|
98
97
|
end
|
99
98
|
|
@@ -68,15 +68,17 @@ module SemanticLogger
|
|
68
68
|
# regular expression. All other messages will be ignored.
|
69
69
|
# Proc: Only include log messages where the supplied Proc returns true
|
70
70
|
# The Proc must return true or false.
|
71
|
-
def initialize(token: nil,
|
72
|
-
|
73
|
-
|
71
|
+
def initialize(token: nil,
|
72
|
+
source_type: nil,
|
73
|
+
index: nil,
|
74
|
+
compress: true,
|
75
|
+
**args,
|
76
|
+
&block)
|
74
77
|
|
75
78
|
@source_type = source_type
|
76
79
|
@index = index
|
77
80
|
|
78
|
-
super(
|
79
|
-
level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
81
|
+
super(compress: compress, **args, &block)
|
80
82
|
|
81
83
|
# Put splunk auth token in the header of every HTTP post.
|
82
84
|
@header['Authorization'] = "Splunk #{token}"
|
@@ -120,9 +120,12 @@ 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,
|
123
|
+
facility: ::Syslog::LOG_USER,
|
124
|
+
level_map: SemanticLogger::Formatters::Syslog::LevelMap.new,
|
125
|
+
options: ::Syslog::LOG_PID | ::Syslog::LOG_CONS,
|
124
126
|
tcp_client: {},
|
125
|
-
|
127
|
+
**args,
|
128
|
+
&block)
|
126
129
|
|
127
130
|
@options = options
|
128
131
|
@facility = facility
|
@@ -155,7 +158,7 @@ module SemanticLogger
|
|
155
158
|
end
|
156
159
|
end
|
157
160
|
|
158
|
-
super(
|
161
|
+
super(**args, &block)
|
159
162
|
reopen
|
160
163
|
end
|
161
164
|
|
@@ -164,7 +167,8 @@ module SemanticLogger
|
|
164
167
|
def reopen
|
165
168
|
case @protocol
|
166
169
|
when :syslog
|
167
|
-
::Syslog.
|
170
|
+
method = ::Syslog.opened? ? :reopen : :open
|
171
|
+
::Syslog.send(method, application, options, facility)
|
168
172
|
when :tcp
|
169
173
|
# Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
|
170
174
|
@tcp_client_options[:logger] = logger
|
@@ -182,7 +182,7 @@ 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,
|
185
|
+
level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false,
|
186
186
|
**tcp_client_args, &block)
|
187
187
|
@separator = separator
|
188
188
|
@tcp_client_args = tcp_client_args
|
@@ -48,6 +48,10 @@ module SemanticLogger
|
|
48
48
|
# Proc: Only include log messages where the supplied Proc returns true
|
49
49
|
# The Proc must return true or false.
|
50
50
|
#
|
51
|
+
# metrics: [Boolean]
|
52
|
+
# Send metrics only events over udp.
|
53
|
+
# Default: true
|
54
|
+
#
|
51
55
|
# Limitations:
|
52
56
|
# * UDP packet size is limited by the connected network and any routers etc
|
53
57
|
# that the message has to traverse. See https://en.wikipedia.org/wiki/Maximum_transmission_unit
|
@@ -57,11 +61,11 @@ module SemanticLogger
|
|
57
61
|
# appender: :udp,
|
58
62
|
# server: 'server:3300'
|
59
63
|
# )
|
60
|
-
def initialize(server:, udp_flags: 0,
|
64
|
+
def initialize(server:, udp_flags: 0, metrics: true, **args, &block)
|
61
65
|
@server = server
|
62
66
|
@udp_flags = udp_flags
|
63
67
|
|
64
|
-
super(
|
68
|
+
super(metrics: metrics, **args, &block)
|
65
69
|
reopen
|
66
70
|
end
|
67
71
|
|
@@ -39,7 +39,7 @@ module SemanticLogger
|
|
39
39
|
# logger.info('Hello World', some: :payload)
|
40
40
|
#
|
41
41
|
# Install the `rails_semantic_logger` gem to replace the Rails logger with Semantic Logger.
|
42
|
-
def initialize(logger:,
|
42
|
+
def initialize(logger:, **args, &block)
|
43
43
|
@logger = logger
|
44
44
|
|
45
45
|
# Check if the custom appender responds to all the log levels. For example Ruby ::Logger
|
@@ -48,7 +48,7 @@ module SemanticLogger
|
|
48
48
|
raise(ArgumentError, "Supplied logger does not implement:#{does_not_implement}. It must implement all of #{LEVELS[1..-1].inspect}")
|
49
49
|
end
|
50
50
|
|
51
|
-
super(
|
51
|
+
super(**args, &block)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Pass log calls to the underlying Rails, log4j or Ruby logger
|
data/lib/semantic_logger/base.rb
CHANGED
data/lib/semantic_logger/log.rb
CHANGED
@@ -109,9 +109,9 @@ module SemanticLogger
|
|
109
109
|
end
|
110
110
|
|
111
111
|
if backtrace
|
112
|
-
self.backtrace = Utils.
|
112
|
+
self.backtrace = Utils.extract_backtrace(backtrace)
|
113
113
|
elsif level_index >= SemanticLogger.backtrace_level_index
|
114
|
-
self.backtrace = Utils.
|
114
|
+
self.backtrace = Utils.extract_backtrace
|
115
115
|
end
|
116
116
|
|
117
117
|
if metric
|
@@ -149,7 +149,7 @@ module SemanticLogger
|
|
149
149
|
if result.is_a?(String)
|
150
150
|
message = message.nil? ? result : "#{message} -- #{result}"
|
151
151
|
assign(message: message, payload: payload, exception: exception)
|
152
|
-
elsif message.nil? && result.is_a?(Hash) && [
|
152
|
+
elsif message.nil? && result.is_a?(Hash) && %i[message payload exception].any? { |k| result.key? k }
|
153
153
|
assign(result)
|
154
154
|
elsif payload&.respond_to?(:merge)
|
155
155
|
assign(message: message, payload: payload.merge(result), exception: exception)
|
@@ -295,9 +295,9 @@ module SemanticLogger
|
|
295
295
|
(self.context ||= {})[key] = value
|
296
296
|
end
|
297
297
|
|
298
|
-
# A metric only event has a metric but no message
|
298
|
+
# A metric only event has a metric but no message or exception.
|
299
299
|
def metric_only?
|
300
|
-
metric && message.nil? && exception.nil?
|
300
|
+
metric && message.nil? && exception.nil?
|
301
301
|
end
|
302
302
|
end
|
303
303
|
end
|
@@ -37,16 +37,9 @@ module SemanticLogger
|
|
37
37
|
# regular expression. All other messages will be ignored.
|
38
38
|
# Proc: Only include log messages where the supplied Proc returns true
|
39
39
|
# The Proc must return true or false.
|
40
|
-
def initialize(prefix: 'Custom',
|
41
|
-
level: nil,
|
42
|
-
formatter: nil,
|
43
|
-
filter: nil,
|
44
|
-
application: nil,
|
45
|
-
host: nil,
|
46
|
-
&block)
|
47
|
-
|
40
|
+
def initialize(prefix: 'Custom', **args, &block)
|
48
41
|
@prefix = prefix
|
49
|
-
super(
|
42
|
+
super(**args, &block)
|
50
43
|
end
|
51
44
|
|
52
45
|
# Returns metric name to use.
|
@@ -76,28 +76,13 @@ module SemanticLogger
|
|
76
76
|
def initialize(token:,
|
77
77
|
dimensions: nil,
|
78
78
|
url: 'https://ingest.signalfx.com',
|
79
|
-
open_timeout: 2.0,
|
80
|
-
read_timeout: 1.0,
|
81
|
-
continue_timeout: 1.0,
|
82
|
-
filter: nil,
|
83
|
-
application: nil,
|
84
|
-
host: nil,
|
85
79
|
formatter: nil,
|
80
|
+
**args,
|
86
81
|
&block)
|
87
82
|
|
88
83
|
formatter ||= SemanticLogger::Formatters::Signalfx.new(token: token, dimensions: dimensions)
|
89
84
|
|
90
|
-
super(
|
91
|
-
url: url,
|
92
|
-
read_timeout: read_timeout,
|
93
|
-
open_timeout: open_timeout,
|
94
|
-
continue_timeout: continue_timeout,
|
95
|
-
filter: filter,
|
96
|
-
application: application,
|
97
|
-
host: host,
|
98
|
-
formatter: formatter,
|
99
|
-
&block
|
100
|
-
)
|
85
|
+
super(url: url, formatter: formatter, **args, &block)
|
101
86
|
|
102
87
|
@header['X-SF-TOKEN'] = token
|
103
88
|
@full_url = "#{url}/#{END_POINT}"
|
@@ -5,7 +5,7 @@ module SemanticLogger
|
|
5
5
|
class Subscriber < SemanticLogger::Base
|
6
6
|
# Every appender has its own formatter
|
7
7
|
attr_reader :formatter
|
8
|
-
attr_writer :application, :host, :logger
|
8
|
+
attr_writer :application, :host, :logger, :metrics
|
9
9
|
|
10
10
|
# Returns the current log level if set, otherwise it logs everything it receives.
|
11
11
|
def level
|
@@ -59,7 +59,7 @@ module SemanticLogger
|
|
59
59
|
|
60
60
|
# Whether this log entry meets the criteria to be logged by this appender.
|
61
61
|
def should_log?(log)
|
62
|
-
super(log) &&
|
62
|
+
super(log) && (log.metric_only? ? metrics? : true)
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
@@ -88,10 +88,15 @@ module SemanticLogger
|
|
88
88
|
# host: [String]
|
89
89
|
# Name of this host to appear in log messages.
|
90
90
|
# Default: SemanticLogger.host
|
91
|
-
|
91
|
+
#
|
92
|
+
# metrics: [Boolean]
|
93
|
+
# Whether to log metric only entries with this subscriber.
|
94
|
+
# Default: false
|
95
|
+
def initialize(level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false, &block)
|
92
96
|
self.formatter = block || formatter
|
93
97
|
@application = application
|
94
98
|
@host = host
|
99
|
+
@metrics = metrics
|
95
100
|
|
96
101
|
# Subscribers don't take a class name, so use this class name if a subscriber
|
97
102
|
# is logged to directly.
|
@@ -104,5 +109,10 @@ module SemanticLogger
|
|
104
109
|
def level_index
|
105
110
|
@level_index || 0
|
106
111
|
end
|
112
|
+
|
113
|
+
# Whether to log metric only entries with this subscriber
|
114
|
+
def metrics?
|
115
|
+
@metrics
|
116
|
+
end
|
107
117
|
end
|
108
118
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module SemanticLogger
|
2
|
+
# Internal-use only utility functions for Semantic Logger.
|
3
|
+
# Not intended for public use.
|
2
4
|
module Utils
|
3
5
|
def self.constantize_symbol(symbol, namespace = 'SemanticLogger::Appender')
|
4
6
|
klass = "#{namespace}::#{camelize(symbol.to_s)}"
|
@@ -37,11 +39,26 @@ module SemanticLogger
|
|
37
39
|
SELF_PATTERN = File.join('lib', 'semantic_logger')
|
38
40
|
|
39
41
|
# Extract the backtrace leaving out the last few Semantic Logger lines.
|
40
|
-
def self.
|
42
|
+
def self.extract_backtrace(stack = caller)
|
41
43
|
while (first = stack.first) && first.include?(SELF_PATTERN)
|
42
44
|
stack.shift
|
43
45
|
end
|
44
46
|
stack
|
45
47
|
end
|
48
|
+
|
49
|
+
# Strips off all gems and built-in ruby code paths from the top of the stack until application code is found.
|
50
|
+
def self.strip_backtrace(stack = caller)
|
51
|
+
while (first = stack.first) && system_path?(first)
|
52
|
+
stack.shift
|
53
|
+
end
|
54
|
+
stack
|
55
|
+
end
|
56
|
+
|
57
|
+
GEM_ROOT = File.expand_path('../../..', __dir__) + '/'
|
58
|
+
|
59
|
+
def self.system_path?(path)
|
60
|
+
path.start_with?(GEM_ROOT) ||
|
61
|
+
path.start_with?(RbConfig::CONFIG['rubylibdir'])
|
62
|
+
end
|
46
63
|
end
|
47
64
|
end
|
@@ -66,6 +66,15 @@ module Appender
|
|
66
66
|
assert_equal @message, hash[:message], hash
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
it 'does not send metric only notifications' do
|
71
|
+
exception = hash = nil
|
72
|
+
Bugsnag.stub(:notify, ->(exc, h) { exception = exc; hash = h }) do
|
73
|
+
@appender.debug metric: 'my/custom/metric', payload: {hello: :world}
|
74
|
+
end
|
75
|
+
assert_nil exception
|
76
|
+
assert_nil hash
|
77
|
+
end
|
69
78
|
end
|
70
79
|
end
|
71
80
|
end
|
data/test/appender/file_test.rb
CHANGED
@@ -64,6 +64,16 @@ module Appender
|
|
64
64
|
@appender.debug exc
|
65
65
|
assert_match(/\d+-\d+-\d+ \d+:\d+:\d+.\d+ D \[\d+:#{@thread_name}\] SemanticLogger::Appender::File -- Exception: StandardError: StandardError\n\n/, @io.string)
|
66
66
|
end
|
67
|
+
|
68
|
+
it 'ignores metric only messages' do
|
69
|
+
@appender.debug metric: 'my/custom/metric'
|
70
|
+
assert_equal '', @io.string
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'ignores metric only messages with payload' do
|
74
|
+
@appender.debug metric: 'my/custom/metric', payload: {hello: :world}
|
75
|
+
assert_equal '', @io.string
|
76
|
+
end
|
67
77
|
end
|
68
78
|
|
69
79
|
describe 'for each log level' do
|
@@ -66,6 +66,15 @@ module Appender
|
|
66
66
|
assert payload = params[:payload], params
|
67
67
|
assert_equal 4, payload[:key3], payload
|
68
68
|
end
|
69
|
+
|
70
|
+
it 'does not send metric only notifications' do
|
71
|
+
exception = hash = nil
|
72
|
+
NewRelic::Agent.stub(:notice_error, ->(exc, h) { exception = exc; hash = h }) do
|
73
|
+
@appender.debug metric: 'my/custom/metric', payload: {hello: :world}
|
74
|
+
end
|
75
|
+
assert_nil exception
|
76
|
+
assert_nil hash
|
77
|
+
end
|
69
78
|
end
|
70
79
|
end
|
71
80
|
end
|
data/test/logger_test.rb
CHANGED
@@ -89,10 +89,10 @@ class LoggerTest < Minitest::Test
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'logs payload from block' do
|
92
|
-
logger.send(level) { {
|
92
|
+
logger.send(level) { {'test_key1' => 'hello world', 'test_key2' => payload} }
|
93
93
|
|
94
94
|
assert log = log_message
|
95
|
-
assert_equal log.payload,
|
95
|
+
assert_equal log.payload, 'test_key1' => 'hello world', 'test_key2' => payload
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'logs payload only' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.6
|
143
|
+
rubygems_version: 2.7.6
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Feature rich logging framework, and replacement for existing Ruby & Rails
|