简体   繁体   中英

Rails managing debugging code

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM