Read more

Hunt down that elusive debug message in Ruby

Henning Koch
November 26, 2010Software engineer at makandra GmbH

When you just went through a long debug-fest and infested your code with dozens of debug messages, it can be hard to find all those calls to puts and p. This note describes a hack that lets you trace those messages in your code.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Let's say you want to get rid of a console message "foobar". Copy the Undebug class below to config/initializers.rb. In the same initializer, type a line:

Undebug.trace_message('foobar')

Now run tests or whatever you need to do to to trigger that message. The console output should look like this:

Message tracing is active and slowing down the application! Disable me in /home/henning/projects/notes/config/initializers/undebug.rb:34.
foobar
Printed 'foobar' at /home/henning/projects/notes/features/step_definitions/web_steps.rb:280:in `puts'

When you're done, remember to remove that call to Undebug.trace_message because it will slow down your application.

Posted by Henning Koch to makandra dev (2010-11-26 15:12)