Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails, logger in development mode: console vs logfile

Rails 3.0, to the extent it matters.

So, ordinarily in development mode, logger messages end up written to both development.log AND console, if you're in an interactive console.

Which is just spiffy, fine.

But something I can't figure out, if I write a logger message during the boot process (say in config.after_initialize), then this does NOT happen. The log message is in the log/development.log file, but NOT written to console. Which is annoying, the reason I'm writing something out during the boot process (echo'ing certain config) is for the developer to see it, because it aids in debugging.

Anyone have any idea what's going on here, and if there's anything I can do about it?

like image 540
jrochkind Avatar asked Oct 10 '22 20:10

jrochkind


1 Answers

All you need to do is to add a print statement before your logger call, eg:

config.after_initialize do
  print Rails.logger.info("Testing")
end

The Rails console won't automatically display anything while it's initializing, but it will display anything you pass it with a print statement. Rails.logger returns the value it writes to the log, so it really is as simple as this.

like image 70
Lucas Meyer Avatar answered Oct 14 '22 05:10

Lucas Meyer