bunyan 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.2.1
2
+ =============
3
+ * Bunyan now fails silently when a connection error occurs
4
+
1
5
  Version 0.2.0
2
6
  =============
3
7
  * Moved all configuration-related stuff to the Config class
data/README.md CHANGED
@@ -56,6 +56,7 @@ More
56
56
 
57
57
  TODO
58
58
  ====
59
+ * Fail silently if no mongo server running
59
60
  * Ability to limit bunyan to only run in certain environments
60
61
  * Add middleware client for easy drop-in to rails/rack apps
61
62
  * <del>Ability to configure size of capped collection</del>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.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.2.0"
8
+ s.version = "0.2.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-03-20}
12
+ s.date = %q{2010-04-06}
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 = [
@@ -39,7 +39,6 @@ Gem::Specification.new do |s|
39
39
  s.test_files = [
40
40
  "spec/bunyan_spec.rb",
41
41
  "spec/config_spec.rb",
42
- "spec/integration/non_rails_spec.rb",
43
42
  "spec/spec_helper.rb",
44
43
  "examples/rails.rb"
45
44
  ]
data/lib/bunyan.rb CHANGED
@@ -56,13 +56,18 @@ module Bunyan
56
56
 
57
57
  private
58
58
  def initialize_connection
59
- @db = Mongo::Connection.new.db(config.database)
60
- @connection = @db.connection
61
- @collection = retrieve_or_initialize_collection(config.collection)
59
+ begin
60
+ @db = Mongo::Connection.new.db(config.database)
61
+ @connection = @db.connection
62
+ @collection = retrieve_or_initialize_collection(config.collection)
63
+ rescue Mongo::ConnectionFailure => ex
64
+ @disabled = true
65
+ $stderr.puts 'An error occured trying to connect to MongoDB!'
66
+ end
62
67
  end
63
68
 
64
69
  def database_is_usable?
65
- configured? && !disabled?
70
+ configured? && !disabled?
66
71
  end
67
72
 
68
73
  def ensure_required_options_exist
data/spec/bunyan_spec.rb CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Bunyan::Logger do
4
4
  before do
5
+ Mongo::Connection.unstub!(:new)
5
6
  @logger = Bunyan::Logger.instance
6
7
  @mock_database = nil
7
- Mongo::Connection.unstub!(:new)
8
8
  end
9
9
 
10
10
  it 'should have a connection' do
@@ -13,11 +13,12 @@ describe Bunyan::Logger do
13
13
  end
14
14
 
15
15
  it 'should have a reference to the mongo db object' do
16
+ configure_test_db
16
17
  @logger.db.should be_instance_of Mongo::DB
17
18
  end
18
19
 
19
20
  it 'should have a config hash' do
20
- @logger.config.should respond_to :[]
21
+ Bunyan::Logger.config.should respond_to :[]
21
22
  end
22
23
 
23
24
 
@@ -26,6 +27,29 @@ describe Bunyan::Logger do
26
27
  end
27
28
  end
28
29
 
30
+ describe 'when a mongod instance is not running' do
31
+ before do
32
+ Mongo::Connection.stub!(:new).and_raise(Mongo::ConnectionFailure)
33
+ end
34
+
35
+ it 'should not blow up' do
36
+ lambda {
37
+ Bunyan::Logger.configure do |c|
38
+ c.database 'doesnt_matter'
39
+ c.collection 'b/c mongod isnt running'
40
+ end
41
+ }.should_not raise_exception(Mongo::ConnectionFailure)
42
+ end
43
+
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'
48
+ end
49
+ Bunyan::Logger.instance.instance_variable_get(:@disabled).should == true
50
+ end
51
+ end
52
+
29
53
  describe 'when initializing the collection' do
30
54
  before do
31
55
  @conn = mock_mongo_connection
data/spec/spec_helper.rb CHANGED
@@ -8,10 +8,6 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
8
8
 
9
9
  Spec::Runner.configure do |config|
10
10
 
11
- config.after :each do
12
- cleanup_bunyan_config
13
- end
14
-
15
11
  config.before :each do
16
12
  mock_mongo_connection
17
13
  end
@@ -29,10 +25,6 @@ Spec::Runner.configure do |config|
29
25
  @mock_database
30
26
  end
31
27
 
32
- def cleanup_bunyan_config
33
- Bunyan::Logger.instance_variable_set(:@config, Bunyan::Logger::Config.new)
34
- end
35
-
36
28
  def configure_test_db
37
29
  Bunyan::Logger.configure do |config|
38
30
  config.database 'bunyan_test'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Sharp
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-20 00:00:00 -07:00
17
+ date: 2010-04-06 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -99,6 +99,5 @@ summary: A MongoDB-based logging solution.
99
99
  test_files:
100
100
  - spec/bunyan_spec.rb
101
101
  - spec/config_spec.rb
102
- - spec/integration/non_rails_spec.rb
103
102
  - spec/spec_helper.rb
104
103
  - examples/rails.rb
@@ -1,14 +0,0 @@
1
- # $LOAD_PATH.unshift(File.expand_path(File.dirname('../../lib/bunyan'))
2
- #
3
- # require 'bunyan'
4
- #
5
- # Bunyan::Logger.configure do |c|
6
- # c.database 'bunyan_integration_db'
7
- # c.collection 'test_log'
8
- #
9
- # c.size 104857600 # 100.megabytes
10
- # end
11
- #
12
- # describe
13
- #
14
- # Bunyan::Logger.insert({ })