bunyan 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ Version 0.5.0
2
+ =============
3
+ * Added ActiveRecord-style "silent" connection reconnect
4
+ * Added #abort_on_failed_reconnect configuration option
5
+ * Upped dependent version of mongo gem to ~> 1.2.4
6
+
1
7
  Version 0.4.0
2
8
  =============
3
9
  * New configuration syntax (see readme)
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'bson_ext', '>=1.0.9'
3
+ gem 'bson_ext', '>=1.2.4'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'rspec', '>= 1.3.0'
7
+ gem 'rspec', '~> 1.3.0'
8
8
  end
data/Rakefile CHANGED
@@ -7,13 +7,24 @@ 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', '~> 1.0.9'
10
+ gemspec.add_dependency 'mongo', '~> 1.2.4'
11
11
  end
12
12
  Jeweler::GemcutterTasks.new
13
13
  rescue LoadError
14
14
  puts "Jeweler not available. Install it with: gem install jeweler"
15
15
  end
16
16
 
17
- task :default do
18
- system("spec spec")
17
+ begin
18
+ require 'spec/rake/spectask'
19
+
20
+ Spec::Rake::SpecTask.new
21
+
22
+ Spec::Rake::SpecTask.new(:specs_with_coverage) do |t|
23
+ t.spec_files = FileList['spec/*_spec.rb']
24
+ t.rcov = true
25
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
26
+ end
27
+ rescue LoadError
19
28
  end
29
+
30
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.5.0
data/bunyan.gemspec CHANGED
@@ -1,66 +1,68 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bunyan}
8
- s.version = "0.4.2"
8
+ s.version = "0.5.0"
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-10-06}
12
+ s.date = %q{2011-03-31}
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 = [
16
16
  "README.md"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "CHANGELOG.md",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "MIT-LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "bunyan.gemspec",
28
- "examples/middleware.rb",
29
- "examples/rails.rb",
30
- "lib/bunyan.rb",
31
- "lib/bunyan/config.rb",
32
- "lib/bunyan/configurable_methods.rb",
33
- "spec/bunyan_spec.rb",
34
- "spec/config_spec.rb",
35
- "spec/integration_spec.rb",
36
- "spec/spec.opts",
37
- "spec/spec_helper.rb"
19
+ "CHANGELOG.md",
20
+ "Gemfile",
21
+ "MIT-LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bunyan.gemspec",
26
+ "examples/middleware.rb",
27
+ "examples/rails.rb",
28
+ "lib/bunyan.rb",
29
+ "lib/bunyan/config.rb",
30
+ "lib/bunyan/configurable_methods.rb",
31
+ "spec/bunyan_spec.rb",
32
+ "spec/config_spec.rb",
33
+ "spec/integration_spec.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb"
38
36
  ]
39
37
  s.homepage = %q{http://github.com/ajsharp/bunyan}
40
- s.rdoc_options = ["--charset=UTF-8"]
41
38
  s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.7}
39
+ s.rubygems_version = %q{1.6.2}
43
40
  s.summary = %q{A MongoDB-based logging solution.}
44
41
  s.test_files = [
42
+ "examples/middleware.rb",
43
+ "examples/rails.rb",
45
44
  "spec/bunyan_spec.rb",
46
- "spec/config_spec.rb",
47
- "spec/integration_spec.rb",
48
- "spec/spec_helper.rb",
49
- "examples/middleware.rb",
50
- "examples/rails.rb"
45
+ "spec/config_spec.rb",
46
+ "spec/integration_spec.rb",
47
+ "spec/spec_helper.rb"
51
48
  ]
52
49
 
53
50
  if s.respond_to? :specification_version then
54
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
51
  s.specification_version = 3
56
52
 
57
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
- s.add_runtime_dependency(%q<mongo>, ["~> 1.0.9"])
54
+ s.add_runtime_dependency(%q<bson_ext>, [">= 1.2.4"])
55
+ s.add_runtime_dependency(%q<bunyan>, [">= 0"])
56
+ s.add_runtime_dependency(%q<mongo>, ["~> 1.2.4"])
59
57
  else
60
- s.add_dependency(%q<mongo>, ["~> 1.0.9"])
58
+ s.add_dependency(%q<bson_ext>, [">= 1.2.4"])
59
+ s.add_dependency(%q<bunyan>, [">= 0"])
60
+ s.add_dependency(%q<mongo>, ["~> 1.2.4"])
61
61
  end
62
62
  else
63
- s.add_dependency(%q<mongo>, ["~> 1.0.9"])
63
+ s.add_dependency(%q<bson_ext>, [">= 1.2.4"])
64
+ s.add_dependency(%q<bunyan>, [">= 0"])
65
+ s.add_dependency(%q<mongo>, ["~> 1.2.4"])
64
66
  end
65
67
  end
66
68
 
data/lib/bunyan.rb CHANGED
@@ -14,17 +14,19 @@ module Bunyan
14
14
 
15
15
  attr_reader :db, :connection, :collection, :config
16
16
 
17
- # Bunyan::Logger.configure do
18
- # # required options
19
- # database 'bunyan_logger'
20
- # collection 'development_log'
17
+ # @example Configuring bunyan
18
+ # Bunyan::Logger.configure do
19
+ # # required options
20
+ # database 'bunyan_logger'
21
+ # collection 'development_log'
21
22
  #
22
- # # optional options
23
- # disabled true
24
- # size 52428800 # 50.megabytes in Rails
25
- # end
23
+ # # optional options
24
+ # disabled true
25
+ # size 52428800 # 50.megabytes in Rails
26
+ # end
26
27
  def configure(&block)
27
28
  @config = Logger::Config.new
29
+ @config.abort_on_failed_reconnect = false
28
30
 
29
31
  # provide legacy support for old configuration syntax
30
32
  (block.arity > 0) ? yield(@config) : @config.instance_eval(&block)
@@ -46,8 +48,26 @@ module Bunyan
46
48
  def method_missing(method, *args, &block)
47
49
  begin
48
50
  collection.send(method, *args) if database_is_usable?
49
- rescue
50
- super(method, *args, &block)
51
+ rescue Mongo::ConnectionFailure
52
+ # At this point, the problem may be that the server was restarted
53
+ # and we have stale connection object. The mongo ruby driver will
54
+ # handle automatically handling a reconnect, and will issue a fresh
55
+ # connection object if it can obtain one. In which case, let's try
56
+ # the query again.
57
+ begin
58
+ collection.send(method, *args, &block) if database_is_usable?
59
+ rescue Mongo::ConnectionFailure => e
60
+ # Ok, we're having real connection issues. The mongod server is likely
61
+ # down. We still may want to fail silently, because bunyan is mostly a support
62
+ # library, and we wouldn't want exceptions to bubble up just b/c the
63
+ # mongod server is down. If it were the core datastore, then we probably
64
+ # would want it to bubble up.
65
+ #
66
+ # If you for some reason you do want error to bubble up, set the
67
+ # `abort_on_failed_reconnect` config option to true.
68
+
69
+ raise e if config.abort_on_failed_reconnect?
70
+ end
51
71
  end
52
72
  end
53
73
 
data/lib/bunyan/config.rb CHANGED
@@ -5,7 +5,7 @@ module Bunyan
5
5
 
6
6
  class Config
7
7
  extend Bunyan::ConfigurableMethods
8
- configurable_methods :port, :host, :database, :collection, :disabled, :connection
8
+ configurable_methods :port, :host, :database, :collection, :disabled, :connection, :abort_on_failed_reconnect
9
9
 
10
10
  def initialize
11
11
  @size = 52428800
@@ -20,6 +20,10 @@ module Bunyan
20
20
  !!@disabled
21
21
  end
22
22
 
23
+ def abort_on_failed_reconnect?
24
+ !!@abort_on_failed_reconnect
25
+ end
26
+
23
27
  # default size is 50 megabytes
24
28
  def size(new_size = nil)
25
29
  new_size.nil? ? @size : @size = new_size
data/spec/bunyan_spec.rb CHANGED
@@ -28,25 +28,111 @@ describe Bunyan::Logger do
28
28
  end
29
29
 
30
30
  describe 'when a mongod instance is not running' do
31
- before do
32
- Mongo::Connection.stub!(:new).and_raise(Mongo::ConnectionFailure)
33
- end
31
+ context "when initializing the bunyan setup" do
32
+ before do
33
+ Mongo::Connection.stub!(:new).and_raise(Mongo::ConnectionFailure)
34
+ end
34
35
 
35
- it 'should not blow up' do
36
- lambda {
36
+ it 'should not blow up' do
37
+ lambda {
38
+ Bunyan::Logger.configure do |c|
39
+ c.database 'doesnt_matter'
40
+ c.collection 'b/c mongod isnt running'
41
+ end
42
+ }.should_not raise_exception(Mongo::ConnectionFailure)
43
+ end
44
+
45
+ it 'should mark bunyan as disabled' do
37
46
  Bunyan::Logger.configure do |c|
38
47
  c.database 'doesnt_matter'
39
48
  c.collection 'b/c mongod isnt running'
40
49
  end
41
- }.should_not raise_exception(Mongo::ConnectionFailure)
50
+ Bunyan::Logger.should be_disabled
51
+ end
42
52
  end
43
53
 
44
- it 'should mark bunyan as disabled' do
45
- Bunyan::Logger.configure do |c|
46
- c.database 'doesnt_matter'
47
- c.collection 'b/c mongod isnt running'
54
+ context "when sending queries to Bunyan when a connection error occurs" do
55
+ class Mongo::Connection
56
+ attr_accessor :conn_fail
57
+
58
+ def new_send_message_on_socket(*args)
59
+ if conn_fail && conn_fail > 0
60
+ self.conn_fail -= 1
61
+ raise Mongo::ConnectionFailure
62
+ else
63
+ old_send_message_on_socket(*args)
64
+ end
65
+ end
66
+ end
67
+
68
+ before do
69
+ Mongo::Connection.send(:alias_method, :old_send_message_on_socket, :send_message_on_socket)
70
+ Mongo::Connection.send(:alias_method, :send_message_on_socket, :new_send_message_on_socket)
71
+ end
72
+
73
+ after do
74
+ Mongo::Connection.send(:alias_method, :send_message_on_socket, :old_send_message_on_socket)
75
+ end
76
+
77
+ before do
78
+ unstub_mongo
79
+ configure_test_db
80
+ end
81
+
82
+ it "should not raise an exception" do
83
+ Bunyan::Logger.connection.conn_fail = 1
84
+
85
+ lambda {
86
+ Bunyan::Logger.count
87
+ }.should_not raise_error(Mongo::ConnectionFailure)
88
+ end
89
+
90
+ context "by default" do
91
+ it "should not raise an exception if a connection error occurs on multiple requests" do
92
+ Bunyan::Logger.connection.conn_fail = 2
93
+
94
+ lambda {
95
+ Bunyan::Logger.count
96
+ }.should_not raise_error(Mongo::ConnectionFailure)
97
+ end
98
+ end
99
+
100
+ context "when abort_on_failed_reconnect is true" do
101
+ before do
102
+ configure_test_db do |c|
103
+ c.abort_on_failed_reconnect true
104
+ end
105
+ end
106
+
107
+ it "should raise an exception when more than one failed request occurs" do
108
+ Bunyan::Logger.connection.conn_fail = 2
109
+
110
+ lambda {
111
+ Bunyan::Logger.count
112
+ }.should raise_error(Mongo::ConnectionFailure)
113
+ end
114
+
115
+ it "should not raise an error when only one failed request occurs" do
116
+ Bunyan::Logger.connection.conn_fail = 1
117
+
118
+ lambda {
119
+ Bunyan::Logger.count
120
+ }.should_not raise_error(Mongo::ConnectionFailure)
121
+ end
122
+ end
123
+
124
+ it "should raise errors at the mongo level" do
125
+ # This is really a test to make sure our crazy stubbing magic
126
+ # above is working properly. It has nothing to do with actual
127
+ # library behavior.
128
+ Bunyan::Logger.connection.conn_fail = 1
129
+ db = Bunyan::Logger.db
130
+ coll = db.collection('no_op_collection')
131
+
132
+ lambda {
133
+ coll.count
134
+ }.should raise_error(Mongo::ConnectionFailure)
48
135
  end
49
- Bunyan::Logger.should be_disabled
50
136
  end
51
137
  end
52
138
 
data/spec/config_spec.rb CHANGED
@@ -210,4 +210,49 @@ describe 'the old configuration syntax' do
210
210
 
211
211
  Bunyan::Logger.config.database.should == 'old_config_db'
212
212
  end
213
- end
213
+ end
214
+
215
+ describe Bunyan::Logger::Config, '#abort_on_failed_reconnect' do
216
+ subject { Bunyan::Logger.config.abort_on_failed_reconnect }
217
+
218
+ it 'defaults to false' do
219
+ configure_test_db
220
+ subject.should be_false
221
+ end
222
+
223
+ it 'can be set to true in the config block' do
224
+ configure_test_db do |c|
225
+ c.abort_on_failed_reconnect true
226
+ end
227
+
228
+ subject.should be_true
229
+ end
230
+
231
+ it 'can be set to false in the config block' do
232
+ configure_test_db do |c|
233
+ c.abort_on_failed_reconnect false
234
+ end
235
+
236
+ subject.should be_false
237
+ end
238
+
239
+ describe "#abort_on_failed_reconnect?" do
240
+ subject { Bunyan::Logger.config.abort_on_failed_reconnect? }
241
+
242
+ it "should returns true when set to true" do
243
+ configure_test_db { |c| c.abort_on_failed_reconnect true }
244
+
245
+ subject.should be_true
246
+ end
247
+
248
+ it "should return false when set to false" do
249
+ configure_test_db { |c| c.abort_on_failed_reconnect false }
250
+ subject.should be_false
251
+ end
252
+
253
+ it "should return false by default" do
254
+ subject.should be_false
255
+ end
256
+ end
257
+ end
258
+
data/spec/spec_helper.rb CHANGED
@@ -28,6 +28,10 @@ Spec::Runner.configure do |config|
28
28
  @mock_database
29
29
  end
30
30
 
31
+ def unstub_mongo
32
+ Mongo::Connection.unstub!(:new)
33
+ end
34
+
31
35
  def other_fake_mongo
32
36
  #I want to check Mongo::Connection.stub.new is not called
33
37
  dm = DuckedMongo
@@ -35,10 +39,11 @@ Spec::Runner.configure do |config|
35
39
  dm
36
40
  end
37
41
 
38
- def configure_test_db
39
- Bunyan::Logger.configure do |config|
40
- config.database 'bunyan_test'
41
- config.collection 'bunyan_test_log'
42
+ def configure_test_db(&block)
43
+ Bunyan::Logger.configure do |c|
44
+ c.database 'bunyan_test'
45
+ c.collection 'bunyan_test_log'
46
+ yield(c) if block_given?
42
47
  end
43
48
  end
44
49
  end
metadata CHANGED
@@ -2,12 +2,12 @@
2
2
  name: bunyan
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 11
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Sharp
@@ -15,25 +15,55 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-06 00:00:00 -07:00
18
+ date: 2011-03-31 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: mongo
23
22
  prerelease: false
23
+ type: :runtime
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 5
29
+ hash: 23
30
30
  segments:
31
31
  - 1
32
+ - 2
33
+ - 4
34
+ version: 1.2.4
35
+ name: bson_ext
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ type: :runtime
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
32
47
  - 0
33
- - 9
34
- version: 1.0.9
48
+ version: "0"
49
+ name: bunyan
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ prerelease: false
35
53
  type: :runtime
36
- version_requirements: *id001
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 1
62
+ - 2
63
+ - 4
64
+ version: 1.2.4
65
+ name: mongo
66
+ version_requirements: *id003
37
67
  description: Bunyan is a thin ruby wrapper around a MongoDB capped collection, created with high-performance, flexible logging in mind.
38
68
  email: ajsharp@gmail.com
39
69
  executables: []
@@ -43,10 +73,8 @@ extensions: []
43
73
  extra_rdoc_files:
44
74
  - README.md
45
75
  files:
46
- - .gitignore
47
76
  - CHANGELOG.md
48
77
  - Gemfile
49
- - Gemfile.lock
50
78
  - MIT-LICENSE
51
79
  - README.md
52
80
  - Rakefile
@@ -67,8 +95,8 @@ homepage: http://github.com/ajsharp/bunyan
67
95
  licenses: []
68
96
 
69
97
  post_install_message:
70
- rdoc_options:
71
- - --charset=UTF-8
98
+ rdoc_options: []
99
+
72
100
  require_paths:
73
101
  - lib
74
102
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -92,14 +120,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
120
  requirements: []
93
121
 
94
122
  rubyforge_project:
95
- rubygems_version: 1.3.7
123
+ rubygems_version: 1.6.2
96
124
  signing_key:
97
125
  specification_version: 3
98
126
  summary: A MongoDB-based logging solution.
99
127
  test_files:
128
+ - examples/middleware.rb
129
+ - examples/rails.rb
100
130
  - spec/bunyan_spec.rb
101
131
  - spec/config_spec.rb
102
132
  - spec/integration_spec.rb
103
133
  - spec/spec_helper.rb
104
- - examples/middleware.rb
105
- - examples/rails.rb
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- .bundle
2
- coverage
3
- pkg
4
- .rvmrc
data/Gemfile.lock DELETED
@@ -1,23 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bunyan (0.4.1)
5
- mongo (~> 1.0.9)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- bson (1.1)
11
- bson_ext (1.1)
12
- mongo (1.0.9)
13
- bson (>= 1.0.5)
14
- rspec (1.3.0)
15
-
16
- PLATFORMS
17
- ruby
18
-
19
- DEPENDENCIES
20
- bson_ext (>= 1.0.9)
21
- bunyan!
22
- mongo (~> 1.0.9)
23
- rspec (>= 1.3.0)