logasm 1.2.0 → 1.2.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: b337bd71343caed24d803eb66ef0894db28cd135
4
- data.tar.gz: 61c6bdcdf09b7309e335c996388933e315b892bc
3
+ metadata.gz: e5b272c844ca3c64532cfb0f37de002ffda50d3e
4
+ data.tar.gz: 667f20880add349a9c54e3be8690d128a5969fb4
5
5
  SHA512:
6
- metadata.gz: 5206acdaa98e5fcfa8a5565d3be91dda8db603f23d722234dbb261104d380899564ac0692d93813eee76950bdcd9f5bc2ee196edde1890fb8998c9a1a0302d2b
7
- data.tar.gz: 7e754346d1e30e11f827fad0db9438741e0a471ccf3315140b6d73acd2d6e9b66a89deb0a7e7bc4f9082d7d2f106bdd96c815fc7890b268a86aa9a62fc64fe85
6
+ metadata.gz: bb228496cfe64b0ce19fc1e1c2a7fe8488a8bc59d40f65ee3d0e16f32b1bd865f9e34daf15cf5d03dd23200e5b5dfed73ab7fc5b6a34a94bda2f63a84d18b085
7
+ data.tar.gz: 30239faea99548dca6dcae5d023e21dd85c40213fdae86fd25de71190d6392f79c3467dbc0a77ce7e9e55612f1489910c6c25eb011d92ebbf6859160a30e2ce7
@@ -3,4 +3,5 @@ rvm:
3
3
  - 2.2
4
4
  - 2.3
5
5
  - 2.4
6
+ - 2.5
6
7
  - jruby
@@ -5,12 +5,13 @@ class Logasm
5
5
  @level = level
6
6
  @service_name = service_name
7
7
  @application_name = Utils.application_name(service_name)
8
+ @mutex = Mutex.new if RUBY_ENGINE == "jruby"
8
9
  end
9
10
 
10
11
  def log(level, metadata = {})
11
12
  if meets_threshold?(level)
12
13
  message = Utils.build_event(metadata, level, @application_name)
13
- STDOUT.puts(Utils.generate_json(message))
14
+ print_line(Utils.generate_json(message))
14
15
  end
15
16
  end
16
17
 
@@ -39,6 +40,21 @@ class Logasm
39
40
  def meets_threshold?(level)
40
41
  LOG_LEVELS.index(level.to_s) >= @level
41
42
  end
43
+
44
+ # puts is atomic in MRI starting from 2.5.0
45
+ if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.5.0"
46
+ def print_line(str)
47
+ $stdout.puts(str)
48
+ end
49
+ elsif RUBY_ENGINE == "jruby"
50
+ def print_line(str)
51
+ @mutex.synchronize { $stdout.write(str + "\n") }
52
+ end
53
+ else
54
+ def print_line(str)
55
+ $stdout.write(str + "\n")
56
+ end
57
+ end
42
58
  end
43
59
  end
44
60
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.name = 'logasm'
10
10
  end
11
11
 
12
- gem.version = '1.2.0'
12
+ gem.version = '1.2.1'
13
13
  gem.authors = ["Salemove"]
14
14
  gem.email = ["support@salemove.com"]
15
15
  gem.description = %q{It's logasmic}
@@ -8,6 +8,19 @@ describe Logasm::Adapters::StdoutJsonAdapter do
8
8
  let(:info_level_code) { 1 }
9
9
  let(:info_level) { Logasm::Adapters::LOG_LEVELS[info_level_code] }
10
10
 
11
+ let(:stdout) { StringIO.new }
12
+
13
+ around do |example|
14
+ old_stdout = $stdout
15
+ $stdout = stdout
16
+
17
+ begin
18
+ example.call
19
+ ensure
20
+ $stdout = old_stdout
21
+ end
22
+ end
23
+
11
24
  describe '#log' do
12
25
  context 'when below threshold' do
13
26
  let(:adapter) { described_class.new(debug_level_code, service_name) }
@@ -23,9 +36,9 @@ describe Logasm::Adapters::StdoutJsonAdapter do
23
36
  .and_return(event)
24
37
  end
25
38
 
26
- it 'sends serialized event to STDOUT' do
27
- expect(STDOUT).to receive(:puts).with(serialized_event)
39
+ it 'sends serialized event to $stdout' do
28
40
  adapter.log(info_level, metadata)
41
+ expect(output).to eq serialized_event + "\n"
29
42
  end
30
43
  end
31
44
 
@@ -35,9 +48,15 @@ describe Logasm::Adapters::StdoutJsonAdapter do
35
48
  let(:service_name) { 'my-service' }
36
49
 
37
50
  it 'does not log the event' do
38
- expect(STDOUT).to_not receive(:puts)
39
51
  adapter.log(debug_level, metadata)
52
+ expect(output).to be_empty
40
53
  end
41
54
  end
42
55
  end
56
+
57
+ private
58
+
59
+ def output
60
+ stdout.string
61
+ end
43
62
  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: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-09 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lru_redux