alephant-logger 0.2.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de780cad17918478c874e67e2b92f664e4be91ee
4
- data.tar.gz: aaa9ae2aca771d382386706ada2cceb59171249e
3
+ metadata.gz: 64032058c0749b0c64d5032d751481b4ca84b442
4
+ data.tar.gz: 73684eaf331ef5d93818846ba82300dfb9480738
5
5
  SHA512:
6
- metadata.gz: 2dee305aad70a33dc38ac5f64e9ba51851298bb16e42d3be030b6827d14546bb951a492fcb0b93c98d342150b848a952191ce2019f9cd5f645c42e69c59d06cc
7
- data.tar.gz: 41753b2edd992d33a8c330e75035deb733b514c16760bd7dd95b00f952230c3ff40a5d47d1975f185d48424dd93504977c8695d3e2197fee31cf643e4b5ce684
6
+ metadata.gz: 392a50cf2e51c7e53d7a2e013969d6f9c19f8d543eaa7e01c29599b6fa087d79264c31f1d3d414e976ff60339f7374f63de455f080a54c0a35ffb56f6912b731
7
+ data.tar.gz: 9a9389935f96c1b6e019a8399046bedb6951dc860d78b1df16ed0768e9f57ea89c16d0a5cea07264103ea4991d7f5a6a7bda45a7bf767a53788e207db162df18
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- jruby-1.7.9
1
+ jruby-1.7
data/README.md CHANGED
@@ -1,93 +1,61 @@
1
1
  # Alephant::Logger
2
2
 
3
- Logger functionality for Alephant
3
+ Logger functionality for BBC News' [Alephant](https://github.com/BBC-News/alephant) framework.
4
4
 
5
5
  [![Build
6
- Status](https://travis-ci.org/BBC-News/alephant-logger.png)](https://travis-ci.org/BBC-News/alephant-logger)
7
-
8
- [![Gem Version](https://badge.fury.io/rb/alephant-logger.png)](http://badge.fury.io/rb/alephant-logger)
6
+ Status](https://travis-ci.org/BBC-News/alephant-logger.png)](https://travis-ci.org/BBC-News/alephant-logger) [![Gem Version](https://badge.fury.io/rb/alephant-logger.png)](http://badge.fury.io/rb/alephant-logger)
9
7
 
10
8
  ## Installation
11
9
 
12
10
  Add this line to your application's Gemfile:
13
11
 
14
- gem 'alephant-logger'
12
+ ```
13
+ gem 'alephant-logger'
14
+ ```
15
15
 
16
16
  And then execute:
17
17
 
18
+ ```
18
19
  $ bundle
20
+ ```
19
21
 
20
22
  Or install it yourself as:
21
23
 
24
+ ```
22
25
  $ gem install alephant-logger
26
+ ```
23
27
 
24
28
  ## Usage
25
29
 
26
30
  ```rb
27
- require 'alephant/logger'
28
-
29
- # Using the standard logger
30
- class IncludesLogger
31
- include Alephant::Logger
32
-
33
- def calls_logger
34
- logger.warn "MUCH WARN. WOW."
35
- end
36
- end
37
-
38
- # Sets a logger
39
- class SetsLogger
40
- include Alephant::Logger
41
-
42
- def calls_logger
43
- Alephant::Logger.set_logger(CustomLogger.new)
44
- logger.warn "SUCH CUSTOM. MUCH LOG."
45
- end
46
- end
47
- ```
48
-
49
- ### AWS CloudWatch Metrics
50
-
51
- ```ruby
52
- require "aws-sdk"
53
31
  require "alephant/logger"
54
- require "alephant/logger/cloudwatch_decorator"
32
+ require "alephant/logger/statsd"
33
+ require "alephant/logger/cloudwatch"
55
34
 
56
- AWS.config(
57
- :region => "eu-west-1",
58
- :access_key_id => "ACCESS_KEY_ID",
59
- :secret_access_key => "SECRET_ACCESS_KEY",
60
- :session_token => "SESSION_TOKEN"
61
- )
35
+ config = {
36
+ :host => "statsd.test.service.bbc.co.uk",
37
+ :port => 6452,
38
+ :namespace => "test"
39
+ }
62
40
 
63
- LOGGER = Alephant::Logger::CloudWatchDecorator.new(
64
- Logger.new("app.log"), "SomeCloudWatchMetricNameSpace"
65
- )
41
+ statsd_driver = Alephant::Logger::Statsd.new config
42
+ cloudwatch_driver = Alephant::Logger::CloudWatch.new "my_namespace"
66
43
 
67
- Alephant::Logger.set_logger LOGGER
68
-
69
- class Foo
70
- include Alephant::Logger
44
+ logger = Alephant::Logger.create([statsd_driver, cloudwatch_driver])
45
+ logger.increment "foo.bar"
46
+ logger.metric(:name => "FooBar", :unit => "Count", :value => 1)
47
+ ```
71
48
 
72
- def initialize
73
- logger.info "some info"
74
- logger.debug "much debug"
75
- logger.error "great error"
76
- logger.warn "so warn"
77
- logger.fatal "ooh fatal"
49
+ ## Drivers
78
50
 
79
- # Without the CloudWatchDecorator the `metric` call is a no-op
80
- logger.metric({:name => "SomeMetricName", :unit => "Count", :value => 1})
81
- end
82
- end
51
+ You can consume an array of other gems to allow Alephant Logger to send custom metrics:
83
52
 
84
- Foo.new
85
- ```
53
+ 1. [Statsd](https://github.com/BBC-News/alephant-logger-statsd#alephantloggerstatsd)
86
54
 
87
55
  ## Contributing
88
56
 
89
- 1. Fork it ( http://github.com/BBC-News/alephant-logger/fork )
90
- 2. Create your feature branch (`git checkout -b my-new-feature`)
91
- 3. Commit your changes (`git commit -am 'Add some feature'`)
92
- 4. Push to the branch (`git push origin my-new-feature`)
93
- 5. Create new Pull Request
57
+ 1. [Fork it!](http://github.com/BBC-News/alephant-logger/fork)
58
+ 2. Create your feature branch: `git checkout -b my-new-feature`
59
+ 3. Commit your changes: `git commit -am 'Add some feature'`
60
+ 4. Push to the branch: `git push origin my-new-feature`
61
+ 5. Create new [Pull Request](https://github.com/BBC-News/alephant-logger/compare).
@@ -17,8 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_runtime_dependency "aws-sdk"
21
-
22
20
  spec.add_development_dependency "rspec"
23
21
  spec.add_development_dependency "rspec-nc"
24
22
  spec.add_development_dependency "guard"
@@ -2,35 +2,32 @@ require 'alephant/logger/version'
2
2
  require 'logger'
3
3
 
4
4
  module Alephant
5
- class DelegatingLogger
6
- attr_reader :logger
7
-
8
- def initialize(logger)
9
- @logger = logger
10
- end
11
-
12
- def method_missing(name, *args)
13
- logger.send(name, *args) if logger.respond_to? name
5
+ module Logger
6
+ def self.create(drivers = [])
7
+ Logger.new drivers
14
8
  end
15
9
 
16
- def respond_to?(name)
17
- logger.respond_to? name || super
18
- end
19
- end
10
+ class Logger
11
+ def initialize(drivers)
12
+ @drivers = drivers << ::Logger.new(STDOUT)
13
+ end
20
14
 
21
- module Logger
22
- @@logger = nil
15
+ def method_missing(name, *args)
16
+ drivers.each do |driver|
17
+ driver.send(name, *args) if driver.respond_to? name
18
+ end
19
+ end
23
20
 
24
- def logger
25
- ::Alephant::Logger.get_logger
26
- end
21
+ def respond_to?(name)
22
+ drivers.any? do |driver|
23
+ driver.respond_to?(name) || super
24
+ end
25
+ end
27
26
 
28
- def self.get_logger
29
- @@logger ||= Alephant::DelegatingLogger.new ::Logger.new(STDOUT)
30
- end
27
+ private
31
28
 
32
- def self.set_logger(value)
33
- @@logger = Alephant::DelegatingLogger.new value
29
+ attr_reader :drivers
34
30
  end
35
31
  end
36
32
  end
33
+
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Logger
3
- VERSION = "0.2.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
data/spec/logger_spec.rb CHANGED
@@ -1,45 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Alephant::Logger do
4
- describe ".get_logger" do
5
-
6
- context "no logger set" do
7
- specify {
8
- expect(subject.get_logger.logger).to be_a Logger
9
- }
4
+ describe ".create" do
5
+ specify do
6
+ expect(subject.create).to be_a Alephant::Logger::Logger
10
7
  end
8
+ end
9
+ end
11
10
 
12
- context "subject.set_logger(:foo)" do
13
- it "returns @@logger" do
14
- subject.class_variable_set(:@@logger, :foo)
15
- expect(subject.get_logger).to eq(:foo)
11
+ describe Alephant::Logger::Logger do
12
+ describe "#info" do
13
+ context "no logger drivers given" do
14
+ subject { Alephant::Logger::Logger.new [] }
15
+
16
+ specify do
17
+ expect_any_instance_of(::Logger).to receive(:info).with "msg"
18
+
19
+ subject.info "msg"
16
20
  end
17
21
  end
18
- end
19
22
 
20
- describe ".set_logger(:foo)" do
21
- it "sets foo as @@logger" do
22
- subject.set_logger(:bar)
23
- expect(subject.class_variable_get(:@@logger).logger).to eq :bar
24
- end
25
- end
23
+ context "logger drivers given" do
24
+ subject { Alephant::Logger::Logger.new [driver] }
26
25
 
27
- context "when included in a class" do
26
+ let(:driver) { double }
28
27
 
29
- class IncludesLog
30
- include Alephant::Logger
28
+ it "responding drivers receive method calls" do
29
+ expect(driver).to receive(:metric).with("foo")
31
30
 
32
- def calls_logger
33
- logger
31
+ subject.metric("foo")
34
32
  end
35
- end
36
33
 
37
- context "called via '#logger'" do
38
- it "returns the value of @@logger" do
39
- subject.class_variable_set(:@@logger, :baz)
40
- expect(IncludesLog.new.calls_logger).to eq :baz
34
+ it "::Logger is always used" do
35
+ expect_any_instance_of(::Logger).to receive(:info).with "foo"
36
+
37
+ subject.info "foo"
41
38
  end
42
39
  end
43
-
44
40
  end
45
41
  end
metadata CHANGED
@@ -1,156 +1,142 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Kenny
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aws-sdk
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - '>='
18
17
  - !ruby/object:Gem::Version
19
18
  version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
19
  name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
20
  prerelease: false
21
+ type: :development
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - '>='
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rspec-nc
43
28
  requirement: !ruby/object:Gem::Requirement
44
29
  requirements:
45
30
  - - '>='
46
31
  - !ruby/object:Gem::Version
47
32
  version: '0'
48
- type: :development
33
+ name: rspec-nc
49
34
  prerelease: false
35
+ type: :development
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - '>='
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: guard
57
42
  requirement: !ruby/object:Gem::Requirement
58
43
  requirements:
59
44
  - - '>='
60
45
  - !ruby/object:Gem::Version
61
46
  version: '0'
62
- type: :development
47
+ name: guard
63
48
  prerelease: false
49
+ type: :development
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - '>='
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
56
  requirement: !ruby/object:Gem::Requirement
72
57
  requirements:
73
58
  - - '>='
74
59
  - !ruby/object:Gem::Version
75
60
  version: '0'
76
- type: :development
61
+ name: guard-rspec
77
62
  prerelease: false
63
+ type: :development
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - '>='
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
- name: pry
85
70
  requirement: !ruby/object:Gem::Requirement
86
71
  requirements:
87
72
  - - '>='
88
73
  - !ruby/object:Gem::Version
89
74
  version: '0'
90
- type: :development
75
+ name: pry
91
76
  prerelease: false
77
+ type: :development
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - '>='
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: pry-remote
99
84
  requirement: !ruby/object:Gem::Requirement
100
85
  requirements:
101
86
  - - '>='
102
87
  - !ruby/object:Gem::Version
103
88
  version: '0'
104
- type: :development
89
+ name: pry-remote
105
90
  prerelease: false
91
+ type: :development
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - '>='
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: pry-nav
113
98
  requirement: !ruby/object:Gem::Requirement
114
99
  requirements:
115
100
  - - '>='
116
101
  - !ruby/object:Gem::Version
117
102
  version: '0'
118
- type: :development
103
+ name: pry-nav
119
104
  prerelease: false
105
+ type: :development
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - '>='
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: bundler
127
112
  requirement: !ruby/object:Gem::Requirement
128
113
  requirements:
129
114
  - - ~>
130
115
  - !ruby/object:Gem::Version
131
116
  version: '1.5'
132
- type: :development
117
+ name: bundler
133
118
  prerelease: false
119
+ type: :development
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - ~>
137
123
  - !ruby/object:Gem::Version
138
124
  version: '1.5'
139
125
  - !ruby/object:Gem::Dependency
140
- name: rake
141
126
  requirement: !ruby/object:Gem::Requirement
142
127
  requirements:
143
128
  - - '>='
144
129
  - !ruby/object:Gem::Version
145
130
  version: '0'
146
- type: :development
131
+ name: rake
147
132
  prerelease: false
133
+ type: :development
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - '>='
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0'
153
- description:
139
+ description:
154
140
  email:
155
141
  - kenoir@gmail.com
156
142
  executables: []
@@ -167,7 +153,6 @@ files:
167
153
  - Rakefile
168
154
  - alephant-logger.gemspec
169
155
  - lib/alephant/logger.rb
170
- - lib/alephant/logger/cloudwatch_decorator.rb
171
156
  - lib/alephant/logger/version.rb
172
157
  - spec/logger_spec.rb
173
158
  - spec/spec_helper.rb
@@ -175,7 +160,7 @@ homepage: ''
175
160
  licenses:
176
161
  - MIT
177
162
  metadata: {}
178
- post_install_message:
163
+ post_install_message:
179
164
  rdoc_options: []
180
165
  require_paths:
181
166
  - lib
@@ -190,9 +175,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
175
  - !ruby/object:Gem::Version
191
176
  version: '0'
192
177
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.0.14
195
- signing_key:
178
+ rubyforge_project:
179
+ rubygems_version: 2.1.9
180
+ signing_key:
196
181
  specification_version: 4
197
182
  summary: Logger functionality for Alephant
198
183
  test_files:
@@ -1,57 +0,0 @@
1
- require "aws-sdk"
2
-
3
- module Alephant
4
- module Logger
5
- class CloudWatchDecorator
6
- ONE_HOUR = 3600
7
-
8
- def initialize(logger, namespace)
9
- @logger = logger
10
- @namespace = namespace
11
- @cloudwatch = AWS::CloudWatch.new
12
- end
13
-
14
- def metric(opts)
15
- name, value, unit, dimensions = opts.values_at(:name, :value, :unit, :dimensions)
16
-
17
- Thread.new do
18
- cloudwatch.put_metric_data(
19
- :namespace => namespace,
20
- :metric_data => [{
21
- :metric_name => name,
22
- :value => value,
23
- :unit => unit || "None",
24
- :dimensions => parse(dimensions || {})
25
- }]
26
- )
27
- end
28
- end
29
-
30
- # Ruby's Kernel implements a `warn` method
31
- def warn(*args)
32
- logger.warn(*args)
33
- end
34
-
35
- def method_missing(name, *args)
36
- logger.send(name, *args)
37
- end
38
-
39
- def respond_to?(name)
40
- logger.respond_to?(name) || super
41
- end
42
-
43
- private
44
-
45
- attr_reader :logger, :cloudwatch, :namespace
46
-
47
- def parse(dimensions)
48
- dimensions.map do |name, value|
49
- {
50
- :name => name,
51
- :value => value
52
- }
53
- end
54
- end
55
- end
56
- end
57
- end