sidekiq-logging-json 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq/logging/json/version.rb +1 -1
- data/lib/sidekiq/logging/json.rb +8 -4
- data/spec/sidekiq/logging/json_spec.rb +21 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f4079eaf3238dd1dd917cf12319e6a1e5b7509d
|
4
|
+
data.tar.gz: 3e3c14122d40f6ca293c8b9e83ce2c91d344ef15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ac21724b975e195b5946c5814a1e72f37928a7053197702f252e1adcf422237671808a0fdbb6d6de699ce8307b79cb2af070fdd7a335c7cc71f2bc28a947be0
|
7
|
+
data.tar.gz: 467b3e0525d4ac0193c24837af29e76cce3d99a82d2cb497a9de0a0ac4e79c07091a95c8cda59a2e29854567ee6b27931c8de5e3ea5256e18ddbb6aa1714c925
|
data/lib/sidekiq/logging/json.rb
CHANGED
@@ -22,14 +22,18 @@ module Sidekiq
|
|
22
22
|
'@severity' => severity,
|
23
23
|
'@run_time' => nil,
|
24
24
|
'@message' => "#{time.utc.iso8601} #{::Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{context} #{severity}: #{message}",
|
25
|
-
}.merge(process_message(message
|
25
|
+
}.merge(process_message(message)).to_json + "\n"
|
26
26
|
end
|
27
27
|
|
28
|
-
def process_message(message
|
28
|
+
def process_message(message)
|
29
|
+
return { '@status' => 'exception' } if message.is_a?(Exception)
|
30
|
+
|
29
31
|
result = message.split(" ")
|
32
|
+
status = result[0].match(/^(start|done):?$/) || []
|
33
|
+
|
30
34
|
{
|
31
|
-
'@status' =>
|
32
|
-
'@run_time' => result[1] && result[1].to_f # run time in seconds
|
35
|
+
'@status' => status[1], # start or done
|
36
|
+
'@run_time' => status[1] && result[1] && result[1].to_f # run time in seconds
|
33
37
|
}
|
34
38
|
end
|
35
39
|
end
|
@@ -2,30 +2,42 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Sidekiq::Logging::Json" do
|
4
4
|
describe "process_message" do
|
5
|
-
subject { Sidekiq::Logging::Json::Logger.new.
|
5
|
+
subject { JSON.parse(Sidekiq::Logging::Json::Logger.new.call(severity, time, program_name, logentry)) }
|
6
6
|
let(:logentry) { "Some random message" }
|
7
|
-
let(:message) { subject[
|
8
|
-
let(:status) { subject[
|
9
|
-
let(:run_time) { subject[
|
7
|
+
let(:message) { subject["@message"] }
|
8
|
+
let(:status) { subject["@status"] }
|
9
|
+
let(:run_time) { subject["@run_time"] }
|
10
|
+
let(:severity) { "INFO" }
|
11
|
+
let(:time) { Time.now }
|
12
|
+
let(:program_name) { "RSpec" }
|
10
13
|
|
11
|
-
it { expect( message ).to
|
14
|
+
it { expect( message ).to match(/#{logentry}/) }
|
12
15
|
it { expect( status ).to eq(nil) }
|
13
16
|
it { expect( run_time ).to eq(nil) }
|
14
17
|
|
15
18
|
context "start" do
|
16
|
-
let(:logentry) { "
|
19
|
+
let(:logentry) { "start" }
|
17
20
|
|
18
|
-
it { expect( message ).to
|
21
|
+
it { expect( message ).to match(/#{logentry}/) }
|
19
22
|
it { expect( status ).to eq("start") }
|
20
23
|
it { expect( run_time ).to eq(nil) }
|
21
24
|
end
|
22
25
|
|
23
26
|
context "done" do
|
24
|
-
let(:logentry) { "
|
27
|
+
let(:logentry) { "done: 51.579 sec" }
|
25
28
|
|
26
|
-
it { expect( message ).to
|
29
|
+
it { expect( message ).to match(/#{logentry}/) }
|
27
30
|
it { expect( status ).to eq("done") }
|
28
31
|
it { expect( run_time ).to eq(51.579) }
|
29
32
|
end
|
33
|
+
|
34
|
+
context "exception" do
|
35
|
+
let(:exception_message) { "This is the message that should be logged." }
|
36
|
+
let(:logentry) { NoMethodError.new( exception_message ) }
|
37
|
+
|
38
|
+
it { expect(message).to match( exception_message ) }
|
39
|
+
it { expect( status ).to eq("exception") }
|
40
|
+
it { expect( run_time ).to eq(nil) }
|
41
|
+
end
|
30
42
|
end
|
31
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-logging-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wouter de Vos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|