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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05dedabda3a19624d090e99d8abad07f7b61b294
4
- data.tar.gz: ee5e8a5bf244910c49fb42cc89918f221e61f860
3
+ metadata.gz: 0f4079eaf3238dd1dd917cf12319e6a1e5b7509d
4
+ data.tar.gz: 3e3c14122d40f6ca293c8b9e83ce2c91d344ef15
5
5
  SHA512:
6
- metadata.gz: ea42d627687aa06ba28333569f664fac8924635bf5cb765e05c356278d3f33a8040cec2d57b51d3c5acca0f4bdc301f8a9365a703c19a43b46f787356ed3e291
7
- data.tar.gz: e12b62184ee79b67a2796127a88d1eb1201fa65f9419463c451f021cee95c1a07880995c2fecbd1a85c1dfce73743c5f2fcc9b9d56986fae2490b0cfe2ddde72
6
+ metadata.gz: 3ac21724b975e195b5946c5814a1e72f37928a7053197702f252e1adcf422237671808a0fdbb6d6de699ce8307b79cb2af070fdd7a335c7cc71f2bc28a947be0
7
+ data.tar.gz: 467b3e0525d4ac0193c24837af29e76cce3d99a82d2cb497a9de0a0ac4e79c07091a95c8cda59a2e29854567ee6b27931c8de5e3ea5256e18ddbb6aa1714c925
@@ -1,7 +1,7 @@
1
1
  module Sidekiq
2
2
  module Logging
3
3
  module Json
4
- VERSION = "0.0.9"
4
+ VERSION = "0.0.10"
5
5
  end
6
6
  end
7
7
  end
@@ -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, severity)).to_json + "\n"
25
+ }.merge(process_message(message)).to_json + "\n"
26
26
  end
27
27
 
28
- def process_message(message, severity)
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' => result[0], # start or done
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.process_message(logentry) }
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[:message] }
8
- let(:status) { subject[:status] }
9
- let(:run_time) { subject[:run_time] }
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 eq(logentry) }
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) { "2014-06-05T12:38:55Z 8630 TID-osanfu5nw SubjectClickthroughTracker JID-e17a9e9ca0521bb74b423166 INFO: start" }
19
+ let(:logentry) { "start" }
17
20
 
18
- it { expect( message ).to eq(logentry) }
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) { "2014-06-05T12:38:42Z 8630 TID-osammcf2k TrainingIndexer::Work JID-177066e96052c2314dcad8c7 INFO: done: 51.579 sec" }
27
+ let(:logentry) { "done: 51.579 sec" }
25
28
 
26
- it { expect( message ).to eq(logentry) }
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.9
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-06-13 00:00:00.000000000 Z
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler