lib/semantic_logger/log.rb in semantic_logger-4.15.0 vs lib/semantic_logger/log.rb in semantic_logger-4.16.0
- old
+ new
@@ -142,11 +142,13 @@
# Extract the arguments from a Hash Payload
def extract_arguments(payload, message = nil)
raise(ArgumentError, "payload must be a Hash") unless payload.is_a?(Hash)
message = nil if message == ""
- return payload if payload.key?(:payload)
+ if payload.key?(:payload)
+ return message ? payload.merge(message: message) : payload
+ end
new_payload = {}
args = {}
payload.each_pair do |key, value|
# Supplied message takes precedence
@@ -246,18 +248,22 @@
CALLER_REGEXP = /^(.*):(\d+).*/.freeze
# Extract the filename and line number from the last entry in the supplied backtrace
def extract_file_and_line(stack, short_name = false)
+ return unless stack&.size&.positive?
+
match = CALLER_REGEXP.match(stack.first)
+ return unless match
+
[short_name ? File.basename(match[1]) : match[1], match[2].to_i]
end
# Returns [String, String] the file_name and line_number from the backtrace supplied
# in either the backtrace or exception
def file_name_and_line(short_name = false)
stack = backtrace || exception&.backtrace
- extract_file_and_line(stack, short_name) if stack&.size&.positive?
+ extract_file_and_line(stack, short_name)
end
# Strip the standard Rails colorizing from the logged message
def cleansed_message
message.to_s.gsub(/(\e(\[([\d;]*[mz]?))?)?/, "").strip