How to Ruby logo

How to puts-debug more efficiently

03 Jul 2020

Meet LogBuddy. It has been my main debugging tool since forever. It’s the supercharged version of puts.

# ... anywhere in the code
d { goal }
# ...
d { params }
# ...
tail -f log/awesome.log

log-buddy-output

Debugged variables are:

  • named automatically
  • color-printed with the awesome print gem
  • logged in a separate file

Configuration

# Gemfile

group :development, :test do
  gem "awesome_print"
  gem "log_buddy"
end
# config/initializers/log_buddy.rb

if Rails.env.development? || Rails.env.test?
  LogBuddy.init(
    logger: Logger.new("log/awesome.log"),
    use_awesome_print: true
  )
end

I’m really amazed that a library written 12 years ago with no commits for the past 8 years could still work so flawlessly.