logasm 0.7.0 → 0.8.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: 56e3d511b8873dffb529444790ec2c111f2e06ce
4
- data.tar.gz: 26ae968b0af65670a1fe9db8801b69748f6d6c96
3
+ metadata.gz: 8a3b4cdf873d8b5fb737dda3641fbe20c0d34b8a
4
+ data.tar.gz: a08c2488400e76df30a3a7eb1211d13d538f41ec
5
5
  SHA512:
6
- metadata.gz: f71ce0380318847e9fe3eafd4cd4f9ab26b4175e2cd796dd575d9cf2f4192ca298d0b801b5e9464ccdc649c7dc0b0071b4f29fce2514bd099f8342806123de89
7
- data.tar.gz: 38cf576d4f1e8f2961cbf8416373de2a06f6960bb83e13dc692940a56cd1554ca5537eac9be9650aba935030ea0dbd4b83d4e396f826dfac1178d6205b9303ef
6
+ metadata.gz: 5630b79f07f88556af1b1d6c665e80b498a2d6c13cef60932ef67920b9ccae4bc5f1c00c72dd9d0f03c23b4646f822c0a85b3f8dd9c233f74c029c0f6fcdec0f
7
+ data.tar.gz: f93e2611e11da4bcc13e7b28e9d4b5fccb259c39701ee8394cd53c40b338709ba3e9f8fd7577772b88bcf700475086f8dae45ebbdd21f55381570e69cf90155a
data/lib/logasm/utils.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'socket'
2
+ require 'time'
2
3
 
3
4
  class Logasm
4
5
  module Utils
@@ -14,7 +15,7 @@ class Logasm
14
15
  # @return [Hash]
15
16
  def self.build_event(metadata, level, service_name)
16
17
  overwritable_params
17
- .merge(metadata)
18
+ .merge(serialize_time_objects(metadata))
18
19
  .merge(
19
20
  application: application_name(service_name),
20
21
  level: level.to_s.downcase
@@ -39,6 +40,21 @@ class Logasm
39
40
  host: HOST
40
41
  }
41
42
  end
43
+
44
+ def self.serialize_time_objects(object)
45
+ if object.is_a?(Hash)
46
+ object.reduce({}) do |hash, (key, value)|
47
+ hash.merge(key => serialize_time_objects(value))
48
+ end
49
+ elsif object.is_a?(Array)
50
+ object.map(&method(:serialize_time_objects))
51
+ elsif object.is_a?(Time) || object.is_a?(Date)
52
+ object.iso8601
53
+ else
54
+ object
55
+ end
56
+ end
57
+
42
58
  private_class_method :overwritable_params
43
59
  end
44
60
  end
data/logasm.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "logasm"
7
- gem.version = '0.7.0'
7
+ gem.version = '0.8.0'
8
8
  gem.authors = ["Salemove"]
9
9
  gem.email = ["support@salemove.com"]
10
10
  gem.description = %q{It's logasmic}
@@ -19,11 +19,11 @@ describe Logasm::Adapters::RabbitmqAdapter do
19
19
  context 'when logging a message' do
20
20
  let(:log_level) { 0 }
21
21
 
22
- it 'delegates to freddy' do
22
+ it 'delegates to bunny' do
23
23
  adapter.log :info, message: 'test'
24
24
 
25
25
  expect(exchange).to have_received(:publish).with(
26
- match(/{"@timestamp":"\d{4}-\d{2}-\d{2}T.*","host":"\w+","message":"test","application":"test_service","level":"info"}/),
26
+ match(/{"@timestamp":"\d{4}-\d{2}-\d{2}T.*","host":".+","message":"test","application":"test_service","level":"info"}/),
27
27
  { content_type: 'application/json', routing_key: 'logstash-queue' }
28
28
  )
29
29
  end
@@ -32,7 +32,7 @@ describe Logasm::Adapters::RabbitmqAdapter do
32
32
  context 'when log level is lower than threshold' do
33
33
  let(:log_level) { 3 }
34
34
 
35
- it 'does not delegate to freddy' do
35
+ it 'does not delegate to bunny' do
36
36
  adapter.log :info, message: 'test', a: 'b'
37
37
 
38
38
  expect(exchange).to_not have_received(:publish)
@@ -83,7 +83,7 @@ describe Logasm::Preprocessors::Whitelist do
83
83
 
84
84
  it 'does not include nested elements' do
85
85
  source = {foo: {bar: {baz: 'asd'}}}
86
- target = {foo: {bar: {baz: '***'}}}
86
+ target = {foo: {bar: {baz: '*****'}}}
87
87
  expect(process(['/foo/~'], source)).to eq(target)
88
88
  end
89
89
  end
data/spec/utils_spec.rb CHANGED
@@ -55,5 +55,13 @@ describe Logasm::Utils do
55
55
  expect(subject[:host]).to eq('xyz')
56
56
  end
57
57
  end
58
+
59
+ context 'when time object in metadata' do
60
+ let(:metadata) { {time: Time.utc(2016, 1, 5, 10, 38)} }
61
+
62
+ it 'serializes as iso8601 format' do
63
+ expect(subject[:time]).to eq("2016-01-05T10:38:00Z")
64
+ end
65
+ end
58
66
  end
59
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflecto