services 1.2.0 → 1.3.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: 5badc829e3bbaa1e7dfde3b0578580a95c590cdd
4
- data.tar.gz: 245f341ba15aa65aebb1707fdf7301727ac45d0d
3
+ metadata.gz: 5d81b81f1b90d4c408865594ca48558fe9469e7d
4
+ data.tar.gz: a33b8e7d9007b638feddadd7270780756a083a0f
5
5
  SHA512:
6
- metadata.gz: 7ac343f2d578b4a90424d65dea68526d73e7383466f91c5be9160045e06791796537f80c584e5edeb30b045b4b07960f4a3e0b898853e24399cff134abdb8848
7
- data.tar.gz: 32759e41c136880fe9aa566fca32035f9b5815a1e31c4bae45a5df556d74a172d1d8ed2223c2b450d1e779ad8010c687be6cd42fa62bde00565055894681d10e
6
+ metadata.gz: 28c253c6305653cd64b7fed56a905d6b4215f6ca579500ac3c0015f6ed0c682958478771b7a7b45bd90360b86b745bfa8c19b1d5814e845476d65bb1e107747f
7
+ data.tar.gz: 0942c38383e122fdf186cde9fd278c684d1e2fe8211b82724fb306f6bd168bf8b587abe362c61927a87752326276ef488d331227e856ceabfb39def0453fcb72
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.3.0
2
+
3
+ * Allow only certain classes in Redis logger meta (NilClass, TrueClass, FalseClass, Symbol, String, Numeric)
4
+
1
5
  ## 1.2.0
2
6
 
3
7
  * Convert log time to time object when fetching logs
@@ -9,7 +9,7 @@ module Services
9
9
  @logger.clear_tags!
10
10
  end
11
11
 
12
- def log(message, meta = {}, severity = :info)
12
+ def log(message, meta = {}, severity = 'info')
13
13
  tags = meta.map do |k, v|
14
14
  [k, v].join('=')
15
15
  end
@@ -1,16 +1,30 @@
1
1
  module Services
2
2
  module Logger
3
3
  class Redis
4
+ META_CLASSES = [
5
+ NilClass,
6
+ TrueClass,
7
+ FalseClass,
8
+ Symbol,
9
+ String,
10
+ Numeric
11
+ ]
12
+
13
+ InvalidMetaError = Class.new(StandardError)
14
+
4
15
  def initialize(redis, key = 'logs')
5
16
  @redis, @key = redis, key
6
17
  end
7
18
 
8
- def log(message, meta = {}, severity = :info)
19
+ def log(message, meta = {}, severity = 'info')
20
+ # Allow only simple data types in meta
21
+ raise InvalidMetaError, "Meta keys and values must be of one of the following classes: #{META_CLASSES.join(', ')}" if meta_includes_invalid_values?(meta)
22
+
9
23
  value = {
10
24
  time: Time.now.to_i,
11
25
  message: message.to_s,
12
26
  severity: severity.to_s,
13
- meta: meta.map { |k, v| [k.to_s, v.to_s] }.to_h
27
+ meta: meta
14
28
  }
15
29
  @redis.lpush @key, value.to_json
16
30
  end
@@ -37,6 +51,16 @@ module Services
37
51
  data['time'] = Time.at(data['time'])
38
52
  data
39
53
  end
54
+
55
+ def meta_includes_invalid_values?(meta)
56
+ [meta.values, meta.keys].any? do |elements|
57
+ elements.any? do |element|
58
+ META_CLASSES.none? do |klass|
59
+ element.class <= klass
60
+ end
61
+ end
62
+ end
63
+ end
40
64
  end
41
65
  end
42
66
  end
@@ -20,8 +20,8 @@ module Services
20
20
 
21
21
  private
22
22
 
23
- def log(message, severity = :info)
24
- Services.configuration.logger.log message, { service: self.class, id: @id }, severity
23
+ def log(message, severity = 'info')
24
+ Services.configuration.logger.log message, { service: self.class.to_s, 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.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -12,14 +12,18 @@ describe Services::Logger::Redis do
12
12
  severity: :info,
13
13
  meta: {
14
14
  foo: 'bar',
15
- class: Services::Base,
16
- object: redis
15
+ class: Services::Base.to_s,
16
+ object: redis.to_s
17
17
  }
18
18
  }, {
19
19
  time: Date.new(2014, 10, 10),
20
20
  message: "Oh baby, we'll be old",
21
21
  severity: :warning,
22
- meta: {}
22
+ meta: {
23
+ true: true,
24
+ false: false,
25
+ nil: nil
26
+ }
23
27
  }, {
24
28
  time: Date.new(2014, 11, 17),
25
29
  message: 'And think of all the stories',
@@ -42,7 +46,7 @@ describe Services::Logger::Redis do
42
46
  log[k] = log[k].try(:to_s) || ''
43
47
  end
44
48
  log[:meta] = if log.has_key?(:meta)
45
- log[:meta].map { |k, v| [k.to_s, v.to_s] }.to_h
49
+ log[:meta].stringify_keys
46
50
  else
47
51
  {}
48
52
  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.2.0
4
+ version: 1.3.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-15 00:00:00.000000000 Z
11
+ date: 2014-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake