Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the rails logger to use standard out from rake tasks (rails2)

When I do

Rails.logger.debug "hello world" from within my rake tasks I want it to log to standard out.

How do I set the rails logger to Logger.new(STDOUT) from within my rake task?

I want my app to log to the file when coming through controllers etc, just want the rake tasks to go to std out because of the way my monitoring is setup.

I was thinking I could define another environment and use that config, but probably overkill, I want all the same environment vars in each env, just want to change the location of my log destination.

For now I have a log helper that uses puts, but I want to take advantage of the formatting of rails logs and the buffering.

like image 594
Joelio Avatar asked Jan 25 '11 23:01

Joelio


People also ask

What is Rake in ror?

Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.

How to write Rake task in Rails?

We can also write our custom Rake tasks in Rails environment by creating files with . rake extension in ./lib/tasks. It's a common practice after cloning a repository for the first time, to run ./bin/setup, in order to automatically fetch all the libraries, create db, seed data etc.

Where does Rails logger write to?

Rails is configured to create separate log files for each of the three default environments: development, test and production. By default it puts these log files in the log/ directory of your project.

What is logger in Rails?

The Logger class provides a simple but sophisticated logging utility that you can use to output messages. The messages have associated levels, such as INFO or ERROR that indicate their importance. You can then give the Logger a level, and only messages at that level or higher will be printed. The levels are: UNKNOWN.


1 Answers

I just did Rails.logger = Logger.new(STDOUT) and that also worked (rails3)

like image 121
singpolyma Avatar answered Oct 11 '22 11:10

singpolyma