views:

1101

answers:

2

Hi,

What's the configuration setting to get calls to puts to be written to the Apache log file? (Using Passenger to run Rails on Apache)

Thanks

+4  A: 

Why not just log to the Rails logs? You can use Rails.logger to write to the files in your app's log directory.

Example:

Rails.logger.warn "Login failed for user #{@user.login}"

Rails has different logging levels built in (debug, info, warn, error, and fatal), and these can be specified in your environment file. So to set logging in production mode to debug level:

config.log_level = :debug
Ben
+1  A: 

I think you can "reopen" STDOUT to point to whatever RAILS_DEFAULT_LOGGER points to (your passenger log in this case).

But I'm not sure it is a Good idea, here is why:

Log is for things you want to know during normal function of your app, and is filtered differently according to your envioronment logger.debug() calls print to development.log but not to production.log, logger.error() goes, logically enough ,everywhere.

STDOUT (p, puts, printf, pretty_print...) is perfect por script/console experiments and for debugger calls, see this: post about ruby-debug for some hints on how to use "puts" or "p" to watch the values of your variable in the middle of an execution.

I hope this can help you.

Fer