0

I have a rails project that is sprinkled with various debugging code and customized logging to the console.

For example a lot of it take the form like this:

CustomLogger.debug("TYPE", "My Message = " + some_variable.inspect)

Which in the backend I can either write to the log and watch a console by tailing a log files or else even package it up and display in special UI. But sprinkling this seems messy and I only really need in development context. Is there a best practice for dynamically stripping out code like this when say releasing to production environment. I am sort of looking for something in the way of a preprocessor macro like in C. Something where this common boilerplate is in the source. But is removed under certain environments.

Perhaps there are some useful meta programming techniques that would help?

I really want to globably turn on and off but also not have to comment it out repeatedly.

Maybe I just doing it wrong but caveman debugging seems to make sense to me. The downside is that it seems like I spend a lot of time writing debugging code.

1
  • The Rails logger has different log levels and the default level is configurable per environment. Can you not build on this? railscasts.com/episodes/56-the-logger Commented Nov 26, 2012 at 23:13

1 Answer 1

1

In your config/environment/production.rb file, add something like

config.log_level = :info

This will ignore :debug level log entries when in production.

Suggested Reading: http://guides.rubyonrails.org/debugging_rails_applications.html#log-levels

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.