services 1.0.0 → 1.1.0

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: 06b81795775cc40d634101b8736c934f9bb64b75
4
- data.tar.gz: 5a80029a0b5da7660e4ecad40e6868f5ea444919
3
+ metadata.gz: 5e3a4eda849ba7c5dfa6aedd6fa7f405c942bb0e
4
+ data.tar.gz: 16e437174cf3a28070d2c70cb1fcbe4a0bc72a42
5
5
  SHA512:
6
- metadata.gz: e5148f72b9f1bd8ee35592bb106e0e25222c284d0eed74a94ec41dfd2daffe3fc2f90223f701e2dc2b24b42f33f27dbd38c0653adf1b703602738cccef1642bc
7
- data.tar.gz: 03b295a1abdda5f1377c720ffe4d292a360dd108dcd2ec0fc347477a44304382775f38b183c384b6e0069f668975ebd59cca3ce4a5d03d4fa15e8a475ae89a1a
6
+ metadata.gz: eab5ca8ffb5a39029b42351230b31aa2106ab36a9d93e008b16940c451d3a508bce74a7d243522b3a0dfdea004d88d7d926094ff0c2377b921af80a82c671e8c
7
+ data.tar.gz: 0932d4b1d53c5add16846778e117e73437018786043722f85c59087523992565ffe4a2cd3748f232ea96d91f00eea6cbf1e7c53ef8b425954afd387f40d8ca9d
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ ## 1.1.0
2
+
3
+ * Change arguments for log call in file and Redis logger, replace tag array with meta hash
4
+ * Add methods to query size of logs and fetch logs to Redis logger
5
+
6
+ ## 1.0.0
7
+
8
+ * Added Redis logger
9
+ * Moved file logger to separate class
10
+ * Don't initialize file logger automatically for Rails apps anymore
11
+ * Changed argument order for Redis and file logger, made `tags` parameter optional
12
+
13
+ ## 0.4.0
14
+
15
+ * Renamed `service_class` helper to `object_class`
16
+
17
+ ## 0.3.4
18
+
19
+ * Added `BaseFinder`
20
+ * Updated uniqueness key
@@ -9,7 +9,10 @@ module Services
9
9
  @logger.clear_tags!
10
10
  end
11
11
 
12
- def log(message, tags = [], severity = :info)
12
+ def log(message, meta = {}, severity = :info)
13
+ tags = meta.map do |k, v|
14
+ [k, v].join('=')
15
+ end
13
16
  @logger.tagged Time.now, severity.upcase, *tags do
14
17
  @logger.send severity, message
15
18
  end
@@ -5,16 +5,26 @@ module Services
5
5
  @redis, @key = redis, key
6
6
  end
7
7
 
8
- def log(message, tags = [], severity = :info)
8
+ def log(message, meta = {}, severity = :info)
9
9
  value = {
10
10
  time: Time.now.to_i,
11
11
  message: message,
12
12
  severity: severity,
13
- tags: tags
13
+ meta: meta
14
14
  }
15
15
  @redis.lpush @key, value.to_json
16
16
  end
17
17
 
18
+ def size
19
+ @redis.llen @key
20
+ end
21
+
22
+ def fetch
23
+ @redis.lrange(@key, 0, -1).map do |json|
24
+ JSON.load json
25
+ end
26
+ end
27
+
18
28
  def clear
19
29
  @redis.multi do
20
30
  @redis.lrange @key, 0, -1
@@ -21,7 +21,7 @@ module Services
21
21
  private
22
22
 
23
23
  def log(message, severity = :info)
24
- Services.configuration.logger.log message, [self.class, @id], severity
24
+ Services.configuration.logger.log message, { service: self.class, id: @id }, severity
25
25
  end
26
26
 
27
27
  def log_exception(e, cause = false)
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Services::Logger::Redis do
4
- let(:tags) { %w(foo bar baz) }
4
+ let(:meta) { { foo: 'bar' } }
5
5
  let(:message) { "One day baby we'll be old" }
6
6
  let(:severity) { 'critical' }
7
7
  let(:key) { 'custom_log_key' }
@@ -14,6 +14,15 @@ describe Services::Logger::Redis do
14
14
  end
15
15
  end
16
16
 
17
+ def create_logs
18
+ (2.days.ago.to_i..Time.now.to_i).step(1.hour) do |timestamp|
19
+ time = Time.at(timestamp)
20
+ Timecop.freeze time do
21
+ logger.log time.to_s(:long), weekday: time.strftime('%a')
22
+ end
23
+ end
24
+ end
25
+
17
26
  describe '#log' do
18
27
  it 'logs properly' do
19
28
  Timecop.freeze do
@@ -21,35 +30,41 @@ describe Services::Logger::Redis do
21
30
  'time' => Time.now.to_i,
22
31
  'message' => message,
23
32
  'severity' => severity,
24
- 'tags' => tags
33
+ 'meta' => meta.stringify_keys
25
34
  }
26
35
  expect do
27
- logger.log message, tags, severity
36
+ logger.log message, meta, severity
28
37
  end.to change { log_entries }.from([]).to([payload])
29
38
  end
30
39
  end
31
40
  end
32
41
 
33
- describe '#clear' do
42
+ context 'when logs are present' do
34
43
  before do
35
- (2.days.ago.to_i..Time.now.to_i).step(1.hour) do |timestamp|
36
- time = Time.at(timestamp)
37
- Timecop.freeze time do
38
- tags = [time.strftime('%a')]
39
- logger.log tags, time.to_s(:long)
40
- end
41
- end
44
+ create_logs
42
45
  expect(log_entries.size).to be > 0
43
46
  end
44
47
 
45
- it 'returns all log entries' do
46
- expect(log_entries).to eq(logger.clear)
48
+ describe '#size' do
49
+ it 'returns the amount of logs' do
50
+ expect(logger.size).to eq(log_entries.size)
51
+ end
52
+ end
53
+
54
+ describe '#fetch' do
55
+ it 'returns all logs' do
56
+ expect(logger.fetch).to eq(log_entries)
57
+ end
47
58
  end
48
59
 
49
- it 'clears all log entries' do
50
- expect do
51
- logger.clear
52
- end.to change { log_entries }.to([])
60
+ describe '#clear' do
61
+ it 'returns all logs' do
62
+ expect(log_entries).to eq(logger.clear)
63
+ end
64
+
65
+ it 'clears all log entries' do
66
+ expect { logger.clear }.to change { log_entries }.to([])
67
+ end
53
68
  end
54
69
  end
55
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: services
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-14 00:00:00.000000000 Z
11
+ date: 2014-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -144,6 +144,7 @@ extra_rdoc_files: []
144
144
  files:
145
145
  - ".gitignore"
146
146
  - ".travis.yml"
147
+ - CHANGELOG.md
147
148
  - Gemfile
148
149
  - Guardfile
149
150
  - LICENSE.txt