Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thin server: ouput rails application logs to console, as 'rails s' does

I need to run thin start or thin -ssl ... start within the root of my rails app, and see the application logs output to the console, similar to what rails s does

like image 439
Benj Avatar asked Mar 03 '14 22:03

Benj


People also ask

Can you console log in rails?

One of the best tools in a rails developers arsenal is the rails console, being extremely useful for brainstorming, debugging, and testing. Having it log active record queries directly to the console can improve readability and convenience over looking through the development logs to see what SQL queries have been run.

How do I view rails logs?

In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.

How does rails Logger work?

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. So if you open up that folder you'll see a development. log and test.

What is the log to check for errors in rails?

Rails uses six different log levels: debug, info, warn, error, fatal, and unknown. Each level defines how much information your application will log: Debug: diagnostic information for developers and system administrators, including database calls or inspecting object attributes.


1 Answers

In config.ru file, located at the root of your application, add the following code, just before the line run Rails.application:

console = ActiveSupport::Logger.new($stdout)
console.formatter = Rails.logger.formatter
console.level = Rails.logger.level

Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
like image 112
Benj Avatar answered Sep 28 '22 18:09

Benj