bunyan 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/MIT-LICENSE +19 -0
- data/README.md +20 -9
- data/VERSION +1 -1
- data/bunyan.gemspec +6 -2
- data/lib/bunyan/config.rb +3 -32
- data/lib/bunyan/configurable_methods.rb +17 -0
- data/lib/bunyan.rb +15 -9
- data/spec/config_spec.rb +54 -1
- data/spec/integration_spec.rb +49 -0
- data/spec/spec_helper.rb +10 -0
- metadata +7 -3
data/CHANGELOG.md
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Alex Sharp
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THEse, and/or sell
|
19
|
+
copies of the Software, and to permit p
|
data/README.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
Bunyan
|
2
2
|
======
|
3
|
+
![](http://img2.timeinc.net/ew/dynamic/imgs/080612/Paul-Bunyan-Blue-Ox_l.jpg)
|
4
|
+
|
3
5
|
Bunyan is a thin ruby wrapper around a MongoDB [capped collection](http://www.mongodb.org/display/DOCS/Capped+Collections),
|
4
6
|
created with high-performance, flexible logging in mind.
|
5
7
|
|
6
|
-
|
8
|
+
Bunyan is not intended to be used as a drop-in replacement for the default
|
9
|
+
rails logger. If you need to do this, please see peburrows' [mongo\_db\_logger](http://github.com/peburrows/mongo_db_logger).
|
10
|
+
|
11
|
+
However, there is planned support for a flexible middleware component to drop in
|
12
|
+
to your rails app.
|
7
13
|
|
8
14
|
Install
|
9
15
|
=======
|
@@ -16,15 +22,20 @@ The only configuration options required are the database and collection name.
|
|
16
22
|
For rails apps, put the following config block in an initializer.
|
17
23
|
|
18
24
|
# config/initializers/bunyan.rb
|
19
|
-
Bunyan::Logger.configure do
|
25
|
+
Bunyan::Logger.configure do
|
20
26
|
# required options
|
21
|
-
|
22
|
-
|
27
|
+
database 'bunyan_logger'
|
28
|
+
collection 'development_log'
|
23
29
|
|
24
30
|
# optional
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
host 'some.remote.host' # defaults to localhost
|
32
|
+
port '12345' # defaults to 27017
|
33
|
+
disabled true
|
34
|
+
|
35
|
+
# other connection option
|
36
|
+
# Specify a valid ruby driver connection object (single / pair)
|
37
|
+
# if you do so, host / port are ignored
|
38
|
+
connection = $connection
|
28
39
|
end
|
29
40
|
|
30
41
|
Usage
|
@@ -58,9 +69,9 @@ More
|
|
58
69
|
|
59
70
|
TODO
|
60
71
|
====
|
61
|
-
* Ability to specify auth creds for making mongo connection
|
72
|
+
* Ability to specify auth creds for making a mongo connection
|
62
73
|
* <del>Fail silently if no mongo server running</del>
|
63
74
|
* Ability to limit bunyan to only run in certain environments
|
64
75
|
* Add middleware client for easy drop-in to rails/rack apps
|
65
|
-
<del
|
76
|
+
* <del>Add ability to connect to a remote mongo server</del>
|
66
77
|
* <del>Ability to configure size of capped collection</del>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
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.
|
8
|
+
s.version = "0.4.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-
|
12
|
+
s.date = %q{2010-08-14}
|
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,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
".gitignore",
|
20
20
|
"CHANGELOG.md",
|
21
21
|
"Gemfile",
|
22
|
+
"MIT-LICENSE",
|
22
23
|
"README.md",
|
23
24
|
"Rakefile",
|
24
25
|
"VERSION",
|
@@ -26,8 +27,10 @@ Gem::Specification.new do |s|
|
|
26
27
|
"examples/rails.rb",
|
27
28
|
"lib/bunyan.rb",
|
28
29
|
"lib/bunyan/config.rb",
|
30
|
+
"lib/bunyan/configurable_methods.rb",
|
29
31
|
"spec/bunyan_spec.rb",
|
30
32
|
"spec/config_spec.rb",
|
33
|
+
"spec/integration_spec.rb",
|
31
34
|
"spec/spec.opts",
|
32
35
|
"spec/spec_helper.rb"
|
33
36
|
]
|
@@ -39,6 +42,7 @@ Gem::Specification.new do |s|
|
|
39
42
|
s.test_files = [
|
40
43
|
"spec/bunyan_spec.rb",
|
41
44
|
"spec/config_spec.rb",
|
45
|
+
"spec/integration_spec.rb",
|
42
46
|
"spec/spec_helper.rb",
|
43
47
|
"examples/rails.rb"
|
44
48
|
]
|
data/lib/bunyan/config.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
require 'bunyan/configurable_methods'
|
1
2
|
|
2
3
|
module Bunyan
|
3
4
|
class Logger
|
4
5
|
|
5
6
|
class Config
|
6
|
-
|
7
|
-
|
7
|
+
extend Bunyan::ConfigurableMethods
|
8
|
+
configurable_methods :port, :host, :database, :collection, :disabled, :connection
|
8
9
|
|
9
10
|
def initialize
|
10
11
|
@size = 52428800
|
@@ -15,36 +16,6 @@ module Bunyan
|
|
15
16
|
send(meth)
|
16
17
|
end
|
17
18
|
|
18
|
-
def port(port_num = nil)
|
19
|
-
@port ||= port_num
|
20
|
-
end
|
21
|
-
alias_method :port=, :port
|
22
|
-
|
23
|
-
def host(host_address = nil)
|
24
|
-
@host ||= host_address
|
25
|
-
end
|
26
|
-
alias_method :host=, :host
|
27
|
-
|
28
|
-
# First time called sets the database name.
|
29
|
-
# Otherwise, returns the database name.
|
30
|
-
def database(db_name = nil)
|
31
|
-
@database ||= db_name
|
32
|
-
end
|
33
|
-
alias_method :database=, :database
|
34
|
-
|
35
|
-
# First time called sets the collection name.
|
36
|
-
# Otherwise, returns the collection name.
|
37
|
-
# For the actual collection object returned by Mongo, see #db.
|
38
|
-
def collection(coll = nil)
|
39
|
-
@collection ||= coll
|
40
|
-
end
|
41
|
-
alias_method :collection=, :collection
|
42
|
-
|
43
|
-
def disabled(dis = nil)
|
44
|
-
@disabled ||= dis
|
45
|
-
end
|
46
|
-
alias_method :disabled=, :disabled
|
47
|
-
|
48
19
|
def disabled?
|
49
20
|
!!@disabled
|
50
21
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Bunyan
|
2
|
+
module ConfigurableMethods
|
3
|
+
private
|
4
|
+
def configurable_method(method_name)
|
5
|
+
class_eval %Q{
|
6
|
+
def #{method_name}(local_#{method_name} = nil)
|
7
|
+
@#{method_name} ||= local_#{method_name}
|
8
|
+
end
|
9
|
+
alias_method :#{method_name}=, :#{method_name}
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def configurable_methods(*methods)
|
14
|
+
methods.each { |method| configurable_method(method) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/bunyan.rb
CHANGED
@@ -14,19 +14,20 @@ module Bunyan
|
|
14
14
|
|
15
15
|
attr_reader :db, :connection, :collection, :config
|
16
16
|
|
17
|
-
# Bunyan::Logger.configure do
|
17
|
+
# Bunyan::Logger.configure do
|
18
18
|
# # required options
|
19
|
-
#
|
20
|
-
#
|
19
|
+
# database 'bunyan_logger'
|
20
|
+
# collection 'development_log'
|
21
21
|
#
|
22
22
|
# # optional options
|
23
|
-
#
|
24
|
-
#
|
23
|
+
# disabled true
|
24
|
+
# size 52428800 # 50.megabytes in Rails
|
25
25
|
# end
|
26
26
|
def configure(&block)
|
27
27
|
@config = Logger::Config.new
|
28
28
|
|
29
|
-
|
29
|
+
# provide legacy support for old configuration syntax
|
30
|
+
(block.arity > 0) ? yield(@config) : @config.instance_eval(&block)
|
30
31
|
|
31
32
|
ensure_required_options_exist
|
32
33
|
initialize_connection unless disabled?
|
@@ -34,7 +35,7 @@ module Bunyan
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def configured?
|
37
|
-
|
38
|
+
!!@configured
|
38
39
|
end
|
39
40
|
|
40
41
|
def disabled?
|
@@ -58,8 +59,13 @@ module Bunyan
|
|
58
59
|
private
|
59
60
|
def initialize_connection
|
60
61
|
begin
|
61
|
-
|
62
|
-
|
62
|
+
if (config.connection)
|
63
|
+
@connection = config.connection
|
64
|
+
@db = @connection.db
|
65
|
+
else
|
66
|
+
@db = Mongo::Connection.new(config.host, config.port).db(config.database)
|
67
|
+
@connection = @db.connection
|
68
|
+
end
|
63
69
|
@collection = retrieve_or_initialize_collection(config.collection)
|
64
70
|
rescue Mongo::ConnectionFailure => ex
|
65
71
|
# @TODO: I don't like how I'm overloading @config.disabled
|
data/spec/config_spec.rb
CHANGED
@@ -43,7 +43,15 @@ describe Bunyan::Logger::Config, 'when setting the collection size' do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe Bunyan::Logger::Config, 'when getting the collection size' do
|
46
|
-
it 'should return the collection size'
|
46
|
+
it 'should return the collection size' do
|
47
|
+
Bunyan::Logger.configure do |c|
|
48
|
+
c.database 'test_db'
|
49
|
+
c.collection 'test_collection'
|
50
|
+
c.size 2929
|
51
|
+
end
|
52
|
+
|
53
|
+
Bunyan::Logger.config.size.should == 2929
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
57
|
describe Bunyan::Logger::Config, 'alternate method invocation syntax' do
|
@@ -158,3 +166,48 @@ describe 'when we configure a port' do
|
|
158
166
|
end
|
159
167
|
end
|
160
168
|
|
169
|
+
describe 'when we set a connection' do
|
170
|
+
|
171
|
+
def configure_with_connection
|
172
|
+
Bunyan::Logger.configure do |c|
|
173
|
+
c.connection = other_fake_mongo
|
174
|
+
c.port '20910'
|
175
|
+
c.database 'test_db'
|
176
|
+
c.collection 'test_collection'
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should not set a connection based on other params' do
|
181
|
+
Mongo::Connection.should_not_receive(:new)
|
182
|
+
configure_with_connection
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should set the db field' do
|
186
|
+
Mongo::Connection.should_not_receive(:new)
|
187
|
+
configure_with_connection
|
188
|
+
Bunyan::Logger.db.should eql(@mock_database)
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
describe 'the new configuration syntax' do
|
194
|
+
it 'should allow argument-less block configuration syntax' do
|
195
|
+
Bunyan::Logger.configure do
|
196
|
+
database 'new_config_db'
|
197
|
+
collection 'new_config_collection'
|
198
|
+
end
|
199
|
+
|
200
|
+
Bunyan::Logger.config.database.should == 'new_config_db'
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe 'the old configuration syntax' do
|
205
|
+
it 'should allow the configuration object to be passed in to the configure block' do
|
206
|
+
Bunyan::Logger.configure do |c|
|
207
|
+
c.database 'old_config_db'
|
208
|
+
c.collection 'old_config_collection'
|
209
|
+
end
|
210
|
+
|
211
|
+
Bunyan::Logger.config.database.should == 'old_config_db'
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'making a mongodb connection with the new configuration syntax' do
|
4
|
+
def configure_db_with_new_syntax
|
5
|
+
Bunyan::Logger.configure do
|
6
|
+
database 'bunyan_integration_db'
|
7
|
+
collection 'test_integration'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
Mongo::Connection.unstub!(:new)
|
13
|
+
configure_db_with_new_syntax
|
14
|
+
@params = {:request_uri => '/', :response_code => 200}
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should allow inserting documents' do
|
18
|
+
Bunyan::Logger.insert(@params).should be_instance_of BSON::ObjectID
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should allow querying documents' do
|
22
|
+
Bunyan::Logger.insert(@params)
|
23
|
+
Bunyan::Logger.find(@params).count.should == 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'making a mongodb connection with the old configuration syntax' do
|
28
|
+
def configure_db_with_old_syntax
|
29
|
+
Bunyan::Logger.configure do |c|
|
30
|
+
c.database 'bunyan_integration_db'
|
31
|
+
c.collection 'test_integration'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
Mongo::Connection.unstub!(:new)
|
37
|
+
configure_db_with_old_syntax
|
38
|
+
@params = {:request_uri => '/', :response_code => 200}
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should allow inserting documents' do
|
42
|
+
Bunyan::Logger.insert(@params).should be_instance_of BSON::ObjectID
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should allow querying documents' do
|
46
|
+
Bunyan::Logger.insert(@params)
|
47
|
+
Bunyan::Logger.find(@params).count.should == 1
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,9 @@ Bundler.require :default, :test
|
|
6
6
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/bunyan')
|
7
7
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
8
8
|
|
9
|
+
class DuckedMongo
|
10
|
+
end
|
11
|
+
|
9
12
|
Spec::Runner.configure do |config|
|
10
13
|
|
11
14
|
config.before :each do
|
@@ -25,6 +28,13 @@ Spec::Runner.configure do |config|
|
|
25
28
|
@mock_database
|
26
29
|
end
|
27
30
|
|
31
|
+
def other_fake_mongo
|
32
|
+
#I want to check Mongo::Connection.stub.new is not called
|
33
|
+
dm = DuckedMongo
|
34
|
+
dm.stub!(:db).and_return(@mock_database)
|
35
|
+
dm
|
36
|
+
end
|
37
|
+
|
28
38
|
def configure_test_db
|
29
39
|
Bunyan::Logger.configure do |config|
|
30
40
|
config.database 'bunyan_test'
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.4.0
|
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-
|
17
|
+
date: 2010-08-14 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- .gitignore
|
58
58
|
- CHANGELOG.md
|
59
59
|
- Gemfile
|
60
|
+
- MIT-LICENSE
|
60
61
|
- README.md
|
61
62
|
- Rakefile
|
62
63
|
- VERSION
|
@@ -64,8 +65,10 @@ files:
|
|
64
65
|
- examples/rails.rb
|
65
66
|
- lib/bunyan.rb
|
66
67
|
- lib/bunyan/config.rb
|
68
|
+
- lib/bunyan/configurable_methods.rb
|
67
69
|
- spec/bunyan_spec.rb
|
68
70
|
- spec/config_spec.rb
|
71
|
+
- spec/integration_spec.rb
|
69
72
|
- spec/spec.opts
|
70
73
|
- spec/spec_helper.rb
|
71
74
|
has_rdoc: true
|
@@ -101,5 +104,6 @@ summary: A MongoDB-based logging solution.
|
|
101
104
|
test_files:
|
102
105
|
- spec/bunyan_spec.rb
|
103
106
|
- spec/config_spec.rb
|
107
|
+
- spec/integration_spec.rb
|
104
108
|
- spec/spec_helper.rb
|
105
109
|
- examples/rails.rb
|