Simple Rails Logging 3 comments

Posted by robon April 01, 2007

For long time now (~8 years) I've defined a debugging method called "yell", in many of my apps, for spitting out messages in times of heavy debugging. So far, there have been no name space conflicts, thanks to the off-the-wall name. Anyway, here what I add to any of my Rails projects where complex logic might require this type of brute-force debugging:

config/environment.rb:
def yell(msg) 
  # stupid simple logging:
  f = File.open(File.expand_path(File.dirname(__FILE__) + "/../log/yell.log"),"a") 
  f.puts msg 
  f.close
end

What do you do?


Comments

Leave a response

  1. Mike MckayApril 02, 2007 @ 01:09 AM
    I use logger. How is this better/different? I guess because you don't have to wade through all of the other messages?
  2. Rob OrsiniApril 02, 2007 @ 08:18 AM
    @Mike: Exactly. I use the built in logging facility more then this one. But when working with a hard problem where I need to quickly log complex data structures or whatever, having it in it's own file--where I see no other output--has been really helpful to me. I expect someone to mention using "grep" along with "tail -f" on the built-in log files. But this doesn't work well for multiline output. I should mention that I remove these calls a soon as I have solved whatever I was trying to figure out. These calls are not fit to leave in my code for more then a few minutes.
  3. GennadyApril 02, 2007 @ 12:50 PM
    Tried to do logging in that way. You are right, sometimes this approach works better than the standart logger.