Alex
Alex

Reputation: 36101

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?

Upvotes: 8

Views: 5346

Answers (4)

Rajan Verma - Aarvy
Rajan Verma - Aarvy

Reputation: 2117

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')

Upvotes: 1

Muhd
Muhd

Reputation: 25566

I had a similar problem trying to use logger.debug and RAILS_DEFAULT_LOGGER.debug.

However, the following works:

Rails.logger.debug 'hello world'

Then check the logs for the corresponding environment in your app's /log folder.

Upvotes: 0

deepak
deepak

Reputation: 8080

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

Upvotes: 2

Diegol
Diegol

Reputation: 51

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.

Upvotes: 5

Related Questions