Skip to content

Commit

Permalink
Set priority on stacktrace Fixes #951
Browse files Browse the repository at this point in the history
  • Loading branch information
baelter committed Feb 16, 2025
1 parent 6b12571 commit c7a1dc0
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/lavinmq/log_formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "log"
module LavinMQ
struct JournalLogFormat < ::Log::StaticFormatter
def run
@io << '<' << severity_to_priority << '>' << ' '
severity
source
context(before: '[', after: ']')
data(before: '[', after: ']')
Expand All @@ -12,6 +12,37 @@ module LavinMQ
exception
end

private def severity : Nil
@io << '<' << severity_to_priority << '>' << ' '
end

private def exception(*, before = '\n', after = nil) : Nil
if ex = @entry.exception
@io << '\n'
inspect_with_backtrace(ex)
@io << after
end
end

private def inspect_with_backtrace(ex : Exception) : Nil
severity
@io << message << " (" << ex.class << ")\n"

ex.backtrace?.try &.each do |frame|
severity
@io.print " from "
@io.puts frame
end

if cause = ex.cause
severity
@io << "Caused by: "
inspect_with_backtrace(cause)
end

@io.flush
end

private def severity_to_priority
case @entry.severity
when ::Log::Severity::Trace then 7 # journald doesn't have trace
Expand Down

0 comments on commit c7a1dc0

Please sign in to comment.