Awesomeness
Awesomeness

Reputation: 2631

How do I get logger to work in IRB?

I am trying to work in IRB to get an understanding for some code that I found online.

I am able to require a file which eventually imports this file:

module LinkedIn
  module Api

    logger.debug "....7"

    module QueryMethods

      logger.debug "....6"

      def profile(options={})
        logger.debug "....1"
        path = person_path(options)
        simple_query(path, options)
      end

      def connections(options={})
        path = "#{person_path(options)}/connections"
        simple_query(path, options)
      end

      def network_updates(options={})
        path = "#{person_path(options)}/network/updates"
        simple_query(path, options)
      end

      def company(options = {})
        path   = company_path(options)
        simple_query(path, options)
      end

      def test(options = {})
         logger.debug "helllllooooo"
      end

      private
      logger.debug "....2"
        def simple_query(path, options={})
          logger.debug "....3"
          fields = options.delete(:fields) || LinkedIn.default_profile_fields

          if options.delete(:public)
            path +=":public"
          elsif fields
            path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
          end

          headers = options.delete(:headers) || {}
          params  = options.map { |k,v| "#{k}=#{v}" }.join("&")
          path   += "?#{params}" if not params.empty?

          Mash.from_json(get(path, headers))
        end

        def person_path(options)
          logger.debug "....4"
          path = "/people/"
          if id = options.delete(:id)
            path += "id=#{id}"
          elsif url = options.delete(:url)
            path += "url=#{CGI.escape(url)}"
          else
            path += "~"
          end
        end

        def company_path(options)
          path = "/companies/"
          if id = options.delete(:id)
            path += "id=#{id}"
          elsif url = options.delete(:url)
            path += "url=#{CGI.escape(url)}"
          elsif name = options.delete(:name)
            path += "universal-name=#{CGI.escape(name)}"
          elsif domain = options.delete(:domain)
            path += "email-domain=#{CGI.escape(domain)}"
          else
            path += "~"
          end
        end

    end

  end
end

This code is a wrapper for LinkedIn and I found it here: https://github.com/pengwynn/linkedin/blob/master/lib/linked_in/api/query_methods.rb

It is mostly off the shelf, but this test bit is mine:

  def test(options = {})
     logger.debug "helllllooooo"
  end

I copied these files locally, and in IRB I can perform some commands, but I can not for some reason do something like client.test whereas I can do something like client.profile.

Also none of the debug statements show up in IRB. Do I have to start IRB with some sort of a flag to see the debug?

Upvotes: 1

Views: 1035

Answers (2)

Ruby Racer
Ruby Racer

Reputation: 5740

Looking an answer to the same question, I tried this which I found somewhere online and it worked:

2.0.0-p353 :020 > ActiveRecord::Base.logger.debug "your whatever text"

Upvotes: 0

RadBrad
RadBrad

Reputation: 7304

logger is part of rails

irb is just a ruby command line interpreter

use 'rails console' to get a command line interface with the rails infrastructure running.

use puts as a substitute for logger while using irb

EDIT

You'll never get anywhere trying to run that code in irb, instead, copy your file to yourapp/lib, then do a

rails console

Now RAILS is booted up, but with a command line interface, then try

include LinkedIn::Api::QueryMethods

test

now you can also use logger.debug

Upvotes: 3

Related Questions