bunyan 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .bundle
2
2
  coverage
3
3
  pkg
4
+ .rvmrc
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- gem 'bson_ext', '>= 0.20.1'
2
- gem 'mongo', '>= 0.20'
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
3
4
 
4
5
  group :test do
5
6
  gem 'rspec', '>= 1.3.0'
6
7
  gem 'ZenTest'
7
8
  gem 'autotest-growl'
8
- gem 'autotest-fsevent'
9
9
  end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bunyan (0.4.0)
5
+ bson_ext (>= 0.20.1)
6
+ mongo (>= 0.20.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ ZenTest (4.4.0)
12
+ autotest (4.3.2)
13
+ autotest-growl (0.2.4)
14
+ autotest (>= 4.2.4)
15
+ bson (1.0.7)
16
+ bson_ext (1.0.7)
17
+ mongo (1.0.8)
18
+ bson (>= 1.0.5)
19
+ rspec (1.3.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ ZenTest
26
+ autotest-growl
27
+ bson_ext (>= 0.20.1)
28
+ bunyan!
29
+ mongo (>= 0.20.1)
30
+ rspec (>= 1.3.0)
data/README.md CHANGED
@@ -45,6 +45,19 @@ The Logger class is implemented as a singleton, and you can call any instance
45
45
  method on the Logger class. This is implemented with some method_missing magic,
46
46
  which is explained in a bit more detail below.
47
47
 
48
+ Middleware
49
+ ==========
50
+ To make use of Bunyan in your web apps, you need some way to capture request data.
51
+ I have added an example middleware (which is extremely, extremely ugly) which you
52
+ can find at `examples/middleware.rb`.
53
+
54
+ There are plans for a standard middleware API, but it has not yet been implemented.
55
+ If you have interest in helping/collaborating on this feature, please get in touch
56
+ with me.
57
+
58
+ Until the middleware API is complete, please use this example middleware at your
59
+ own risk!
60
+
48
61
  Internals
49
62
  =========
50
63
  Bunyan makes heavy usage of method\_missing both at the class and instance level.
data/Rakefile CHANGED
@@ -7,11 +7,14 @@ begin
7
7
  gemspec.email = "ajsharp@gmail.com"
8
8
  gemspec.homepage = "http://github.com/ajsharp/bunyan"
9
9
  gemspec.authors = ["Alex Sharp"]
10
- gemspec.add_dependency 'mongo', '>= 0.20.1'
11
- gemspec.add_dependency 'bson_ext', '>= 0.20.1'
10
+ gemspec.add_dependency 'mongo', '~> 1.0.8'
11
+ gemspec.add_dependency 'bson_ext', '~> 1.0.7'
12
12
  end
13
13
  Jeweler::GemcutterTasks.new
14
14
  rescue LoadError
15
15
  puts "Jeweler not available. Install it with: gem install jeweler"
16
16
  end
17
17
 
18
+ task :default do
19
+ system("spec spec")
20
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/bunyan.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bunyan}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Sharp"]
12
- s.date = %q{2010-08-14}
12
+ s.date = %q{2010-09-02}
13
13
  s.description = %q{Bunyan is a thin ruby wrapper around a MongoDB capped collection, created with high-performance, flexible logging in mind.}
14
14
  s.email = %q{ajsharp@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -19,11 +19,13 @@ Gem::Specification.new do |s|
19
19
  ".gitignore",
20
20
  "CHANGELOG.md",
21
21
  "Gemfile",
22
+ "Gemfile.lock",
22
23
  "MIT-LICENSE",
23
24
  "README.md",
24
25
  "Rakefile",
25
26
  "VERSION",
26
27
  "bunyan.gemspec",
28
+ "examples/middleware.rb",
27
29
  "examples/rails.rb",
28
30
  "lib/bunyan.rb",
29
31
  "lib/bunyan/config.rb",
@@ -37,13 +39,14 @@ Gem::Specification.new do |s|
37
39
  s.homepage = %q{http://github.com/ajsharp/bunyan}
38
40
  s.rdoc_options = ["--charset=UTF-8"]
39
41
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.6}
42
+ s.rubygems_version = %q{1.3.7}
41
43
  s.summary = %q{A MongoDB-based logging solution.}
42
44
  s.test_files = [
43
45
  "spec/bunyan_spec.rb",
44
46
  "spec/config_spec.rb",
45
47
  "spec/integration_spec.rb",
46
48
  "spec/spec_helper.rb",
49
+ "examples/middleware.rb",
47
50
  "examples/rails.rb"
48
51
  ]
49
52
 
@@ -51,16 +54,16 @@ Gem::Specification.new do |s|
51
54
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
55
  s.specification_version = 3
53
56
 
54
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<mongo>, [">= 0.20.1"])
56
- s.add_runtime_dependency(%q<bson_ext>, [">= 0.20.1"])
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<mongo>, ["~> 1.0.8"])
59
+ s.add_runtime_dependency(%q<bson_ext>, ["~> 1.0.7"])
57
60
  else
58
- s.add_dependency(%q<mongo>, [">= 0.20.1"])
59
- s.add_dependency(%q<bson_ext>, [">= 0.20.1"])
61
+ s.add_dependency(%q<mongo>, ["~> 1.0.8"])
62
+ s.add_dependency(%q<bson_ext>, ["~> 1.0.7"])
60
63
  end
61
64
  else
62
- s.add_dependency(%q<mongo>, [">= 0.20.1"])
63
- s.add_dependency(%q<bson_ext>, [">= 0.20.1"])
65
+ s.add_dependency(%q<mongo>, ["~> 1.0.8"])
66
+ s.add_dependency(%q<bson_ext>, ["~> 1.0.7"])
64
67
  end
65
68
  end
66
69
 
@@ -0,0 +1,67 @@
1
+ # This sample middleware is provided purerly as an example.
2
+ # It is meant to be used with authlogic.
3
+ # Please use it as your own risk.
4
+ # Once I implement some type of bunyan middleware, this file will be removed.
5
+ # - @ajsharp
6
+ class BunyanMiddleware
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ # there are a number of conditions where we want to bypass and not log anything
12
+ def call(env)
13
+ @status, @headers, @response = @app.call(env)
14
+ if @status != 304 && @response && !@response.body.is_a?(Proc)
15
+ Bunyan::Logger.insert(prepare_extra_fields)
16
+ end
17
+ [@status, @headers, @response]
18
+ end
19
+
20
+ protected
21
+ def prepare_extra_fields
22
+ prepare_additional_response_data.merge(prepare_user_data) || {}
23
+ end
24
+
25
+ def prepare_additional_response_data
26
+ unless @response.blank?
27
+ { 'request_method' => @response.request.request_method,
28
+ 'user_agent' => @response.request.user_agent,
29
+ 'status' => @status,
30
+ 'request_uri' => @response.request.request_uri,
31
+ 'request_time' => Time.now.utc,
32
+ 'controller_action' => format_controller_action }
33
+ end || {}
34
+ end
35
+
36
+ def format_controller_action
37
+ params = @response.request.path_parameters
38
+ "#{params['controller']}##{params['action']}"
39
+ end
40
+
41
+ def prepare_user_data
42
+ if user_exists_in_session?
43
+ begin
44
+ user = User.find(@response.session[user_credentials_key])
45
+ { 'user' => { 'email' => user.email,
46
+ 'first_name' => user.first_name,
47
+ 'last_name' => user.last_name,
48
+ 'roles' => user.role_names
49
+ }
50
+ }
51
+ rescue ActiveRecord::RecordNotFound
52
+ {}
53
+ end
54
+ else
55
+ {}
56
+ end
57
+ end
58
+
59
+ def user_exists_in_session?
60
+ !!(@response != [] && @response.session && @response.session[user_credentials_key])
61
+ end
62
+
63
+ def user_credentials_key
64
+ 'user_credentials_id'
65
+ end
66
+
67
+ end
@@ -15,7 +15,7 @@ describe 'making a mongodb connection with the new configuration syntax' do
15
15
  end
16
16
 
17
17
  it 'should allow inserting documents' do
18
- Bunyan::Logger.insert(@params).should be_instance_of BSON::ObjectID
18
+ Bunyan::Logger.insert(@params).should be_instance_of BSON::ObjectId
19
19
  end
20
20
 
21
21
  it 'should allow querying documents' do
@@ -39,11 +39,11 @@ describe 'making a mongodb connection with the old configuration syntax' do
39
39
  end
40
40
 
41
41
  it 'should allow inserting documents' do
42
- Bunyan::Logger.insert(@params).should be_instance_of BSON::ObjectID
42
+ Bunyan::Logger.insert(@params).should be_instance_of BSON::ObjectId
43
43
  end
44
44
 
45
45
  it 'should allow querying documents' do
46
46
  Bunyan::Logger.insert(@params)
47
47
  Bunyan::Logger.find(@params).count.should == 1
48
48
  end
49
- end
49
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunyan
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 13
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 4
8
- - 0
9
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Alex Sharp
@@ -14,35 +15,39 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-14 00:00:00 -07:00
18
+ date: 2010-09-02 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: mongo
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
- - - ">="
27
+ - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 7
27
30
  segments:
28
- - 0
29
- - 20
30
31
  - 1
31
- version: 0.20.1
32
+ - 0
33
+ - 8
34
+ version: 1.0.8
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: bson_ext
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
- - - ">="
43
+ - - ~>
40
44
  - !ruby/object:Gem::Version
45
+ hash: 25
41
46
  segments:
42
- - 0
43
- - 20
44
47
  - 1
45
- version: 0.20.1
48
+ - 0
49
+ - 7
50
+ version: 1.0.7
46
51
  type: :runtime
47
52
  version_requirements: *id002
48
53
  description: Bunyan is a thin ruby wrapper around a MongoDB capped collection, created with high-performance, flexible logging in mind.
@@ -57,11 +62,13 @@ files:
57
62
  - .gitignore
58
63
  - CHANGELOG.md
59
64
  - Gemfile
65
+ - Gemfile.lock
60
66
  - MIT-LICENSE
61
67
  - README.md
62
68
  - Rakefile
63
69
  - VERSION
64
70
  - bunyan.gemspec
71
+ - examples/middleware.rb
65
72
  - examples/rails.rb
66
73
  - lib/bunyan.rb
67
74
  - lib/bunyan/config.rb
@@ -81,23 +88,27 @@ rdoc_options:
81
88
  require_paths:
82
89
  - lib
83
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
84
92
  requirements:
85
93
  - - ">="
86
94
  - !ruby/object:Gem::Version
95
+ hash: 3
87
96
  segments:
88
97
  - 0
89
98
  version: "0"
90
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
91
101
  requirements:
92
102
  - - ">="
93
103
  - !ruby/object:Gem::Version
104
+ hash: 3
94
105
  segments:
95
106
  - 0
96
107
  version: "0"
97
108
  requirements: []
98
109
 
99
110
  rubyforge_project:
100
- rubygems_version: 1.3.6
111
+ rubygems_version: 1.3.7
101
112
  signing_key:
102
113
  specification_version: 3
103
114
  summary: A MongoDB-based logging solution.
@@ -106,4 +117,5 @@ test_files:
106
117
  - spec/config_spec.rb
107
118
  - spec/integration_spec.rb
108
119
  - spec/spec_helper.rb
120
+ - examples/middleware.rb
109
121
  - examples/rails.rb