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
Share:
33,928

Related videos on Youtube

trnc
Author by

trnc

Updated on July 09, 2022

Comments

  • trnc
    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.
    JD. over 11 years
    And remember to create a logger object from Logger.
  • bpromas
    bpromas almost 8 years
    People 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
    sarnold almost 8 years
    @bpromas, I strongly recommend tail -F or less +F for following log files.
  • Andrew Koster
    Andrew Koster over 4 years
    This should be Rails.logger.info, not logger.info. The plain logger variable is only available in a few specific types of Rails files, such as controllers.

Related