cabin 0.5.0 → 0.6.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.
- data/examples/pipe.rb +14 -0
- data/lib/cabin/channel.rb +2 -0
- data/lib/cabin/mixins/pipe.rb +50 -0
- metadata +39 -70
data/examples/pipe.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "cabin"
|
2
|
+
require "open4"
|
3
|
+
|
4
|
+
cmd = 'strace -e trace=write date'
|
5
|
+
|
6
|
+
logger = Cabin::Channel.get
|
7
|
+
logger.subscribe(STDOUT)
|
8
|
+
logger.level = :info
|
9
|
+
|
10
|
+
status = Open4::popen4(cmd) do |pid, stdin, stdout, stderr|
|
11
|
+
stdin.close
|
12
|
+
logger.pipe(stdout => :info, stderr => :error)
|
13
|
+
end
|
14
|
+
|
data/lib/cabin/channel.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "cabin/mixins/logger"
|
2
|
+
require "cabin/mixins/pipe"
|
2
3
|
require "cabin/mixins/timestamp"
|
3
4
|
require "cabin/mixins/timer"
|
4
5
|
require "cabin/namespace"
|
@@ -88,6 +89,7 @@ class Cabin::Channel
|
|
88
89
|
|
89
90
|
include Cabin::Mixins::Timestamp
|
90
91
|
include Cabin::Mixins::Logger
|
92
|
+
include Cabin::Mixins::Pipe
|
91
93
|
include Cabin::Mixins::Timer
|
92
94
|
|
93
95
|
# All channels come with a metrics provider.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "cabin/namespace"
|
2
|
+
|
3
|
+
# This module provides a 'pipe' method which instructs cabin to pipe anything
|
4
|
+
# read from the IO given to be logged.
|
5
|
+
module Cabin::Mixins::Pipe
|
6
|
+
|
7
|
+
# Pipe IO objects to method calls on a logger.
|
8
|
+
#
|
9
|
+
# The argument is a hash of IO to method symbols.
|
10
|
+
#
|
11
|
+
# logger.pipe(io => :the_method)
|
12
|
+
#
|
13
|
+
# For each line read from 'io', logger.the_method(the_line) will be called.
|
14
|
+
#
|
15
|
+
# Example:
|
16
|
+
#
|
17
|
+
# cmd = "strace -e trace=write date"
|
18
|
+
# Open4::popen4(cmd) do |pid, stdin, stdout, stderr|
|
19
|
+
# stdin.close
|
20
|
+
#
|
21
|
+
# # Make lines from stdout be logged as 'info'
|
22
|
+
# # Make lines from stderr be logged as 'error'
|
23
|
+
# logger.pipe(stdout => :info, stderr => :error)
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Output:
|
27
|
+
#
|
28
|
+
# write(1, "Fri Jan 11 22:49:42 PST 2013\n", 29) = 29 {"level":"error"}
|
29
|
+
# Fri Jan 11 22:49:42 PST 2013 {"level":"info"}
|
30
|
+
# +++ exited with 0 +++ {"level":"error"}
|
31
|
+
def pipe(io_to_method_map)
|
32
|
+
fds = io_to_method_map.keys
|
33
|
+
|
34
|
+
while !fds.empty?
|
35
|
+
readers, _, _ = IO.select(fds, nil, nil, nil)
|
36
|
+
readers.each do |fd|
|
37
|
+
begin
|
38
|
+
line = fd.readline.chomp
|
39
|
+
rescue EOFError
|
40
|
+
fd.close rescue nil
|
41
|
+
fds.delete(fd)
|
42
|
+
next
|
43
|
+
end
|
44
|
+
|
45
|
+
method_name = io_to_method_map[fd]
|
46
|
+
send(method_name, line)
|
47
|
+
end # readers.each
|
48
|
+
end # while !fds.empty?
|
49
|
+
end # def pipe
|
50
|
+
end # module Cabin::Mixins::Logger
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cabin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.5.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jordan Sissel
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: This is an experiment to try and make logging more flexible and more consumable. Plain text logs are bullshit, let's emit structured and contextual logs. Metrics, too!
|
15
15
|
email:
|
@@ -19,72 +19,41 @@ executables:
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
-
-
|
23
|
-
|
24
|
-
-
|
25
|
-
|
26
|
-
-
|
27
|
-
|
28
|
-
-
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
-
|
33
|
-
|
34
|
-
-
|
35
|
-
|
36
|
-
-
|
37
|
-
|
38
|
-
-
|
39
|
-
|
40
|
-
-
|
41
|
-
|
42
|
-
-
|
43
|
-
|
44
|
-
-
|
45
|
-
|
46
|
-
-
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
-
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
-
|
55
|
-
|
56
|
-
-
|
57
|
-
bGliL2NhYmluL21peGlucy9sb2dnZXIucmI=
|
58
|
-
- !binary |-
|
59
|
-
bGliL2NhYmluL21peGlucy90aW1lci5yYg==
|
60
|
-
- !binary |-
|
61
|
-
bGliL2NhYmluL21peGlucy90aW1lc3RhbXAucmI=
|
62
|
-
- !binary |-
|
63
|
-
bGliL2NhYmluL291dHB1dHMvaW8ucmI=
|
64
|
-
- !binary |-
|
65
|
-
bGliL2NhYmluL291dHB1dHMvc3RkbGliLWxvZ2dlci5yYg==
|
66
|
-
- !binary |-
|
67
|
-
bGliL2NhYmluL291dHB1dHMvemVyb21xLnJi
|
68
|
-
- !binary |-
|
69
|
-
bGliL2NhYmluL291dHB1dHMvZW0vc3RkbGliLWxvZ2dlci5yYg==
|
70
|
-
- !binary |-
|
71
|
-
ZXhhbXBsZXMvZmlib25hY2NpLXRpbWluZy5yYg==
|
72
|
-
- !binary |-
|
73
|
-
ZXhhbXBsZXMvbWV0cmljcy5yYg==
|
74
|
-
- !binary |-
|
75
|
-
ZXhhbXBsZXMvc2FtcGxlLnJi
|
76
|
-
- !binary |-
|
77
|
-
ZXhhbXBsZXMvc2luYXRyYS1sb2dnaW5nLnJi
|
78
|
-
- !binary |-
|
79
|
-
dGVzdC9hbGwucmI=
|
80
|
-
- !binary |-
|
81
|
-
dGVzdC9taW5pdGVzdC1wYXRjaC5yYg==
|
82
|
-
- !binary |-
|
83
|
-
dGVzdC90ZXN0X2xvZ2dpbmcucmI=
|
84
|
-
- !binary |-
|
85
|
-
dGVzdC90ZXN0X21ldHJpY3MucmI=
|
86
|
-
- !binary |-
|
87
|
-
dGVzdC90ZXN0X3plcm9tcS5yYg==
|
22
|
+
- lib/cabin.rb
|
23
|
+
- lib/cabin/metrics.rb
|
24
|
+
- lib/cabin/timer.rb
|
25
|
+
- lib/cabin/namespace.rb
|
26
|
+
- lib/cabin/metric.rb
|
27
|
+
- lib/cabin/context.rb
|
28
|
+
- lib/cabin/publisher.rb
|
29
|
+
- lib/cabin/channel.rb
|
30
|
+
- lib/cabin/inspectable.rb
|
31
|
+
- lib/cabin/mixins/logger.rb
|
32
|
+
- lib/cabin/mixins/timer.rb
|
33
|
+
- lib/cabin/mixins/CAPSLOCK.rb
|
34
|
+
- lib/cabin/mixins/pipe.rb
|
35
|
+
- lib/cabin/mixins/colors.rb
|
36
|
+
- lib/cabin/mixins/timestamp.rb
|
37
|
+
- lib/cabin/mixins/dragons.rb
|
38
|
+
- lib/cabin/metrics/timer.rb
|
39
|
+
- lib/cabin/metrics/histogram.rb
|
40
|
+
- lib/cabin/metrics/meter.rb
|
41
|
+
- lib/cabin/metrics/gauge.rb
|
42
|
+
- lib/cabin/metrics/counter.rb
|
43
|
+
- lib/cabin/outputs/stdlib-logger.rb
|
44
|
+
- lib/cabin/outputs/io.rb
|
45
|
+
- lib/cabin/outputs/zeromq.rb
|
46
|
+
- lib/cabin/outputs/em/stdlib-logger.rb
|
47
|
+
- examples/metrics.rb
|
48
|
+
- examples/fibonacci-timing.rb
|
49
|
+
- examples/sample.rb
|
50
|
+
- examples/pipe.rb
|
51
|
+
- examples/sinatra-logging.rb
|
52
|
+
- test/test_metrics.rb
|
53
|
+
- test/all.rb
|
54
|
+
- test/minitest-patch.rb
|
55
|
+
- test/test_logging.rb
|
56
|
+
- test/test_zeromq.rb
|
88
57
|
- LICENSE
|
89
58
|
- CHANGELIST
|
90
59
|
- bin/rubygems-cabin-test
|
@@ -98,14 +67,14 @@ require_paths:
|
|
98
67
|
- lib
|
99
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
69
|
requirements:
|
101
|
-
- -
|
70
|
+
- - ">="
|
102
71
|
- !ruby/object:Gem::Version
|
103
72
|
version: !binary |-
|
104
73
|
MA==
|
105
74
|
none: false
|
106
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
76
|
requirements:
|
108
|
-
- -
|
77
|
+
- - ">="
|
109
78
|
- !ruby/object:Gem::Version
|
110
79
|
version: !binary |-
|
111
80
|
MA==
|