cabin 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELIST +3 -0
- data/lib/cabin/mixins/logger.rb +22 -1
- data/test/test_logging.rb +16 -0
- metadata +40 -60
- data/lib/test.rb +0 -8
data/CHANGELIST
CHANGED
data/lib/cabin/mixins/logger.rb
CHANGED
@@ -33,7 +33,28 @@ module Cabin::Mixins::Logger
|
|
33
33
|
|
34
34
|
# def info, def warn, etc...
|
35
35
|
|
36
|
-
|
36
|
+
# Arguments: message, data, data is assumed to be {} if nil
|
37
|
+
# This hack is necessary because ruby 1.8 doesn't support default arguments
|
38
|
+
# on blocks.
|
39
|
+
define_method(level) do |*args| #|message, data={}|
|
40
|
+
if args.size < 1
|
41
|
+
raise ::ArgumentError.new("#{self.class.name}##{level}(message, " \
|
42
|
+
"data={}) requires at least 1 argument")
|
43
|
+
end
|
44
|
+
if args.size > 2
|
45
|
+
raise ::ArgumentError.new("#{self.class.name}##{level}(message, " \
|
46
|
+
"data={}) takes at most 2 arguments")
|
47
|
+
end
|
48
|
+
|
49
|
+
message = args[0]
|
50
|
+
data = args[1] || {}
|
51
|
+
|
52
|
+
if not data.is_a?(Hash)
|
53
|
+
raise ::ArgumentError.new("#{self.class.name}##{level}(message, " \
|
54
|
+
"data={}) - second argument you gave me was" \
|
55
|
+
"a #{data.class.name}, I require a Hash.")
|
56
|
+
end
|
57
|
+
|
37
58
|
log(level, message, data) if send(predicate)
|
38
59
|
end
|
39
60
|
|
data/test/test_logging.rb
CHANGED
@@ -123,4 +123,20 @@ describe Cabin::Channel do
|
|
123
123
|
assert(!event.include?(:line), "At non-debug level, there should not be a :line attribute")
|
124
124
|
assert(!event.include?(:method), "At non-debug level, there should not be a :method attribute")
|
125
125
|
end
|
126
|
+
|
127
|
+
test "invalid arguments to logger.info raises ArgumentError" do
|
128
|
+
assert_raises(ArgumentError, "logger.info() should raise ArgumentError") do
|
129
|
+
@logger.info()
|
130
|
+
end
|
131
|
+
|
132
|
+
assert_raises(ArgumentError, "logger.info('foo', 'bar') should raise " \
|
133
|
+
"ArgumentError because 'bar' is not a Hash.") do
|
134
|
+
@logger.info("foo", "bar")
|
135
|
+
end
|
136
|
+
|
137
|
+
assert_raises(ArgumentError, "logger.info('foo', { 'foo': 'bar' }, 'baz')" \
|
138
|
+
"should raise ArgumentError for too many arguments") do
|
139
|
+
@logger.info("foo", { "foo" => "bar" }, "bar")
|
140
|
+
end
|
141
|
+
end
|
126
142
|
end # describe Cabin::Channel do
|
metadata
CHANGED
@@ -1,97 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cabin
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 6
|
10
|
-
version: 0.1.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jordan Sissel
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-08 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: json
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &23531280 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *23531280
|
25
|
+
description: This is an experiment to try and make logging more flexible and more
|
26
|
+
consumable. Plain text logs are bullshit, let's emit structured and contextual logs.
|
27
|
+
email:
|
36
28
|
- jls@semicomplete.com
|
37
|
-
executables:
|
29
|
+
executables:
|
38
30
|
- rubygems-cabin-test
|
39
31
|
extensions: []
|
40
|
-
|
41
32
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
|
44
|
-
- lib/test.rb
|
45
|
-
- lib/cabin/context.rb
|
46
|
-
- lib/cabin/timer.rb
|
47
|
-
- lib/cabin/outputs/stdlib-logger.rb
|
33
|
+
files:
|
34
|
+
- lib/cabin.rb
|
48
35
|
- lib/cabin/outputs/em-stdlib-logger.rb
|
49
|
-
- lib/cabin/
|
50
|
-
- lib/cabin/mixins/dragons.rb
|
51
|
-
- lib/cabin/namespace.rb
|
36
|
+
- lib/cabin/outputs/stdlib-logger.rb
|
52
37
|
- lib/cabin/channel.rb
|
53
|
-
- lib/cabin.rb
|
38
|
+
- lib/cabin/namespace.rb
|
39
|
+
- lib/cabin/timer.rb
|
40
|
+
- lib/cabin/context.rb
|
41
|
+
- lib/cabin/mixins/dragons.rb
|
42
|
+
- lib/cabin/mixins/logger.rb
|
54
43
|
- examples/fibonacci-timing.rb
|
55
44
|
- examples/sinatra-logging.rb
|
56
45
|
- examples/sample.rb
|
57
|
-
- test/test_logging.rb
|
58
46
|
- test/minitest-patch.rb
|
47
|
+
- test/test_logging.rb
|
59
48
|
- LICENSE
|
60
49
|
- CHANGELIST
|
61
50
|
- bin/rubygems-cabin-test
|
62
51
|
homepage: https://github.com/jordansissel/ruby-cabin
|
63
|
-
licenses:
|
52
|
+
licenses:
|
64
53
|
- Apache License (2.0)
|
65
54
|
post_install_message:
|
66
55
|
rdoc_options: []
|
67
|
-
|
68
|
-
require_paths:
|
56
|
+
require_paths:
|
69
57
|
- lib
|
70
58
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
60
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
- 0
|
79
|
-
version: "0"
|
80
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
66
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
version: "0"
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
89
71
|
requirements: []
|
90
|
-
|
91
72
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.8.10
|
93
74
|
signing_key:
|
94
75
|
specification_version: 3
|
95
76
|
summary: Experiments in structured and contextual logging
|
96
77
|
test_files: []
|
97
|
-
|