LoginSignup
0
0

More than 5 years have passed since last update.

Backtraceを、おしゃれな色をつけたHTMLに変換して返す

Last updated at Posted at 2013-12-06

バックトレースをHTMLにして返す。外からはこれを使う。

def backtrace_highlight(raw_backtrace)
  raw_backtrace.collect { |trace| to_html( trace ) }.join('<br />')
end

バックトレースの行をHTMLにして返す

def to_html(backtrace_line)
  file_path, line_number, method = backtrace_line.split(':')
  if project_code?(backtrace_line)
    "<b>#{font_tag( file_path, '#E74C3C' )} #{font_tag( line_number , '#E67E22')} #{font_tag( method, '#C0392B' )}</b>"
  else
    "#{font_tag( file_path, '#95A5A6' )} #{font_tag( line_number , '#BDC3C7')} #{font_tag( method, '#7F8C8D' )}"
  end
end

fontタグを作る

def font_tag(text, color = '#000')
  %!<font color="#{color}">#{text}</font>!
end

# プロジェクトのコードかどうかを確認する
def project_code?(backtrace_line)
  backtrace_line.index(Rails.root.to_s) == 0
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0