cabin 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cabin/channel.rb +37 -16
- data/lib/cabin/mixins/logger.rb +11 -0
- data/lib/cabin/mixins/terminal.rb +2 -1
- data/lib/cabin/mixins/timestamp.rb +1 -1
- data/lib/cabin/subscriber.rb +11 -0
- data/test/all.rb +3 -8
- data/test/{test_logging.rb → cabin/test_logging.rb} +14 -8
- data/test/{test_metrics.rb → cabin/test_metrics.rb} +1 -7
- data/test/{test_pipe.rb → cabin/test_pipe.rb} +1 -8
- data/test/{test_zeromq.rb → cabin/test_zeromq.rb} +1 -6
- data/test/{minitest-patch.rb → support/minitest-patch.rb} +0 -0
- data/test/test_helper.rb +8 -0
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4915c746a3d520ad14afb1c7e0ca4ba6c7fa83d
|
4
|
+
data.tar.gz: 6d4ef30f8c4cd39fa68abb1999f9c02c7aa21ff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa797866dca2939f349df4a898fa87e00d36c5adfcce1d213f894cda342a4df8751a2e3a3a655d3375108bb32d3a7e6400faa2ceb422bb6cfddf1b55173932c
|
7
|
+
data.tar.gz: 27e8f16b7893b2db64f582a28572d091c25578d26027a8f2d673cddb4264cd641a623e0286a6e9adbde6b8669d8385ecc0fe63cbe110b9ccaf6f73840ae12a07
|
data/lib/cabin/channel.rb
CHANGED
@@ -7,6 +7,7 @@ require "cabin/namespace"
|
|
7
7
|
require "cabin/context"
|
8
8
|
require "cabin/outputs/stdlib-logger"
|
9
9
|
require "cabin/outputs/io"
|
10
|
+
require "cabin/subscriber"
|
10
11
|
require "cabin/metrics"
|
11
12
|
require "logger" # stdlib
|
12
13
|
require "thread"
|
@@ -75,16 +76,33 @@ class Cabin::Channel
|
|
75
76
|
end
|
76
77
|
end # def Cabin::Channel.each
|
77
78
|
|
78
|
-
# Get a list of
|
79
|
-
def
|
80
|
-
@
|
81
|
-
end # def Cabin::Channel.
|
82
|
-
|
83
|
-
|
79
|
+
# Get a list of actions included in this class.
|
80
|
+
def actions
|
81
|
+
@actions ||= []
|
82
|
+
end # def Cabin::Channel.actions
|
83
|
+
alias_method(:filters, :actions) # DEPRECATED
|
84
|
+
|
85
|
+
# Register a new action. The block is passed the event. It is expected to
|
84
86
|
# modify that event or otherwise do nothing.
|
85
|
-
def
|
86
|
-
|
87
|
-
|
87
|
+
def action(&block)
|
88
|
+
actions << block
|
89
|
+
end
|
90
|
+
alias_method(:filter, :action) # DEPRECATED
|
91
|
+
|
92
|
+
# Get a list of conditions included in this class.
|
93
|
+
def conditions
|
94
|
+
@conditions ||= []
|
95
|
+
end
|
96
|
+
|
97
|
+
# Register a new condition. The block must expect an event and a subscription.
|
98
|
+
# It is expected to either return true (allow the event) or false (reject it).
|
99
|
+
def condition(&block)
|
100
|
+
conditions << block
|
101
|
+
end
|
102
|
+
|
103
|
+
# Decide to publish the event based on conditions and subscription options
|
104
|
+
def allow_event?(event, subscription)
|
105
|
+
conditions.all? { |condition| condition.call(event, subscription) }
|
88
106
|
end
|
89
107
|
end # class << self
|
90
108
|
|
@@ -115,7 +133,7 @@ class Cabin::Channel
|
|
115
133
|
# foo << event
|
116
134
|
#
|
117
135
|
# Returns a subscription id you can use later to unsubscribe
|
118
|
-
def subscribe(output)
|
136
|
+
def subscribe(output, options = {})
|
119
137
|
# Wrap ruby stdlib Logger if given.
|
120
138
|
if output.is_a?(::Logger)
|
121
139
|
output = Cabin::Outputs::StdlibLogger.new(output)
|
@@ -123,7 +141,7 @@ class Cabin::Channel
|
|
123
141
|
output = Cabin::Outputs::IO.new(output)
|
124
142
|
end
|
125
143
|
@subscriber_lock.synchronize do
|
126
|
-
@subscribers[output.object_id] = output
|
144
|
+
@subscribers[output.object_id] = Cabin::Subscriber.new(output, options)
|
127
145
|
end
|
128
146
|
return output.object_id
|
129
147
|
end # def subscribe
|
@@ -159,8 +177,9 @@ class Cabin::Channel
|
|
159
177
|
# is a string ISO8601 timestamp with microsecond precision.
|
160
178
|
def publish(data, &block)
|
161
179
|
event = {}
|
162
|
-
|
163
|
-
|
180
|
+
|
181
|
+
self.class.actions.each do |action|
|
182
|
+
action.call(event)
|
164
183
|
end
|
165
184
|
|
166
185
|
if data.is_a?(String)
|
@@ -171,9 +190,11 @@ class Cabin::Channel
|
|
171
190
|
event.merge!(@data) # Merge any logger context
|
172
191
|
|
173
192
|
@subscriber_lock.synchronize do
|
174
|
-
@subscribers.each do |
|
175
|
-
append =
|
176
|
-
|
193
|
+
@subscribers.each do |_, subscriber|
|
194
|
+
append = block_given? ? block.call(subscriber, event) : true
|
195
|
+
if append && self.class.allow_event?(event, subscriber)
|
196
|
+
subscriber << event
|
197
|
+
end
|
177
198
|
end
|
178
199
|
end
|
179
200
|
end # def publish
|
data/lib/cabin/mixins/logger.rb
CHANGED
@@ -3,6 +3,17 @@ require "cabin/namespace"
|
|
3
3
|
# This module implements methods that act somewhat like Ruby's Logger class
|
4
4
|
# It is included in Cabin::Channel
|
5
5
|
module Cabin::Mixins::Logger
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.condition do |event, subscription|
|
9
|
+
if subscription.nil?
|
10
|
+
true
|
11
|
+
else
|
12
|
+
LEVELS[(subscription.options[:level] || :debug)] >= LEVELS[event[:level]].to_i
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
6
17
|
attr_accessor :level
|
7
18
|
LEVELS = {
|
8
19
|
:fatal => 0,
|
data/test/all.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
|
-
|
1
|
+
require "test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
require "minitest/autorun"
|
5
|
-
require "simplecov"
|
3
|
+
base_dir = File.join(File.expand_path(File.dirname(__FILE__)), "cabin")
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
dir = File.dirname(File.expand_path(__FILE__))
|
10
|
-
Dir.glob(File.join(dir, "**", "test_*.rb")).each do |path|
|
5
|
+
Dir.glob(File.join(base_dir, "test_*.rb")).each do |path|
|
11
6
|
puts "Loading tests from #{path}"
|
12
7
|
if path =~ /test_zeromq/
|
13
8
|
puts "Skipping zeromq tests because they force ruby to exit if libzmq is not found"
|
@@ -1,11 +1,4 @@
|
|
1
|
-
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "lib")
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "minitest-patch"
|
6
|
-
require "cabin"
|
7
|
-
require "stringio"
|
8
|
-
require "minitest/autorun" if __FILE__ == $0
|
1
|
+
require "test_helper"
|
9
2
|
|
10
3
|
describe Cabin::Channel do
|
11
4
|
|
@@ -69,6 +62,19 @@ describe Cabin::Channel do
|
|
69
62
|
assert_equal("Hello world", @target.data[0][:message])
|
70
63
|
end
|
71
64
|
|
65
|
+
test "subscribe with a level impacts log publishing" do
|
66
|
+
sub1 = Receiver.new
|
67
|
+
sub2 = Receiver.new
|
68
|
+
@logger.subscribe(sub1, :level => :info)
|
69
|
+
@logger.subscribe(sub2, :level => :error)
|
70
|
+
@logger.debug("test debug")
|
71
|
+
@logger.info("test info")
|
72
|
+
@logger.error("test error")
|
73
|
+
|
74
|
+
assert_equal("test info", sub1.data[0][:message])
|
75
|
+
assert_equal("test error", sub1.data[1][:message])
|
76
|
+
assert_equal("test error", sub2.data[0][:message])
|
77
|
+
end
|
72
78
|
test "context values" do
|
73
79
|
context = @logger.context
|
74
80
|
context["foo"] = "hello"
|
@@ -1,11 +1,5 @@
|
|
1
|
-
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "lib")
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "minitest-patch"
|
6
|
-
require "cabin"
|
1
|
+
require "test_helper"
|
7
2
|
require "cabin/metrics"
|
8
|
-
require "minitest/autorun" if __FILE__ == $0
|
9
3
|
|
10
4
|
describe Cabin::Metrics do
|
11
5
|
before do
|
@@ -1,11 +1,4 @@
|
|
1
|
-
|
2
|
-
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'minitest-patch'
|
6
|
-
require 'cabin'
|
7
|
-
require 'stringio'
|
8
|
-
require 'minitest/autorun' if __FILE__ == $0
|
1
|
+
require "test_helper"
|
9
2
|
|
10
3
|
describe Cabin::Channel do
|
11
4
|
class Receiver
|
@@ -1,10 +1,5 @@
|
|
1
|
-
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..", "lib")
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "minitest-patch"
|
1
|
+
require "test_helper"
|
6
2
|
require "cabin/outputs/zeromq"
|
7
|
-
require "minitest/autorun" if __FILE__ == $0
|
8
3
|
|
9
4
|
describe Cabin::Outputs::ZeroMQ do
|
10
5
|
|
File without changes
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cabin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Sissel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
-
dependencies:
|
11
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 10.4.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 10.4.2
|
13
27
|
description: This is an experiment to try and make logging more flexible and more
|
14
28
|
consumable. Plain text logs are bullshit, let's emit structured and contextual logs.
|
15
29
|
Metrics, too!
|
@@ -53,13 +67,15 @@ files:
|
|
53
67
|
- lib/cabin/outputs/stdlib-logger.rb
|
54
68
|
- lib/cabin/outputs/zeromq.rb
|
55
69
|
- lib/cabin/publisher.rb
|
70
|
+
- lib/cabin/subscriber.rb
|
56
71
|
- lib/cabin/timer.rb
|
57
72
|
- test/all.rb
|
58
|
-
- test/
|
59
|
-
- test/
|
60
|
-
- test/
|
61
|
-
- test/
|
62
|
-
- test/
|
73
|
+
- test/cabin/test_logging.rb
|
74
|
+
- test/cabin/test_metrics.rb
|
75
|
+
- test/cabin/test_pipe.rb
|
76
|
+
- test/cabin/test_zeromq.rb
|
77
|
+
- test/support/minitest-patch.rb
|
78
|
+
- test/test_helper.rb
|
63
79
|
homepage: https://github.com/jordansissel/ruby-cabin
|
64
80
|
licenses:
|
65
81
|
- Apache License (2.0)
|
@@ -86,4 +102,3 @@ signing_key:
|
|
86
102
|
specification_version: 4
|
87
103
|
summary: Experiments in structured and contextual logging
|
88
104
|
test_files: []
|
89
|
-
has_rdoc:
|