Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle a stack trace that does not return a known file and line number #285 #286

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/semantic_logger/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,19 @@ def process_info(thread_name_length = 30)

# 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
Expand Down
Loading