the_police 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in the_police.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,51 @@
1
+ require 'set'
2
+ require 'rack/request'
3
+
4
+ module ThePolice
5
+ class Roxanne
6
+ TEN_MEGABYTES = 10485760
7
+ WATCH_FOR = [500]
8
+
9
+ attr_reader :app, :collection, :watch_for
10
+
11
+ def initialize(app, options)
12
+ raise "Roxanne needs connections!" unless options[:connection]
13
+ connection = options[:connection].respond_to?(:call) ?
14
+ options[:connection].call :
15
+ options[:connection]
16
+
17
+ @app = app
18
+ @collection = connection.create_collection(
19
+ options[:collection] || 'messages-in-bottles',
20
+ :capped => true,
21
+ :size => options[:capsize] || TEN_MEGABYTES)
22
+
23
+ @watch_for = Set.new(options[:watch_for] || WATCH_FOR)
24
+ end
25
+
26
+ def call(env)
27
+ @app.call(env).tap do |result|
28
+ if watch_for.include?(result.first)
29
+ log(env, result)
30
+ end
31
+ end
32
+ end
33
+
34
+ def log(env, result)
35
+ request = Rack::Request.new(env)
36
+ collection.insert({
37
+ :level => "error",
38
+ :type => "request",
39
+ :time => Time.now.utc,
40
+ :data => {
41
+ :method => request.request_method,
42
+ :url => request.url,
43
+ :params => request.params,
44
+ :response_body => result.last.size == 1 && result.last[0].kind_of?(String) ? result.last[0] : "IO Stream",
45
+ }
46
+ }, {:safe => false})
47
+ rescue
48
+ # Lets make sure logging an error doesn't break stuff!
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module ThePolice
2
+ VERSION = "0.0.1"
3
+ end
data/lib/the_police.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'the_police/roxanne'
2
+
3
+ module ThePolice
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "the_police/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "the_police"
7
+ s.version = ThePolice::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Mathias Biilmann"]
10
+ s.email = ["mathiasch@webpop.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Log errors to a capped mongodb collection}
13
+ s.description = %q{Simple middleware for logging errors to a capped mongodb collection.}
14
+
15
+ s.rubyforge_project = "the_police"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_police
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Mathias Biilmann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-19 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Simple middleware for logging errors to a capped mongodb collection.
18
+ email:
19
+ - mathiasch@webpop.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - Rakefile
30
+ - lib/the_police.rb
31
+ - lib/the_police/roxanne.rb
32
+ - lib/the_police/version.rb
33
+ - the_police.gemspec
34
+ has_rdoc: true
35
+ homepage: ""
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ requirements: []
56
+
57
+ rubyforge_project: the_police
58
+ rubygems_version: 1.5.0
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Log errors to a capped mongodb collection
62
+ test_files: []
63
+