Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Rails.logger.debug print hash more readable

I'm using Rails.logger.debug print variables for debugging purposes. The issue is it prints hashes in an impossible to read format (can't distinguish keys from values). For example, I add the following lines to my code base

#code_base.rb
 my_hash = {'a' => 'alligator', 'b'=>'baboon'}
 Rails.logger.debug my_hash

Then I launch my rails app and type

  tail -f log/development.log 

But when my_hash gets printed, it looks like

  bbaboonaalligator

The key and values are scrunched up, making it impossible to parse. Do you guys know what I should do to fix this?

like image 229
User314159 Avatar asked Jul 08 '13 17:07

User314159


1 Answers

Nevermind, I found the answer to my own question. I need to use

my_hash = {'a' => 'alligator', 'b'=>'baboon'}
Rails.logger.debug "#{my_hash.inspect}"

Then, it looks like

{"b"=>"baboon", "a"=>"aligator"}
like image 160
User314159 Avatar answered Sep 19 '22 20:09

User314159