Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: console.log?

Tags:

ruby

I recently put console.log statements in every line of a JavaScript program and found that it's now much easier to understand. Is there a way to do that with server side code, specifically Ruby? I presume there's no way to read it in firebug, but would it be visible in irb? what console.log equivalent statements would I put in the Ruby code?

like image 826
BrainLikeADullPencil Avatar asked Sep 23 '12 07:09

BrainLikeADullPencil


People also ask

How do I create a log file in Ruby?

Since the logger library comes with Ruby, there's no need to install any gems or other libraries. To begin using the logger library, simply require 'logger' and create a new Logger object. Any messages written to the Logger object will be written to the log file.

What are rails logs?

log file. Rails uses six different log levels: debug, info, warn, error, fatal, and unknown. Each level defines how much information your application will log: Debug: diagnostic information for developers and system administrators, including database calls or inspecting object attributes.


2 Answers

puts is the equivalent in ruby.

Example

puts 'Hello World!' 
like image 147
mash Avatar answered Sep 23 '22 13:09

mash


If you are running your server in the console, you can use puts. Otherwise, you will need to write to a file, possibly via a logger (like Rails.logger.info).

like image 44
Daniel Evans Avatar answered Sep 21 '22 13:09

Daniel Evans