Giter VIP home page Giter VIP logo

http_logger's Introduction

Net::HTTP logger

Simple gem that logs your HTTP api requests just like database queries

Screenshot

Installation

gem install http_logger

Usage

require 'http_logger'

HttpLogger.logger = Logger.new(...) # defaults to Rails.logger if Rails is defined
HttpLogger.colorize = true # Default: true
HttpLogger.ignore = [/newrelic\.com/]
HttpLogger.log_headers = false  # Default: false
HttpLogger.log_request_body  = false  # Default: true
HttpLogger.log_response_body = false  # Default: true
HttpLogger.level = :info # Desired log level as a symbol. Default: :debug
HttpLogger.collapse_body_limit # Change default truncate limit. Default: 5000

Alternative

Net::HTTP has a builtin logger that can be set via #set_debug_output. This method is only available at the instance level and it is not always accessible if used inside of a library. Also output of builtin debugger is not formed well for API debug purposes.

Integration

If you are using Net::HTTP#request hackers like FakeWeb make sure you require http_logger after all others because http_logger always calls "super", rather than others.

http_logger's People

Contributors

biow0lf avatar bogdan avatar cbeer avatar danielfone avatar dependabot[bot] avatar dwbutler avatar estebaninformatica avatar gyfis avatar le0pard avatar mmustala avatar raldred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http_logger's Issues

NameError: uninitialized constant HttpLogger::FakeWeb

I have an environment where:

  • I use http_logger (0.6.0)
  • I use webmock
  • I don't use fakeweb

And I observe this error on an HTTP request:

NameError:
       uninitialized constant HttpLogger::FakeWeb
     # /gems/gems/http_logger-0.6.0/lib/http_logger.rb:149:in `request_uri_as_string'
     # /gems/gems/http_logger-0.6.0/lib/http_logger.rb:136:in `fakeweb?'
     # /gems/gems/http_logger-0.6.0/lib/http_logger.rb:124:in `require_logging?'
     # /gems/gems/http_logger-0.6.0/lib/http_logger.rb:60:in `perform'
     # /gems/gems/http_logger-0.6.0/lib/http_logger.rb:45:in `perform'
     # /gems/gems/http_logger-0.6.0/lib/http_logger.rb:195:in `request'

fakeweb dependency was removed in 474ff60 but there are still some places in the code where FakeWeb is used and are not covered with specs.

BTW. There is at least one more weird thing in the linked commit: why would Gemfile.lock be added to .gitignore? ๐Ÿค”

Stack level too deep

Hi,

Commit 474ff60 breaks rspec systems specs (commit before works).

Example spec:

# frozen_string_literal: true

require "rails_helper"

describe "Sign in features" do
  it "when user successfully sign in" do
    create(:user, email: "[email protected]", password: "password")

    visit "/"

    click_link "Sign In"

    fill_in "user[email]", with: "[email protected]"
    fill_in "user[password]", with: "password"

    click_button "Sign in"

    expect(page).to have_content("Signed in successfully.")

    expect(current_path).to eq("/characters")
  end
end

Fail with

SystemStackError:
  stack level too deep
# ./spec/system/sign_ins_spec.rb:5:in `<top (required)>'
# -e:1:in `<main>'
No examples found.

Finished in 0.00009 seconds (files took 2.1 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

Env:
gem version: 0.6.0
ruby: 2.7.0
rails 6-0-stable from cd0ab2446418215dd9d48e062a2b4db25624eed3
rspec from master.

I can provide minimal rails app for reproduction.

Example fail: https://circleci.com/gh/evemonk/evemonk/698?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

New release?

I'd like to use the new options (level, log_response_body, etc). Can you cut a new release?

HTTP logger logs twice

Due to request() calling request() in Net::HTTP https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L1399

Stack trace for first call:

--> #0  #<Class:HttpLogger>.perform(*args#Array, &block#Proc) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:46
    #1  Net::HTTP.request(request#Net::HTTPGenericRequest, body#NilClass, &block#NilClass) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:198
    #2  Faraday::Adapter::NetHttp.perform_request(http#Net::HTTP, env#Faraday::Env) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:82

Stack trace of second call:

--> #0  #<Class:HttpLogger>.perform(*args#Array, &block#Proc) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:46
    #1  Net::HTTP.request(request#Net::HTTPGenericRequest, body#NilClass, &block#NilClass) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:198
    #2  block in Net::HTTP.block in request(request#NilClass, body#NilClass, &block#NilClass) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/2.2.0/net/http.rb:1377
    #3  Net::HTTP.start at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/2.2.0/net/http.rb:853
    #4  Net::HTTP.request(request#NilClass, body#NilClass, &block#NilClass) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/2.2.0/net/http.rb:1375
    #5  block in Net::HTTP.block in request(request#Net::HTTPGenericRequest, body#NilClass, &block#NilClass) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:199
    #6  HttpLogger.perform(http#Net::HTTP, request#Net::HTTPGenericRequest, request_body#NilClass) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:59
    #7  #<Class:HttpLogger>.perform(*args#Array, &block#Proc) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:46
    #8  Net::HTTP.request(request#Net::HTTPGenericRequest, body#NilClass, &block#NilClass) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/http_logger-0.5.1/lib/http_logger.rb:198
    #9  Faraday::Adapter::NetHttp.perform_request(http#Net::HTTP, env#Faraday::Env) at /Users/justin/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:82

Overriding logger when using Rails

I'm using Rails 3.
I want to override the logger so the output goes in it's own log.
However, http_logger always sets the logger to Rails.logger, this is done in an after_initialize call, so configuring the logger manually in an initializer is impossible, because they are run before after_initialize is called.

Not not sure where else I can configure it because I'm not using it at runtime in my code, It's being called by another gem.

I'd prefer to keep it all in an initializer, could you possible check incase the logger has been set already before setting it to Rails.logger?

eg....

ActiveSupport.on_load(:after_initialize) do
  HttpLogger.logger = Rails.logger unless HttpLogger.logger
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.