cabin 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require "cabin"
5
5
  require "logger"
6
6
 
7
7
  $logger = Cabin::Channel.new
8
- $logger.subscribe(Cabin.new(STDOUT))
8
+ $logger.subscribe(Logger.new(STDOUT))
9
9
 
10
10
  def serve_it_up(arg)
11
11
  $logger.info("Serving it up")
data/lib/cabin/channel.rb CHANGED
@@ -55,6 +55,8 @@ class Cabin::Channel
55
55
  end # def initialize
56
56
 
57
57
  # Subscribe a new input
58
+ # New events will be sent to the subscriber using the '<<' method
59
+ # foo << event
58
60
  public
59
61
  def subscribe(output)
60
62
  # Wrap ruby stdlib Logger if given.
@@ -0,0 +1,16 @@
1
+ require "cabin/namespace"
2
+
3
+ # What kind of metrics do we want?
4
+ # Per-call/transaction/request metrics like:
5
+ # - hit (count++ type metrics)
6
+ # - latencies/timings
7
+ #
8
+ # Per app or generally long-lifetime metrics like:
9
+ # - "uptime"
10
+ # - cpu usage
11
+ # - memory usage
12
+ # - count of active/in-flight actions/requests/calls/transactions
13
+ # - peer metrics (number of cluster members, etc)
14
+ module Cabin::Mixins::Metrics
15
+
16
+ end # module Cabin::Mixins::Metrics
@@ -1,4 +1,6 @@
1
1
  module Cabin
2
- module Outputs; end
2
+ module Outputs
3
+ module EM; end
4
+ end
3
5
  module Mixins; end
4
6
  end
@@ -6,24 +6,25 @@ require "eventmachine"
6
6
  # allows you to output to a normal ruby logger with Cabin. Since
7
7
  # Ruby's Logger has a love for strings alone, this wrapper will
8
8
  # convert the data/event to json before sending it to Logger.
9
- class Cabin::Outputs::EmStdlibLogger
9
+ class Cabin::Outputs::EM::StdlibLogger
10
10
  public
11
11
  def initialize(logger)
12
12
  @logger_queue = EM::Queue.new
13
13
  @logger = logger
14
- consumer # Consume lines from a queue and send them with logger
15
- end # def initialize
14
+ # Consume log lines from a queue and send them with logger
15
+ consumer
16
+ end
16
17
 
17
18
  def consumer
18
19
  line_sender = Proc.new do |line|
19
20
  # This will call @logger.info(data) or something similar
20
21
  @logger.send(line[:method], line[:message])
21
- EM.next_tick do
22
- # Do it again
22
+ EM::next_tick do
23
+ # Pop another line off the queue and do it again
23
24
  @logger_queue.pop(&line_sender)
24
25
  end
25
26
  end
26
- # Pop line off queue and send it with logger
27
+ # Pop a line off the queue and send it with logger
27
28
  @logger_queue.pop(&line_sender)
28
29
  end
29
30
 
@@ -33,7 +34,12 @@ class Cabin::Outputs::EmStdlibLogger
33
34
  line = Hash.new
34
35
  line[:method] = data[:level] || "info"
35
36
  line[:message] = "#{data[:message]} #{data.to_json}"
36
- # Push line onto queue for later sending
37
- @logger_queue.push(line)
38
- end # def <<
39
- end # class Cabin::Outputs::EmStdlibLogger
37
+ if EM::reactor_running?
38
+ # Push line onto queue for later sending
39
+ @logger_queue.push(line)
40
+ else
41
+ # This will call @logger.info(data) or something similar
42
+ @logger.send(line[:method], line[:message])
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,44 +1,54 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cabin
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.7
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 8
9
+ version: 0.1.8
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Jordan Sissel
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2011-11-08 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-01-13 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: json
16
- requirement: &23531280 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
22
31
  type: :runtime
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:
32
+ version_requirements: *id001
33
+ 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.
34
+ email:
28
35
  - jls@semicomplete.com
29
- executables:
36
+ executables:
30
37
  - rubygems-cabin-test
31
38
  extensions: []
39
+
32
40
  extra_rdoc_files: []
33
- files:
41
+
42
+ files:
34
43
  - lib/cabin.rb
35
- - lib/cabin/outputs/em-stdlib-logger.rb
44
+ - lib/cabin/outputs/em/stdlib-logger.rb
36
45
  - lib/cabin/outputs/stdlib-logger.rb
37
46
  - lib/cabin/channel.rb
38
47
  - lib/cabin/namespace.rb
39
48
  - lib/cabin/timer.rb
40
49
  - lib/cabin/context.rb
41
50
  - lib/cabin/mixins/dragons.rb
51
+ - lib/cabin/mixins/metrics.rb
42
52
  - lib/cabin/mixins/logger.rb
43
53
  - examples/fibonacci-timing.rb
44
54
  - examples/sinatra-logging.rb
@@ -48,30 +58,38 @@ files:
48
58
  - LICENSE
49
59
  - CHANGELIST
50
60
  - bin/rubygems-cabin-test
61
+ has_rdoc: true
51
62
  homepage: https://github.com/jordansissel/ruby-cabin
52
- licenses:
63
+ licenses:
53
64
  - Apache License (2.0)
54
65
  post_install_message:
55
66
  rdoc_options: []
56
- require_paths:
67
+
68
+ require_paths:
57
69
  - lib
58
70
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
71
+ required_ruby_version: !ruby/object:Gem::Requirement
60
72
  none: false
61
- requirements:
62
- - - ! '>='
63
- - !ruby/object:Gem::Version
64
- version: '0'
65
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
80
  none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
71
87
  requirements: []
88
+
72
89
  rubyforge_project:
73
- rubygems_version: 1.8.10
90
+ rubygems_version: 1.3.7
74
91
  signing_key:
75
92
  specification_version: 3
76
93
  summary: Experiments in structured and contextual logging
77
94
  test_files: []
95
+