semantic_logger 4.7.0 → 4.7.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/lib/semantic_logger/appender/async_batch.rb +3 -3
- data/lib/semantic_logger/appender/splunk_http.rb +1 -2
- data/lib/semantic_logger/base.rb +34 -15
- data/lib/semantic_logger/formatters/color.rb +10 -6
- data/lib/semantic_logger/formatters/raw.rb +1 -1
- data/lib/semantic_logger/log.rb +41 -55
- data/lib/semantic_logger/logger.rb +1 -3
- data/lib/semantic_logger/semantic_logger.rb +1 -3
- data/lib/semantic_logger/sync_processor.rb +0 -1
- data/lib/semantic_logger/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53de576d3dea3ae2099d237648a027026469632dda0f8c3840557c648ddb0626
|
4
|
+
data.tar.gz: a2fe41e466fd682cc536f33331698a74b19d9026cde7604db93f859e70686d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9c53adbda24e55a427945f9c5953c6e53c244af0c00b4f81ba59c92c3e052d9f7306fc8941bbf0960d665757c56b4089bbc1214255fdfc5ec085fdda24b601e
|
7
|
+
data.tar.gz: 700143b4c0b34e347539b7b2fccd363683b45577a5520accd55a308175f92975ca041152ca03353f7e23ec71eb9189e6de54ff8f985eecf414d51b8900b2ad96
|
@@ -42,9 +42,9 @@ module SemanticLogger
|
|
42
42
|
lag_threshold_s: lag_threshold_s
|
43
43
|
)
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
return if appender.respond_to?(:batch)
|
46
|
+
|
47
|
+
raise(ArgumentError, "#{appender.class.name} does not support batching. It must implement #batch")
|
48
48
|
end
|
49
49
|
|
50
50
|
# Add log message for processing.
|
@@ -87,7 +87,7 @@ module SemanticLogger
|
|
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 = {
|
@@ -96,7 +96,6 @@ module SemanticLogger
|
|
96
96
|
time: h.delete(:time),
|
97
97
|
event: h
|
98
98
|
}
|
99
|
-
message[:environment] = logger.environment if logger.environment
|
100
99
|
message[:sourcetype] = source_type if source_type
|
101
100
|
message[:index] = index if index
|
102
101
|
message.to_json
|
data/lib/semantic_logger/base.rb
CHANGED
@@ -303,23 +303,42 @@ module SemanticLogger
|
|
303
303
|
end
|
304
304
|
|
305
305
|
# Log message at the specified level
|
306
|
-
def log_internal(level, index, message = nil, payload = nil, exception = nil
|
307
|
-
|
306
|
+
def log_internal(level, index, message = nil, payload = nil, exception = nil)
|
307
|
+
# Handle variable number of arguments by detecting exception object and payload hash.
|
308
|
+
if exception.nil? && payload.nil? && message.respond_to?(:backtrace) && message.respond_to?(:message)
|
309
|
+
exception = message
|
310
|
+
message = nil
|
311
|
+
elsif exception.nil? && payload && payload.respond_to?(:backtrace) && payload.respond_to?(:message)
|
312
|
+
exception = payload
|
313
|
+
payload = nil
|
314
|
+
elsif payload && !payload.is_a?(Hash)
|
315
|
+
message = message.nil? ? payload : "#{message} -- #{payload}"
|
316
|
+
payload = nil
|
317
|
+
end
|
318
|
+
|
319
|
+
log = Log.new(name, level, index)
|
308
320
|
should_log =
|
309
321
|
if payload.nil? && exception.nil? && message.is_a?(Hash)
|
310
|
-
#
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
end
|
316
|
-
elsif exception.nil? && message && payload && payload.is_a?(Hash) &&
|
317
|
-
(payload.key?(:payload) || payload.key?(:exception) || payload.key?(:metric))
|
318
|
-
log.assign(message: message, **payload)
|
322
|
+
# Everything as keyword arguments.
|
323
|
+
log.assign(**log.extract_arguments(message))
|
324
|
+
elsif exception.nil? && message && payload && payload.is_a?(Hash)
|
325
|
+
# Message with keyword arguments as the rest.
|
326
|
+
log.assign(message: message, **log.extract_arguments(payload))
|
319
327
|
else
|
320
|
-
|
328
|
+
# No keyword arguments.
|
329
|
+
log.assign(message: message, payload: payload, exception: exception)
|
321
330
|
end
|
322
331
|
|
332
|
+
# Add result of block to message or payload if not nil
|
333
|
+
if block_given?
|
334
|
+
result = yield(log)
|
335
|
+
if result.is_a?(String)
|
336
|
+
log.message = log.message.nil? ? result : "#{log.message} -- #{result}"
|
337
|
+
elsif result.is_a?(Hash)
|
338
|
+
log.assign_hash(result)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
323
342
|
# Log level may change during assign due to :on_exception_level
|
324
343
|
self.log(log) if should_log && should_log?(log)
|
325
344
|
end
|
@@ -349,10 +368,10 @@ module SemanticLogger
|
|
349
368
|
exception = e
|
350
369
|
ensure
|
351
370
|
# Must use ensure block otherwise a `return` in the yield above will skip the log entry
|
352
|
-
log
|
371
|
+
log = Log.new(name, level, index)
|
353
372
|
exception ||= params[:exception]
|
354
|
-
message
|
355
|
-
duration
|
373
|
+
message = params[:message] if params[:message]
|
374
|
+
duration =
|
356
375
|
if block_given?
|
357
376
|
1_000.0 * (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start)
|
358
377
|
else
|
@@ -1,8 +1,12 @@
|
|
1
|
-
# Load
|
1
|
+
# Load Amazing Print, or Awesome Print if available
|
2
2
|
begin
|
3
|
-
require "
|
3
|
+
require "amazing_print"
|
4
4
|
rescue LoadError
|
5
|
-
|
5
|
+
begin
|
6
|
+
require "awesome_print"
|
7
|
+
rescue LoadError
|
8
|
+
nil
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
module SemanticLogger
|
@@ -61,9 +65,9 @@ module SemanticLogger
|
|
61
65
|
#
|
62
66
|
# Parameters:
|
63
67
|
# ap: [Hash]
|
64
|
-
# Any valid
|
68
|
+
# Any valid Amazing Print option for rendering data.
|
65
69
|
# These options can also be changed be creating a `~/.aprc` file.
|
66
|
-
# See: https://github.com/
|
70
|
+
# See: https://github.com/amazing-print/amazing_print
|
67
71
|
#
|
68
72
|
# Note: The option :multiline is set to false if not supplied.
|
69
73
|
# Note: Has no effect if Awesome Print is not installed.
|
@@ -105,7 +109,7 @@ module SemanticLogger
|
|
105
109
|
def payload
|
106
110
|
return unless log.payload?
|
107
111
|
|
108
|
-
if !
|
112
|
+
if !log.payload.respond_to?(:ai)
|
109
113
|
super
|
110
114
|
else
|
111
115
|
begin
|
data/lib/semantic_logger/log.rb
CHANGED
@@ -47,6 +47,12 @@ module SemanticLogger
|
|
47
47
|
# context [Hash]
|
48
48
|
# Named contexts that were captured when the log entry was created.
|
49
49
|
class Log
|
50
|
+
# Keys passed in without a payload that will be extracted and the remainder passed into the payload.
|
51
|
+
NON_PAYLOAD_KEYS = %i[message exception backtrace exception
|
52
|
+
duration min_duration
|
53
|
+
log_exception on_exception_level
|
54
|
+
metric metric_amount dimensions].freeze
|
55
|
+
|
50
56
|
attr_accessor :level, :level_index, :name, :message, :time, :duration,
|
51
57
|
:payload, :exception, :thread_name, :backtrace,
|
52
58
|
:tags, :named_tags, :context,
|
@@ -79,20 +85,13 @@ module SemanticLogger
|
|
79
85
|
log_exception: :full,
|
80
86
|
on_exception_level: nil,
|
81
87
|
dimensions: nil)
|
82
|
-
# Elastic logging: Log when :duration exceeds :min_duration
|
83
|
-
# Except if there is an exception when it will always be logged
|
84
|
-
if duration
|
85
|
-
self.duration = duration
|
86
|
-
return false if (duration < min_duration) && exception.nil?
|
87
|
-
end
|
88
88
|
|
89
|
-
self.message
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
89
|
+
self.message = message
|
90
|
+
self.payload = payload
|
91
|
+
self.duration = duration
|
92
|
+
self.metric = metric
|
93
|
+
self.metric_amount = metric_amount
|
94
|
+
self.dimensions = dimensions
|
96
95
|
|
97
96
|
if exception
|
98
97
|
case log_exception
|
@@ -113,57 +112,45 @@ module SemanticLogger
|
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
115
|
+
# Elastic logging: Log when :duration exceeds :min_duration
|
116
|
+
# Except if there is an exception when it will always be logged
|
117
|
+
if duration
|
118
|
+
return false if (duration < min_duration) && exception.nil?
|
119
|
+
end
|
120
|
+
|
116
121
|
if backtrace
|
117
122
|
self.backtrace = Utils.extract_backtrace(backtrace)
|
118
123
|
elsif level_index >= SemanticLogger.backtrace_level_index
|
119
124
|
self.backtrace = Utils.extract_backtrace
|
120
125
|
end
|
121
126
|
|
122
|
-
if metric
|
123
|
-
self.metric = metric
|
124
|
-
self.metric_amount = metric_amount
|
125
|
-
self.dimensions = dimensions
|
126
|
-
end
|
127
|
-
|
128
127
|
true
|
129
128
|
end
|
130
129
|
|
131
|
-
# Assign
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
def assign_positional(message = nil, payload = nil, exception = nil)
|
138
|
-
# Exception being logged?
|
139
|
-
# Under JRuby a java exception is not a Ruby Exception
|
140
|
-
# Java::JavaLang::ClassCastException.new.is_a?(Exception) => false
|
141
|
-
if exception.nil? && payload.nil? && message.respond_to?(:backtrace) && message.respond_to?(:message)
|
142
|
-
exception = message
|
143
|
-
message = nil
|
144
|
-
elsif exception.nil? && payload && payload.respond_to?(:backtrace) && payload.respond_to?(:message)
|
145
|
-
exception = payload
|
146
|
-
payload = nil
|
147
|
-
elsif payload && !payload.is_a?(Hash)
|
148
|
-
message = message.nil? ? payload : "#{message} -- #{payload}"
|
149
|
-
payload = nil
|
150
|
-
end
|
151
|
-
|
152
|
-
# Add result of block as message or payload if not nil
|
153
|
-
if block_given? && (result = yield)
|
154
|
-
if result.is_a?(String)
|
155
|
-
message = message.nil? ? result : "#{message} -- #{result}"
|
156
|
-
assign(message: message, payload: payload, exception: exception)
|
157
|
-
elsif message.nil? && result.is_a?(Hash) && %i[message payload exception].any? { |k| result.key? k }
|
158
|
-
assign(**result)
|
159
|
-
elsif payload&.respond_to?(:merge)
|
160
|
-
assign(message: message, payload: payload.merge(result), exception: exception)
|
130
|
+
# Assign known keys to self, all other keys to the payload.
|
131
|
+
def assign_hash(hash)
|
132
|
+
self.payload ||= {}
|
133
|
+
hash.each_pair do |key, value|
|
134
|
+
if respond_to?("#{key}=".to_sym)
|
135
|
+
public_send("#{key}=".to_sym, value)
|
161
136
|
else
|
162
|
-
|
137
|
+
payload[key] = value
|
163
138
|
end
|
164
|
-
else
|
165
|
-
assign(message: message, payload: payload, exception: exception)
|
166
139
|
end
|
140
|
+
self.payload = nil if payload.empty?
|
141
|
+
self
|
142
|
+
end
|
143
|
+
|
144
|
+
# Extract the arguments from a Hash Payload
|
145
|
+
def extract_arguments(payload)
|
146
|
+
raise(ArgumentError, "payload must be a Hash") unless payload.is_a?(Hash)
|
147
|
+
|
148
|
+
return payload if payload.key?(:payload)
|
149
|
+
|
150
|
+
args = {}
|
151
|
+
payload.each_key { |key| args[key] = payload.delete(key) if NON_PAYLOAD_KEYS.include?(key) }
|
152
|
+
args[:payload] = payload unless payload.empty?
|
153
|
+
args
|
167
154
|
end
|
168
155
|
|
169
156
|
MAX_EXCEPTIONS_TO_UNWRAP = 5
|
@@ -178,7 +165,7 @@ module SemanticLogger
|
|
178
165
|
yield(ex, depth)
|
179
166
|
|
180
167
|
depth += 1
|
181
|
-
ex
|
168
|
+
ex =
|
182
169
|
if ex.respond_to?(:cause) && ex.cause
|
183
170
|
ex.cause
|
184
171
|
elsif ex.respond_to?(:continued_exception) && ex.continued_exception
|
@@ -280,8 +267,7 @@ module SemanticLogger
|
|
280
267
|
end
|
281
268
|
|
282
269
|
def to_h(host = SemanticLogger.host, application = SemanticLogger.application, environment = SemanticLogger.environment)
|
283
|
-
logger = Struct.new(:host, :application, :environment)
|
284
|
-
.new(host, application, environment)
|
270
|
+
logger = Struct.new(:host, :application, :environment).new(host, application, environment)
|
285
271
|
SemanticLogger::Formatters::Raw.new.call(self, logger)
|
286
272
|
end
|
287
273
|
|
@@ -63,8 +63,6 @@ module SemanticLogger
|
|
63
63
|
Logger.processor.log(log)
|
64
64
|
end
|
65
65
|
|
66
|
-
private
|
67
|
-
|
68
66
|
@processor = nil
|
69
67
|
@subscribers = nil
|
70
68
|
|
@@ -75,7 +73,7 @@ module SemanticLogger
|
|
75
73
|
begin
|
76
74
|
subscriber.call(log)
|
77
75
|
rescue Exception => e
|
78
|
-
|
76
|
+
processor.logger.error("Exception calling :on_log subscriber", e)
|
79
77
|
end
|
80
78
|
end
|
81
79
|
end
|
@@ -502,12 +502,10 @@ module SemanticLogger
|
|
502
502
|
@sync
|
503
503
|
end
|
504
504
|
|
505
|
-
private
|
506
|
-
|
507
505
|
# Initial default Level for all new instances of SemanticLogger::Logger
|
508
506
|
@default_level = :info
|
509
507
|
@default_level_index = Levels.index(@default_level)
|
510
508
|
@backtrace_level = :error
|
511
509
|
@backtrace_level_index = Levels.index(@backtrace_level)
|
512
|
-
@
|
510
|
+
@sync = false
|
513
511
|
end
|
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.7.
|
4
|
+
version: 4.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.1.2
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Feature rich logging framework, and replacement for existing Ruby & Rails
|