Hey, Paul. If you think using the Logger will work for you, then you
should probably run with it. However, I’ve got one very important
thing to say about how you are currently “debugging” your Rails code:
Use the Built-In Testing Framework!
In fact, this really goes for everyone out there doing their
“testing” and “debugging” in this manner.
Use Unit tests for your Models and /lib classes. Use Functional tests
to make sure your Controllers are doing the right thing and returning
the proper XHTML. If you want to get really fancy, you can build out
entire User Stories for your app with Integration tests.
What you don’t want to do is continue to rely on hacks like put
statements or debug log outputs for your web-based applications. They
aren’t repeatable and they are effectively impossible to document.
Writing tests is the only way to gain real confidence that your code
works. And without those tests, any refactoring you plan to do will
be that much harder to pull off, if you don’t really know what impact
those changes have on the rest of your app.
Sorry for the rant, gang, but I’ve been where Paul is. It took me a
while to “see the light” in terms of good, repeatable tests, but once
I did, I pretty much can’t imagine doing with out them. In fact, I’ve
found that I actually prefer the TDD/BDD methodology of writing the
test (or specification) first, and then writing the code that makes
that test pass. Granted, this method won’t be for everyone, but that
doesn’t mean you should skip using the /test directory. It may seem
like extra work, but everything I’ve seen has convinced me that it’s
totally worth it. Plus, I’m pretty sure I was spending just as much
time trying to debug my bad code as I do, writing the test first and
then coding to make the test pass…