logasm-jruby 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
- SHA256:
3
- metadata.gz: d979fabe79cb012160eae9358e7ebb15122ee58715d36c2d19d3a983413f1962
4
- data.tar.gz: fd5391fc22692e4a82528bc43863a9ce4a93fa854e0826fcfb56371c0b6c178d
2
+ SHA1:
3
+ metadata.gz: 14fecade8cd7eaad205f870b2804b42957a97631
4
+ data.tar.gz: 6467f487b9fe16dcd1160b25353fc095e0b06c52
5
5
  SHA512:
6
- metadata.gz: 575d5e5f7ea14be165321542d33561d8405be7b3b653f22c3a88e6be359a29fcf4916ce0c0fbe6a2324edd02e7c659a3f8d663ffef6f79cdbfedc0c356a63fba
7
- data.tar.gz: a9b53672c3b49f420fe55327fdd1ece358580cb6787ae0bfddddcaa98cb6f076b0ab4d72d814b010f0a0494299214c1513ba5fa0bf8cadd6aec096febfa1873e
6
+ metadata.gz: 829d9ee61dc428c7a015382f83e21b9573132a767041452face65e6894883fcddee0061057f74f88c66bf84f12243154269271913af77c8572b66b9904f4b1e2
7
+ data.tar.gz: dce7495e8bf93781746bfcb27d845b9592fd0b3479221502305c6d9b03ae2041b0b7c21e1c47a8b3bf1f6975778197b0bf67c8bd80bc54f3bfa56d2868907e08
@@ -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-jruby
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
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.6.13
155
+ rubygems_version: 2.6.14.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: What description said