Skip to content

Instantly share code, notes, and snippets.

@fakefarm
Last active July 12, 2017 16:57
Show Gist options
  • Save fakefarm/02959a2a8c6ef967e8efcaed2f58a14a to your computer and use it in GitHub Desktop.
Save fakefarm/02959a2a8c6ef967e8efcaed2f58a14a to your computer and use it in GitHub Desktop.
Easy as Pry

Problem

I'm starting work on a API call which I have no idea what the data structure is or where the data I'm interested in comes into play. I work through a VM so I don't currently have access to PRY. I looked to see what kind of logging we have in place but I didn't find anything that was as easy as pry for a direct look at my issue. I also didn't want to parse through all the noise of development.log by simply using logger.info

Solution

This is what I came up with

  class Log
    def self.ger(message=nil)
      @log ||= Logger.new("#{Rails.root}/log/ger.log")
      if message.nil?
        @log.debug("willy nilly")
      else
        @log.debug("Class: " + message.class.inspect)
        @log.debug(message.inspect + "\n\n")
      end
    end
  end

use

  1. Add that file ☝️ to models/

  2. Put Log.ger(thing_of_interest) where ever you want

  3. Open up a new terminal window and tail -f log/ger.log

  4. Hopefully you'll see what you want to see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment