Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puts doesn't print stuff to console

i'm using POW for local rails development. i don't know why, but i can't print or puts information to my development.log. i want to puts the content of variables to console / log from my controller. any advice?

i read my logs with tail -f logs/development.log

thanks!

like image 228
trnc Avatar asked Apr 15 '11 07:04

trnc


People also ask

Does puts call TO_S Ruby?

looks familiar, right? When you use puts, Ruby calls . to_s on an object, converting it to a string then displaying on the screen. A neat thing about puts is that it adds a new line at the end of each statement so you can read it more easily.

How does puts work in Ruby?

The puts (short for "out*put s*tring") and print commands are both used to display in the console the results of evaluating Ruby code. The primary difference between them is that puts adds a new line after executing, and print does not.

What is the difference between puts and print in Ruby?

While the print method allows you to print information in the same line even multiple times, the puts method adds a new line at the end of the object. On the other hand, p is useful when you are trying to understand what your code does, e.g. when you are trying to figure out a certain error.

What does puts return in Ruby?

puts(string) in ruby writes the string value into $stdout . For example if you run ruby console in terminal, string will be written into your terminal. At the same time every method in ruby returns something and method puts returns nil .


2 Answers

Instead of puts, try logger.info(). Logging in Rails is very flexible, but it does mean that you might not be able to use the simplest tools sometimes.

like image 192
sarnold Avatar answered Sep 25 '22 03:09

sarnold


If you're doing debugging and only want to see some messages in the logs you can do the following:

Rails.logger.debug("debug::" + person.name)

and

$ pow logs | grep debug::

now you'll only see logging messages that start with debug::

like image 41
opsb Avatar answered Sep 25 '22 03:09

opsb