http_log 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +38 -0
  3. data/app/assets/javascripts/http_log.js +14 -0
  4. data/app/assets/stylesheets/http_log.css +12 -0
  5. data/app/controllers/http_log/requests_controller.rb +10 -0
  6. data/app/models/http_log/request.rb +35 -0
  7. data/app/views/http_log/requests/show.html.erb +59 -0
  8. data/app/views/layouts/http_log/requests.html.erb +30 -0
  9. data/config/routes.rb +3 -0
  10. data/lib/http_log/http_request.rb +30 -0
  11. data/lib/http_log/middleware.rb +40 -0
  12. data/lib/http_log/railtie.rb +37 -0
  13. data/lib/http_log/version.rb +3 -0
  14. data/lib/http_log.rb +23 -0
  15. data/lib/tasks/http_logger_tasks.rake +4 -0
  16. data/readme.md +106 -0
  17. data/test/dummy/README.rdoc +261 -0
  18. data/test/dummy/Rakefile +7 -0
  19. data/test/dummy/app/assets/images/image.jpg +0 -0
  20. data/test/dummy/app/assets/javascripts/application.js +14 -0
  21. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  22. data/test/dummy/app/controllers/application_controller.rb +2 -0
  23. data/test/dummy/app/controllers/echo_controller.rb +5 -0
  24. data/test/dummy/app/helpers/application_helper.rb +2 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/test/dummy/config/application.rb +62 -0
  27. data/test/dummy/config/boot.rb +10 -0
  28. data/test/dummy/config/environment.rb +5 -0
  29. data/test/dummy/config/environments/development.rb +31 -0
  30. data/test/dummy/config/environments/production.rb +64 -0
  31. data/test/dummy/config/environments/test.rb +35 -0
  32. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  33. data/test/dummy/config/initializers/inflections.rb +15 -0
  34. data/test/dummy/config/initializers/mime_types.rb +5 -0
  35. data/test/dummy/config/initializers/secret_token.rb +7 -0
  36. data/test/dummy/config/initializers/session_store.rb +8 -0
  37. data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
  38. data/test/dummy/config/locales/en.yml +5 -0
  39. data/test/dummy/config/mongoid.yml +7 -0
  40. data/test/dummy/config/routes.rb +4 -0
  41. data/test/dummy/config.ru +4 -0
  42. data/test/dummy/log/test.log +8567 -0
  43. data/test/dummy/public/404.html +26 -0
  44. data/test/dummy/public/422.html +26 -0
  45. data/test/dummy/public/500.html +25 -0
  46. data/test/dummy/public/favicon.ico +0 -0
  47. data/test/dummy/script/rails +6 -0
  48. data/test/dummy/tmp/cache/assets/C56/AF0/sprockets%2F8bd6bc711946e979052328c24a265273 +2491 -0
  49. data/test/dummy/tmp/cache/assets/C88/730/sprockets%2F5b9d71c4883306a9e7425d3149785b0a +0 -0
  50. data/test/dummy/tmp/cache/assets/CAC/FC0/sprockets%2F143f0911dfc3cc1692f4d429654d7422 +0 -0
  51. data/test/dummy/tmp/cache/assets/CBD/000/sprockets%2F9d2bd18b820d1d20830ad0411e05a317 +0 -0
  52. data/test/dummy/tmp/cache/assets/CD7/500/sprockets%2Fae345f99053c3b580c5421a1a8a9b509 +0 -0
  53. data/test/dummy/tmp/cache/assets/CD7/9B0/sprockets%2Fef051dd1922500356c22d85b54b94ef4 +0 -0
  54. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  55. data/test/dummy/tmp/cache/assets/CD8/EB0/sprockets%2Ff6249465d0ba565203e326e971ba33dc +0 -0
  56. data/test/dummy/tmp/cache/assets/D00/890/sprockets%2F641813db3a41029a3f60b1ef90e95eb2 +0 -0
  57. data/test/dummy/tmp/cache/assets/D05/B40/sprockets%2F6ec40b73403c5c791c98c130a66f03eb +0 -0
  58. data/test/dummy/tmp/cache/assets/D14/B90/sprockets%2F22c02508890f4a42d489f5cb9995bcaa +0 -0
  59. data/test/dummy/tmp/cache/assets/D18/BC0/sprockets%2Fcc96a74afecc950f9b1923750a624666 +0 -0
  60. data/test/dummy/tmp/cache/assets/D1C/3F0/sprockets%2Ff3cb97c67a28f035a79bf35393a493b6 +0 -0
  61. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  62. data/test/dummy/tmp/cache/assets/D39/6B0/sprockets%2F8d0238243bc83309bfffe73733edb00d +0 -0
  63. data/test/dummy/tmp/cache/assets/D3E/820/sprockets%2F6260e7992ddc6fc2380ba3b8c032dd94 +0 -0
  64. data/test/dummy/tmp/cache/assets/D47/EC0/sprockets%2Fdc5e701826b1ce3f37c1c89bf75f2538 +0 -0
  65. data/test/dummy/tmp/cache/assets/D4A/E60/sprockets%2Fbfb99140fe3d1ff718034c6a8e18847d +0 -0
  66. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  67. data/test/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +2496 -0
  68. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  69. data/test/dummy/tmp/cache/assets/D5B/D40/sprockets%2F04e9e640af4cc213ef17ba39d31f2a40 +0 -0
  70. data/test/dummy/tmp/cache/assets/D60/660/sprockets%2F180c4ea684d2eadbbd5e85d302601b74 +0 -0
  71. data/test/dummy/tmp/cache/assets/D80/D90/sprockets%2Fe73320ffabc376681cd17ed79d9b93e7 +0 -0
  72. data/test/dummy/tmp/cache/assets/D84/4B0/sprockets%2F6a24f73a9cc3c9f978a16a79afe6818b +0 -0
  73. data/test/dummy/tmp/cache/assets/D8D/D50/sprockets%2Fd4f3b2c5183658aa13fa2d8511e6bcba +0 -0
  74. data/test/dummy/tmp/cache/assets/DB9/CD0/sprockets%2F58dda55967442f12eac66cfe9ef69bf6 +0 -0
  75. data/test/dummy/tmp/cache/assets/DC1/380/sprockets%2Fc4cf1e25b6a6e86e6cb37dd2413fbb00 +0 -0
  76. data/test/dummy/tmp/cache/assets/DC4/7C0/sprockets%2Fcba25fb6f81b385a80ef50f3405b2ded +0 -0
  77. data/test/dummy/tmp/cache/assets/DC7/430/sprockets%2F3a58abcdb48a00fb9f180e8ddf3e9203 +0 -0
  78. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  79. data/test/dummy/tmp/cache/assets/DF5/D50/sprockets%2F5ad27ea47264a1fb2bafb977f50d2fca +0 -0
  80. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  81. data/test/dummy/tmp/cache/assets/E07/410/sprockets%2F490f1cfa897fcbe947b0ff03ec38dfb1 +0 -0
  82. data/test/dummy/tmp/cache/assets/E0C/3A0/sprockets%2Fef495ecd04bb6d988d0865ebbebf3c63 +0 -0
  83. data/test/dummy/tmp/cache/assets/E0D/320/sprockets%2Fbf429fbc894ba0b9e4e65fd9825c1fbe +0 -0
  84. data/test/dummy/tmp/cache/assets/E23/000/sprockets%2Fa2e82546ad8185cbdbbcc6b7fa33db3c +0 -0
  85. data/test/dummy/tmp/cache/assets/E54/5F0/sprockets%2Fffb07dbaf19b3044d2fb165c1eefaf9a +0 -0
  86. data/test/integration/filters_test.rb +37 -0
  87. data/test/integration/logging_test.rb +144 -0
  88. data/test/integration/response_test.rb +11 -0
  89. data/test/integration/retrieve_request_test.rb +13 -0
  90. data/test/support/database_cleaner.rb +17 -0
  91. data/test/support/http_logger.rb +7 -0
  92. data/test/test_helper.rb +10 -0
  93. metadata +274 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'HttpLog'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require twitter/bootstrap
10
+ //= require_tree .
11
+
12
+ $(function() {
13
+ $("body#http-logger > .topbar").scrollSpy()
14
+ });
@@ -0,0 +1,12 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require twitter/bootstrap
7
+ *= require_tree .
8
+ */
9
+
10
+ #http-logger table {
11
+ table-layout: fixed;
12
+ }
@@ -0,0 +1,10 @@
1
+ module HttpLog
2
+ class RequestsController < ActionController::Base
3
+ respond_to :html, :xml, :json
4
+
5
+ def show
6
+ @log = HttpLog::Request.find params[:id]
7
+ respond_with @log
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ module HttpLog
2
+ class Request
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :http_method, :type => String
7
+ field :url, :type => String
8
+ field :raw_post, :type => String
9
+ field :remote_ip, :type => String
10
+ field :remote_host, :type => String
11
+ field :user_agent, :type => String
12
+ field :content_type, :type => String
13
+ field :headers, :type => Hash, :default => {}
14
+ field :params, :type => Hash, :default => {}
15
+ field :cookies, :type => Hash, :default => {}
16
+
17
+ def self.from_request(rack)
18
+ new do |req|
19
+ req.http_method = rack.request_method
20
+ req.url = rack.url
21
+ req.headers = rack.header_hash
22
+ req.params = rack.params
23
+ req.user_agent = rack.user_agent
24
+ req.content_type = rack.content_type
25
+ req.raw_post = rack.raw_post
26
+ req.remote_ip = rack.ip
27
+ req.cookies = rack.cookies
28
+ end
29
+ end
30
+
31
+ def accept
32
+ headers['HTTP_ACCEPT'].present? ? headers['HTTP_ACCEPT'] : nil
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,59 @@
1
+ <h1>HTTP Request: <%= @log.id %></h1>
2
+
3
+ <table id="summary" class="bordered-table zebra-striped">
4
+ <tbody>
5
+ <tr>
6
+ <th>URL</th>
7
+ <td><%= @log.url %></td>
8
+ </tr>
9
+ <tr>
10
+ <th>Method</th>
11
+ <td><%= @log.http_method.upcase %></td>
12
+ </tr>
13
+ <tr>
14
+ <th>Received</th>
15
+ <td><%= @log.created_at %></td>
16
+ </tr>
17
+ <tr>
18
+ <th>From</th>
19
+ <td><%= @log.remote_ip %></td>
20
+ </tr>
21
+ <tr>
22
+ <th>User Agent</th>
23
+ <td><%= @log.user_agent %></td>
24
+ </tr>
25
+ <tr id="content-type">
26
+ <th>Content-Type</th>
27
+ <td><%= @log.content_type %></td>
28
+ </tr>
29
+ <tr id="accepts">
30
+ <th>Accept</th>
31
+ <td><%= @log.accept %></td>
32
+ </tr>
33
+ </tbody>
34
+ </table>
35
+
36
+ <h2>Parameters</h2>
37
+ <pre id="parameters" class="pretty-print">
38
+ <%= @log.params.inspect %>
39
+ </pre>
40
+
41
+ <h2>Headers</h2>
42
+ <table id="headers" class="bordered-table zebra-striped">
43
+ <% @log.headers.each do |name, value| %>
44
+ <tr>
45
+ <th><%= name %></th>
46
+ <td><%= value %></th>
47
+ </tr>
48
+ <% end %>
49
+ </table>
50
+
51
+ <h2>Raw Post</h2>
52
+ <pre id="raw-post" class="pretty-print">
53
+ <%= @log.raw_post %>
54
+ </pre>
55
+
56
+ <h2>Cookies</h2>
57
+ <pre id="cookies" class="pretty-print">
58
+ <%= @log.cookies %>
59
+ </pre>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HTTP Logger</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body id="http-logger" style="padding-top: 60px">
10
+ <div class="topbar" data-scrollspy="scrollspy">
11
+ <div class="topbar-inner">
12
+ <div class="container">
13
+ <h3 class="brand">HTTP Log</h3>
14
+ <ul class="nav">
15
+ <li><%= link_to "Summary", "#summary" %></li>
16
+ <li><%= link_to "Content-Type", "#content-type" %></li>
17
+ <li><%= link_to "Accepts", "#accepts" %></li>
18
+ <li><%= link_to "Paramters", "#parameters" %></li>
19
+ <li><%= link_to "Headers", "#headers" %></li>
20
+ <li><%= link_to "Raw Post", "#raw-post" %></li>
21
+ <li><%= link_to "Cookies ", "#cookies" %></li>
22
+ </ul>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <div class="container">
27
+ <%= yield %>
28
+ </div>
29
+ </body>
30
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ HttpLog::Engine.routes.draw do
2
+ resources :requests, :only => :show, :as => :http_request
3
+ end
@@ -0,0 +1,30 @@
1
+ module HttpLog
2
+ class HttpRequest < Rack::Request
3
+ def accepts
4
+ Array.wrap(super).map(&:to_s)
5
+ end
6
+
7
+ def header_hash
8
+ header_keys = env.keys.select {|k| k =~ /HTTP_\w+/ }
9
+ hash = {}
10
+ header_keys.each do |key|
11
+ hash[key] = env[key]
12
+ end
13
+ hash
14
+ end
15
+
16
+ def accepts
17
+ env['HTTP_ACCEPT']
18
+ end
19
+
20
+ def raw_post
21
+ content = env['rack.input'].read
22
+ env['rack.input'].rewind
23
+ content
24
+ end
25
+
26
+ def params
27
+ super.merge(env['action_dispatch.request.request_parameters'] || {})
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ module HttpLog
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ @proxy = HttpRequest.new(env)
9
+ if passes_filters?
10
+ request = HttpLog::Request.from_request(@proxy)
11
+
12
+ HttpLog.callbacks.each do |callback|
13
+ callback.call @proxy, request
14
+ end
15
+
16
+ request.save
17
+ env['http_log.request_id'] = request.id.to_s
18
+ end
19
+
20
+ @app.call env
21
+ end
22
+
23
+ def passes_filters?
24
+ HttpLog.filters.each do |filter|
25
+ matches_filter = if filter.is_a? Symbol
26
+ @proxy.path_info =~ /\.#{filter}$/
27
+ elsif filter.is_a? Regexp
28
+ @proxy.url =~ filter
29
+ else
30
+ filter.call @proxy
31
+ end
32
+
33
+ return false if matches_filter
34
+ end
35
+
36
+ true
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ module HttpLog
2
+ module ControllerHelpers
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_filter :include_http_request_log_id, :if => :http_log_request_id
7
+
8
+ def include_http_request_log_id
9
+ logger.info " HTTP Logger Request ID: #{http_log_request_id}"
10
+ headers['X-Request-Log-ID'] = http_log_request_id
11
+ end
12
+
13
+ def http_log_request_id
14
+ request.env['http_log.request_id']
15
+ end
16
+ end
17
+ end
18
+
19
+ class Engine < ::Rails::Engine
20
+ isolate_namespace HttpLog
21
+
22
+ initializer "http_log.middlware" do |app|
23
+ app.middleware.use HttpLog::Middleware
24
+ end
25
+
26
+ initializer "http_log.filters" do |app|
27
+ regexp = /assets/
28
+ HttpLog.filters << regexp
29
+ end
30
+
31
+ initializer "http_log.action_controller" do
32
+ ActiveSupport.on_load(:action_controller) do
33
+ ActionController::Base.send :include, HttpLog::ControllerHelpers
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module HttpLog
2
+ VERSION = "0.0.1"
3
+ end
data/lib/http_log.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'mongoid'
2
+ require 'http_log/http_request'
3
+ require 'http_log/middleware'
4
+ require 'twitter-bootstrap-rails'
5
+ require "http_log/railtie"
6
+
7
+ module HttpLog
8
+ def self.with_request(&block)
9
+ callbacks << block
10
+ end
11
+
12
+ def self.callbacks
13
+ @callbacks ||= []
14
+ end
15
+
16
+ def self.filters
17
+ @filters ||= []
18
+ end
19
+
20
+ def self.filter(&block)
21
+ filters << block
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :http_log do
3
+ # # Task goes here
4
+ # end
data/readme.md ADDED
@@ -0,0 +1,106 @@
1
+ # HTTP Log
2
+
3
+ Logs all requests made to your application in a search format to
4
+ MongoDB. This gem includes a middleware to log rack requests to MongodB.
5
+ It also adds a header to every response indicating an `id` that can be
6
+ used to retrieve that request. You can combine this header and the one's
7
+ added by rails to track the conversation applications are having with
8
+ your application.
9
+
10
+ ## Installation
11
+
12
+ This gem using Mongoid to store the models. Once you install the gem,
13
+ run the mongoid config generator to setup the connection.
14
+
15
+ ```
16
+ gem 'http_log'
17
+
18
+ bundle install
19
+
20
+ bundle exec rails g mongoid:config # if you don't already have one
21
+ ```
22
+
23
+ ## Example of What is Logged
24
+
25
+ ```javascript
26
+ {
27
+ "_id":"4f16c6c4340765d7c5000005",
28
+ "url":"http://www.example.com/",
29
+ "http_method":"POST",
30
+ "accept":["text/html","application/xml","image/png","text/plain","*/*"],
31
+ "content_type":"application/json",
32
+ "raw_post":"{\"foo\": \"bar\"}",
33
+ "params":{
34
+ "foo":"bar"
35
+ },
36
+ "headers":{
37
+ "HTTP_HOST":"www.example.com",
38
+ "HTTP_ACCEPT":"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
39
+ "HTTP_COOKIE":""
40
+ },
41
+ "created_at":"2012-01-18T15:19:00+02:00",
42
+ "updated_at":"2012-01-18T15:19:00+02:00"
43
+ }
44
+ ```
45
+
46
+ ## Filtering
47
+
48
+ You may also filter out specific requests. Requests to `/assets` are
49
+ filters by **default**. You can filter requests using three different
50
+ methods:
51
+
52
+ 1. Symbols (treated as file extensions)
53
+ 2. Regex (matched aganist the full URL)
54
+ 3. Blocks/Procs/Lambda/Things that `respond_to? :call`
55
+
56
+ Filters are used to exclude requests. So, if a filter returns true then
57
+ that request will **not** be logged.
58
+
59
+ Here are some examples.
60
+
61
+ ```ruby
62
+ # Using Symbols
63
+ HttpLog.filters << :jpg
64
+
65
+ # Using Regex
66
+ HttpLog.filters << /private/
67
+
68
+ # Using Blocks/Procs/Lambdas/Things that resond_to? :call
69
+ # req is ActionDispatch::Request with some sugar
70
+ HttpLog.filter do |req|
71
+ req.env # perhaps access the rack request stuff
72
+ true if my_conditions_are_met
73
+ end
74
+ ```
75
+
76
+ ## Adding More Log Information
77
+
78
+ You can add has many callbacks as you'd like. They are executed inside
79
+ the middleware after the initial log is instantiated. Callbacks are ran,
80
+ then the log is persisted.
81
+
82
+ Let's say you want to add some more headers of your own:
83
+
84
+ ```ruby
85
+ # config/initializers/http_log.rb
86
+ # req is an ActionDispatch::Request
87
+ # log is the HttpLog::Request instance
88
+
89
+ HttpLog.with_request |log, req|
90
+ log.headers['Custom-Foo'] = 'bar'
91
+ end
92
+ ```
93
+
94
+ You may also add your own fields by reopneing the class and using the
95
+ Mongoid APi.
96
+
97
+ ```ruby
98
+ # config/initializers/http_log.rb
99
+ class HttpLog::Request
100
+ field :developer_api_key, :type => String
101
+ end
102
+
103
+ HttpLog.with_request |log, req|
104
+ log.developer_api_key = req.parameters['developer_api_key']
105
+ end
106
+ ```