Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Rails logging from script/runner

Is there some way to disable all logging (whether from ActiveRecord, other parts of Rails, plugins, etc.) from a script running via script/runner? I've got a long data-loading script running, and it's generating an absurd amount of useless logging information. I'm not trying to change script/runner's environment (e.g., production, development, etc.)- the script currently needs to run in the "development" environment, and it's doing so without issue at the moment.

All I want to do is suppress all logging for the duration of the script's lifetime. From reading the docs, it looks like if I can get a handle to its Rails::Configuration I should be either able to set log_level to something other than :debug or set its logger to nil. Am I on the right track? If so, how do I get access to its Rails::Configuration object?

like image 441
Steven Bedrick Avatar asked Jun 03 '09 17:06

Steven Bedrick


1 Answers

There are a couple of ways I can think of.

1) Set the log level so high that nothing will get logged:

ActiveRecord::Base.logger.level = Logger::Severity::UNKNOWN

See Logger::Severity for more about that. UNKNOWN is the highest.

"level" is just a number, so it can be set to Logger::Severity::UNKNOWN + 1 if you feel paranoid. :)

2) Send the output to /dev/null.

ActiveRecord::Base.logger = Logger.new('/dev/null')

(I'm assuming that there is just one instance of Logger that is used by Rails, and that it's the one you get via ActiveRecord::Base.logger. If there are more of them you'd have to find them and fiddle with them also.)

If you don't like these you might find something else by reading the Logger docs.

like image 90
Jamie Flournoy Avatar answered Nov 18 '22 18:11

Jamie Flournoy