puts doesn't print stuff to console
33,928
Solution 1
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.
Solution 2
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::
Solution 3
Another option is to use the rails tagging logger, http://api.rubyonrails.org/classes/ActiveSupport/TaggedLogging.html.
logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
logger.tagged('BCX') { logger.info 'Stuff' } # Logs "[BCX] Stuff"
$ pow logs | grep BCX
Related videos on Youtube
Author by
trnc
Updated on July 09, 2022Comments
-
trnc almost 2 years
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!
-
JD. over 11 yearsAnd remember to create a logger object from Logger.
-
bpromas almost 8 yearsPeople keep recommending to use the logger for this, but if you use
puts
then you get to see your data immediately in the console, being printed as the code runs, meanwhile by using the logger you have to look inside a text file that doesn't auto-update depending on the text editor you use, resulting in a much clunkier user experience. -
sarnold almost 8 years@bpromas, I strongly recommend
tail -F
orless +F
for following log files. -
Andrew Koster over 4 yearsThis should be
Rails.logger.info
, notlogger.info
. The plainlogger
variable is only available in a few specific types of Rails files, such as controllers.