heavylog 0.0.13 → 0.0.14

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
  SHA256:
3
- metadata.gz: 2e48d8003501e21ef31c7a1918584f3262ee15ce422cd000487ae9ab129f6f67
4
- data.tar.gz: 2b8e7b279148ad6f424846da1699c903415e57c718e081f7162e967815752173
3
+ metadata.gz: 28311750ff2fdcc2dcb08226faf88a2b655c1b3e61d44e590c47c9bb389037d2
4
+ data.tar.gz: 1524b0b67c35da8d3d9edec17b0cceb040ffc77752610d919e04f1ee90dca90f
5
5
  SHA512:
6
- metadata.gz: 79b57e0cbc7ddb381da1ff2e8f075984b03b82d572fc03efd37a27067f665b031f2f1cc99a6d92bea557f3806905ed31ff20804260da43f69a789f574b84e537
7
- data.tar.gz: 4afb16d1a35e1980d3c5c753424255610e9212559a1494114e1a6a6fe8b51dd7416a81071dbc5160dc53ed35d499b71c34452ea96db6bfdf0c1cfe4ac671b935
6
+ metadata.gz: ce3b240f7f9b75ac07d1d3ffccb71f024a1dda45183816b996d99aed4df89557337e564847f25041d2d7ce7b0c819c179b859906165215b3bcfab8ab4093acf5
7
+ data.tar.gz: 57af42b8052b55fe3e74f6f2cc6cb739c1cf0aaa906b5082c408fd362239f73b4a6b90f0534a4e15c3358f7e6e543e0f0642a52306ce74e678684c2b50668e29
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Heavylog
4
4
  class SidekiqLogger
5
+ def initialize(logger=Sidekiq.logger)
6
+ @logger = logger
7
+ end
8
+
5
9
  def call(item, _queue)
6
10
  # item = {"class"=>"SuspiciousJob", "args"=>[12754545, [3858890], "invoice"], "retry"=>true, "queue"=>"default",
7
11
  # "jid"=>"5ec968571e358497d70a3cf2", "created_at"=>1540484817.3950138, "enqueued_at"=>1540484817.395076}
@@ -10,24 +14,51 @@ module Heavylog
10
14
 
11
15
  begin
12
16
  start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
13
- logger.info("start")
17
+ @logger.info("start")
18
+
14
19
  yield
15
- logger.info("done: #{elapsed(start)} sec")
20
+
21
+ with_elapsed_time_context(start) do
22
+ @logger.info("done")
23
+ end
24
+
16
25
  Heavylog.finish_sidekiq
17
26
  rescue StandardError
18
- logger.info("fail: #{elapsed(start)} sec")
27
+ with_elapsed_time_context(start) do
28
+ @logger.info("fail")
29
+ end
30
+
19
31
  raise
20
32
  end
21
33
  end
22
34
 
35
+ def with_job_hash_context(job_hash, &block)
36
+ @logger.with_context(job_hash_context(job_hash), &block)
37
+ end
38
+
39
+ def job_hash_context(job_hash)
40
+ # If we're using a wrapper class, like ActiveJob, use the "wrapped"
41
+ # attribute to expose the underlying thing.
42
+ h = {
43
+ class: job_hash["wrapped"] || job_hash["class"],
44
+ jid: job_hash["jid"],
45
+ }
46
+ h[:bid] = job_hash["bid"] if job_hash["bid"]
47
+ h
48
+ end
49
+
50
+ def with_elapsed_time_context(start, &block)
51
+ @logger.with_context(elapsed_time_context(start), &block)
52
+ end
53
+
54
+ def elapsed_time_context(start)
55
+ { elapsed: elapsed(start).to_s }
56
+ end
57
+
23
58
  private
24
59
 
25
60
  def elapsed(start)
26
61
  (::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start).round(3)
27
62
  end
28
-
29
- def logger
30
- Sidekiq.logger
31
- end
32
63
  end
33
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Heavylog
4
- VERSION = "0.0.13"
4
+ VERSION = "0.0.14"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heavylog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristjan Rang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-15 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -171,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.7.6.2
174
+ rubygems_version: 3.0.3
176
175
  signing_key:
177
176
  specification_version: 4
178
177
  summary: Format all Rails logging per request