# Using PUTS to send message to console

**URL:** <https://www.ruby-forum.com/t/using-puts-to-send-message-to-console/47913>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/using-puts-to-send-message-to-console/47913 "2005-11-12T12:49:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixelmech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@pixelmech](https://www.ruby-forum.com/u/pixelmech)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/using-puts-to-send-message-to-console/47913/1 "2005-11-12T12:49:15Z")

</div>

Hi,

I’m having trouble with my card not working correctly (not adding to  
quantity instead of adding  
full new line item) so I figured I would output some messages to the  
console to see what clause I  
am in, so I tried this:

def add\_product(product)  
item = @items.find {|i| i.product\_id == product.id}  
if item  
puts “if clause”  
item.quantity += 1  
else  
puts “else clause”  
item = LineItem.for\_product(product)  
@items \<\< item  
end  
@total\_price += product.price  
puts “end”  
end

but the puts messages are not showing up…is this not a technique that  
will work? Is there some  
other way I can write to the console?

Hopefully this is my last dumb question of the evening.

Tom

[http://www.pixelmech.com/](http://www.pixelmech.com/)

---

<div class="post-metadata">

**Author:** ![pixelmech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@pixelmech](https://www.ruby-forum.com/u/pixelmech)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/using-puts-to-send-message-to-console/47913/2 "2005-11-12T12:49:17Z")

</div>

Tom Dell’Aringa wrote:

> but the puts messages are not showing up…is this not a technique  
> that will work? Is there some other way I can write to the console?

When runnign Webrick it should “work”, ie display the output in the  
Webrick console window. When running FastCGI I hear rumours it’ll crash  
the FastCGI handler. Undefined results outside of those two scenarios, I  
guess.

A better way to go about it would probably be to add to your logfile:

logger.info(“if clause”)

---

<div class="post-metadata">

**Author:** ![pixelmech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@pixelmech](https://www.ruby-forum.com/u/pixelmech)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/using-puts-to-send-message-to-console/47913/3 "2005-11-12T12:49:17Z")

</div>

— Jakob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Tom Dell’Aringa wrote:
> 
> > but the puts messages are not showing up…is this not a technique  
> > that will work? Is there some other way I can write to the console?
> 
> When runnign Webrick it should “work”, ie display the output in the  
> Webrick console window. When running FastCGI I hear rumours it’ll crash  
> the FastCGI handler. Undefined results outside of those two scenarios, I  
> guess.

I’m not using FastCGI and am using Webrick.

> A better way to go about it would probably be to add to your logfile:
> 
> logger.info(“if clause”)

Makes sense, but I got this error when trying it:

undefined local variable or method `logger’ for #\<Cart:0x385cd88  
@total\_price=0.0, @items=[]\>

Do I have to declare logger somehow?

Tom

[http://www.pixelmech.com/](http://www.pixelmech.com/)

---

<div class="post-metadata">

**Author:** ![pixelmech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@pixelmech](https://www.ruby-forum.com/u/pixelmech)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/using-puts-to-send-message-to-console/47913/4 "2005-11-12T12:49:19Z")

</div>

puts never worked for me with webrick. Try: warn ‘blah blah’ …

---

<div class="post-metadata">

**Author:** ![pixelmech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@pixelmech](https://www.ruby-forum.com/u/pixelmech)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/using-puts-to-send-message-to-console/47913/5 "2005-11-12T12:49:19Z")

</div>

If you are in a model or controller you access the logger via the  
logger variable.  
If you are in a view you access the logger via the @logger variable.

[http://wiki.rubyonrails.com/rails/pages/HowtoAccessTheLogFile](http://wiki.rubyonrails.com/rails/pages/HowtoAccessTheLogFile)
