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.
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.
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.
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.
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.
I just did Rails.logger = Logger.new(STDOUT)
and that also worked (rails3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With