Justin
Justin

Reputation: 2924

logger.debug not writing to log file in Rails

I am trying to debug a model in Rails so I'm using this code: logger.debug('asasd')

However, I'm tailing the log file development.log but I'm not seeing it add to this file.

  1. I am certain this module is being run
  2. I have confirmed that runtime errors are logging to this file, and I see them when I tail.

How do I get this to work?

Upvotes: 24

Views: 24525

Answers (2)

Ryan Bigg
Ryan Bigg

Reputation: 107718

You could attempt to call flush on the logger to force it to write to this file. Usually this would happen after every request:

logger.debug("asasd")
logger.flush

There's also the auto_flushing setting on the Rails.logger instance itself:

Rails.logger.auto_flushing = true

This will make the call to logger.flush unnecessary, as Rails will automatically flush the buffered output to the log file whenever it is written to.

Upvotes: 4

Wes
Wes

Reputation: 6585

Make sure that you have set the log level to debug in environments/appropriate_env_file.rb:

config.log_level = :debug

and also make sure you are tailing the correct log file based on the environment you are running against.

Upvotes: 19

Related Questions