cabin 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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: 2012-11-09 00:00:00.000000000 Z
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
- - !binary |-
23
- bGliL2NhYmluLnJi
24
- - !binary |-
25
- bGliL2NhYmluL2NoYW5uZWwucmI=
26
- - !binary |-
27
- bGliL2NhYmluL2NvbnRleHQucmI=
28
- - !binary |-
29
- bGliL2NhYmluL2luc3BlY3RhYmxlLnJi
30
- - !binary |-
31
- bGliL2NhYmluL21ldHJpYy5yYg==
32
- - !binary |-
33
- bGliL2NhYmluL21ldHJpY3MucmI=
34
- - !binary |-
35
- bGliL2NhYmluL25hbWVzcGFjZS5yYg==
36
- - !binary |-
37
- bGliL2NhYmluL3B1Ymxpc2hlci5yYg==
38
- - !binary |-
39
- bGliL2NhYmluL3RpbWVyLnJi
40
- - !binary |-
41
- bGliL2NhYmluL21ldHJpY3MvY291bnRlci5yYg==
42
- - !binary |-
43
- bGliL2NhYmluL21ldHJpY3MvZ2F1Z2UucmI=
44
- - !binary |-
45
- bGliL2NhYmluL21ldHJpY3MvaGlzdG9ncmFtLnJi
46
- - !binary |-
47
- bGliL2NhYmluL21ldHJpY3MvbWV0ZXIucmI=
48
- - !binary |-
49
- bGliL2NhYmluL21ldHJpY3MvdGltZXIucmI=
50
- - !binary |-
51
- bGliL2NhYmluL21peGlucy9DQVBTTE9DSy5yYg==
52
- - !binary |-
53
- bGliL2NhYmluL21peGlucy9jb2xvcnMucmI=
54
- - !binary |-
55
- bGliL2NhYmluL21peGlucy9kcmFnb25zLnJi
56
- - !binary |-
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==