Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails logging simply doesn't work

I'm trying to do easy logging

logger.error "ERROR!!!"

But nothing is displayed in any of the log files in the /log directory. I tried rescuing an exception, but there's no exception.

What might be the problem here?

like image 652
Alex Avatar asked Nov 10 '10 11:11

Alex


People also ask

How do you write logs in rails?

To write in the current log use the logger. (debug|info|warn|error|fatal|unknown) method from within a controller, model, or mailer: logger. debug "Person attributes hash: #{@person.

What is Rails logger debugging?

logger. debug , or in short logger. debug writes the parameter text to a log file. This log file is by default environment specific. If you are currently running rails in development environment then the log file in use is log/development.

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.

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.


3 Answers

Did you check that your production.log file has the proper rights? Try running sudo chmod 0666 on your production.log file, that might be the problem.

like image 97
Diegol Avatar answered Sep 22 '22 10:09

Diegol


there might be a:

  • permission problem. run "sudo chmod 0666" on the file. rails does show this when the server is started though
  • rails uses a BufferedLogger. try a "logger.flush" Can configure it as well.

what does "logger.class" say? what logger are you using? is the log file created? what is its permission and the permission for the log folder? are you running the server on webrick (locally ?) or passenger etc?

eg. if you say "Rails.logger = Logger.new(STDOUT)" then the logs will go to stdout rather than a file. check that as well

like image 35
deepak Avatar answered Sep 19 '22 10:09

deepak


Check output of Rails.logger. If it shows RailsStdoutLogging::StdoutLogger:0x00007fe3b5bc3540 means you are logging on shell. Change it to ActiveSupport::Logger by creating an initializer.

config/initializer/logger.rb 

Rails.logger = ActiveSupport::Logger.new('log/production.log')
like image 38
Rajan Verma - Aarvy Avatar answered Sep 19 '22 10:09

Rajan Verma - Aarvy