minimul / qbo_api

Ruby JSON-only client for QuickBooks Online API v3. Built on top of the Faraday gem.
MIT License
85 stars 46 forks source link

Refactor logging #69

Closed bf4 closed 6 years ago

bf4 commented 6 years ago

Extracted from #67

bf4 commented 6 years ago

I addressed comments by amending commits. Usually I'd add commits for clarity, but I don't think it needs it here.

bf4 commented 6 years ago

build just need to be re-run

bf4 commented 6 years ago

I made the logs noisy in part to prompt a question a about intention

I have a TestLogger pattern I’ll add to quiet down the test output

B mobile phone

On Mar 20, 2018, at 2:18 PM, Christian Pelczarski notifications@github.com wrote:

@minimul commented on this pull request.

In lib/qbo_api.rb:

rescue => e

  • Catch fetch key errors and just return JSON

  • QboApi.logger.debug { "#{LOG_TAG} response parsing error: entity=#{entity.inspect} body=#{resp.body.inspect} exception=#{e.inspect}" } One last thing. This one is a bit noisy on specs e.g.

bundle exec rspec spec/ D, [2018-03-20T19:11:41.754984 #15262] DEBUG -- : [QuickBooks] entity name not in response body: entity=:customer entity_name="Customer" body={"QueryResponse"=>{"totalCount"=>29}, "time"=>"2015-11-05T04:30:59.195-08:00"} .D, [2018-03-20T19:11:41.771654 #15262] DEBUG -- : [QuickBooks] entity name not in response body: entity=:employee entity_name="Employee" body={"QueryResponse"=>{"totalCount"=>2}, "time"=>"2016-10-04T04:03:53.319-07:00"} .D, [2018-03-20T19:11:41.797480 #15262] DEBUG -- : [QuickBooks] entity name not in response body: entity=:vendor entity_name="Vendor" body={"QueryResponse"=>{"totalCount"=>26}, "time"=>"2015-11-05T06:27:43.230-08:00"} .D, [2018-03-20T19:11:41.854119 #15262] DEBUG -- : [QuickBooks] entity name not in response body: entity=:customer entity_name="Customer" body={"QueryResponse"=>{"totalCount"=>6}, "time"=>"2016-10-04T04:07:15.826-07:00"} ..D, [2018-03-20T19:11:41.907760 #15262] DEBUG -- : [QuickBooks] entity name not in response body: entity=:customer entity_name="Customer" body={"QueryResponse"=>{"totalCount"=>29}, "time"=>"2015-11-05T04:30:59.195-08:00"} ..D, [2018-03-20T19:11:41.925671 #15262] DEBUG -- : [QuickBooks] entity name not in response body: entity=:attachable entity_name="Attachable" body={"AttachableResponse"=>[{"Fault"=>{"Error"=>[{"Message"=>"A business validation error has occurred while processing your request", "Detail"=>"Business Validation Error: The entity Estimate 75 that you are trying to link does not exist.", "code"=>"6000", "element"=>""}], "type"=>"ValidationFault"}}], "time"=>"2018-01-06T06:32:09.863-08:00"} ............................................. Finished in 0.39656 seconds (files took 0.44675 seconds to load) 52 examples, 0 failures Any ideas to keep things cleaner on runs?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

bf4 commented 6 years ago

I have a TestLogger pattern I’ll add to quiet down the test output

nevermind, done in 21c057e

anyhow, here's the test logger

# Log to a string to you can spec log output.
#
# Example Usage:
#
# def with_test_logging(klass=Rails)
#   old_logger = klass.logger
#   logger = ActiveSupport::TaggedLogging.new(TestLogger.new)
#   klass.logger = logger
#   yield
#   logger.messages
# ensure
#   klass.logger = old_logger
# end

class TestLogger < ActiveSupport::Logger
  def initialize
    @file = StringIO.new
    super(@file)
  end

  def messages
    @file.rewind
    @file.read
  end
end
minimul commented 6 years ago

Thank you!