Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http_log

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http_log

  • 0.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

HTTP Log

Logs all requests made to your application in a search format to MongoDB. This gem includes a middleware to log rack requests to MongodB. It also adds a header to every response indicating an id that can be used to retrieve that request. You can combine this header and the one's added by rails to track the conversation applications are having with your application.

Installation

This gem using Mongoid to store the models. Once you install the gem, run the mongoid config generator to setup the connection.

gem 'http_log'

bundle install

bundle exec rails g mongoid:config # if you don't already have one

Example of What is Logged

{
  "_id":"4f16c6c4340765d7c5000005",
  "url":"http://www.example.com/",
  "http_method":"POST",
  "accept":["text/html","application/xml","image/png","text/plain","*/*"],
  "content_type":"application/json",
  "raw_post":"{\"foo\": \"bar\"}",
  "params":{
    "foo":"bar"
  },
  "headers":{
    "HTTP_HOST":"www.example.com",
    "HTTP_ACCEPT":"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
    "HTTP_COOKIE":""
  },
  "created_at":"2012-01-18T15:19:00+02:00",
  "updated_at":"2012-01-18T15:19:00+02:00"
}

Filtering

You may also filter out specific requests. Requests to /assets are filters by default. You can filter requests using three different methods:

  1. Symbols (treated as file extensions)
  2. Regex (matched aganist the full URL)
  3. Blocks/Procs/Lambda/Things that respond_to? :call

Filters are used to exclude requests. So, if a filter returns true then that request will not be logged.

Here are some examples.

# Using Symbols
HttpLog.filters << :jpg

# Using Regex
HttpLog.filters << /private/

# Using Blocks/Procs/Lambdas/Things that resond_to? :call
# req is ActionDispatch::Request with some sugar
HttpLog.filter do |req|
  req.env # perhaps access the rack request stuff
  true if my_conditions_are_met
end

Adding More Log Information

You can add has many callbacks as you'd like. They are executed inside the middleware after the initial log is instantiated. Callbacks are ran, then the log is persisted.

Let's say you want to add some more headers of your own:

# config/initializers/http_log.rb
# req is an ActionDispatch::Request
# log is the HttpLog::Request instance

HttpLog.with_request |log, req|
  log.headers['Custom-Foo'] = 'bar'
end

You may also add your own fields by reopneing the class and using the Mongoid APi.

# config/initializers/http_log.rb
class HttpLog::Request
  field :developer_api_key, :type => String
end

HttpLog.with_request |log, req|
  log.developer_api_key = req.parameters['developer_api_key']
end

FAQs

Package last updated on 16 Aug 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc