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 +5 -5
- data/.travis.yml +1 -0
- data/lib/logasm/adapters/stdout_json_adapter.rb +17 -1
- data/logasm.gemspec +1 -1
- data/spec/adapters/stdout_json_adapter_spec.rb +22 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14fecade8cd7eaad205f870b2804b42957a97631
|
4
|
+
data.tar.gz: 6467f487b9fe16dcd1160b25353fc095e0b06c52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 829d9ee61dc428c7a015382f83e21b9573132a767041452face65e6894883fcddee0061057f74f88c66bf84f12243154269271913af77c8572b66b9904f4b1e2
|
7
|
+
data.tar.gz: dce7495e8bf93781746bfcb27d845b9592fd0b3479221502305c6d9b03ae2041b0b7c21e1c47a8b3bf1f6975778197b0bf67c8bd80bc54f3bfa56d2868907e08
|
@@ -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
|
-
|
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
|
data/logasm.gemspec
CHANGED
@@ -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
|
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.
|
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-
|
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.
|
155
|
+
rubygems_version: 2.6.14.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: What description said
|