Why isn't log working (Pragmatic Programming book)

I’m working my way through the Pragmatic Programmer book on RoR.
Following their examples, I have the following code in a controller:

    begin
  	@product = Product.find(params[:id])
rescue
	flash[:notice] = "Invalid product"
	logger.error("Attempt to access invalid product #{params[:id]}")
	redirect_to :action => :index
else
  	@cart = find_cart
	@cart.add_product(@product)
end

When I cause the error, the rescue clause is clearly trapping the error
as the Invalid product error shows up, and I do get redirected back to
index. The problem is that NOTHING shows up in log/development.log.

Would someone be so kind as to tell me what I’m missing?
—Michael

index. The problem is that NOTHING shows up in log/development.log.
Michael, probably a silly question, but are you sure you are writing to
log/development.log and not another log (like test or productioin).
Plus if you are running this as a test it won’t show up in the
logs…logger is not tied into output printing for tests by default.

Adam

Adam G. wrote:

index. The problem is that NOTHING shows up in log/development.log.
Michael, probably a silly question, but are you sure you are writing to
log/development.log and not another log (like test or productioin).

I looked at the other logs to be sure, it’s not in any of them. To be
completely honest, I’m not sure what defines it as development instead
of test or production; I’m taking the book’s word that it is
development.

Plus if you are running this as a test it won’t show up in the
logs…logger is not tied into output printing for tests by default.

I’d love to have someone explain what makes it a test - and what is
needed to activate the logger. I’m trying to learn and am very grateful
for the help I’m being given.

Thanks much
—Michael

You specify the environment when you start your web server.
The default is development, so unless you said:
script/server RAILS_ENV=test|production
… you’re in development

Is the error printing out to the webserver console?
You might also try changing it to logger.info(“info message”)

– Wes

On 8/15/06, Michael S. [email protected] wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

-- Wes