ezlog 0.2.0 → 0.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
2
  SHA256:
3
- metadata.gz: 94596a090c0744c6edb767e0bec261a515c5954a853f061984c5b094d9cf7cf2
4
- data.tar.gz: 303cb838d233797f903d74f6d20a38bcae91b43c23b20c544b64930529df4253
3
+ metadata.gz: 07eba79fc447346727af12f30a5eb9867740056fed910ba8c6e6f005b8b78597
4
+ data.tar.gz: '08ddf4b8dcd4a22062bfdd0c5134be05698e1426bbc7fcb8704b49a1b846463c'
5
5
  SHA512:
6
- metadata.gz: 7317b40e4ab676771a660e1bdd24003ba488e5cb7cfcca4b6ff2c9fd8c3360e98fc2cb3398af344cbabb8304bdf00f42c8fe3a852cb13155ec2f6eaf9f1277d6
7
- data.tar.gz: 67218232ac200cc27322b83198f9d4bded0d660ada98fffc9f43205a26388a7cd9f47abc9d50d6757b6e9272675283f6213f6d19d1592b0059237cc21924bbfa
6
+ metadata.gz: 6441fe41467856a284f8ffd4cb534793020b83a749d575da453b37a45a15b4632f82014f853aca89e33af314c1ee02c31254d54242d7e66c52033cf485c1593e
7
+ data.tar.gz: 91c51f43684577fff83692f58230b9988e530878ddb255a8bbcea43133ceb9a9084fc75b159000d25061407ac5423736f5f3f7903b30f96eaeb7ddc50a442787
data/README.md CHANGED
@@ -66,24 +66,29 @@ it will automatically be appended to all log messages emitted by the application
66
66
 
67
67
  #### Configures Sidekiq logging
68
68
 
69
- Ezlog comes with its own job logger for [Sidekiq](https://github.com/mperham/sidekiq) which does several things that
70
- come in very handy when working with background jobs.
69
+ Ezlog configures the `Sidekiq.logger` to be an instance of a [Logging](https://github.com/TwP/logging) logger by the name
70
+ of `Sidekiq`, behaving as described above. It also comes with its own job logger for [Sidekiq](https://github.com/mperham/sidekiq)
71
+ which does several things that come in very handy when working with background jobs.
71
72
 
72
73
  * It emits two log messages per job run; one when the job is started and another one when the job is finished (successfully or unsuccessfuly).
73
74
  * It measures the time it took to execute the job and appends the benchmark information to the final log message.
74
75
  * It adds all basic information about the job (worker, queue, JID, created_at, enqueued_at) to the log context so
75
76
  all log messages emitted during the execution of the job will contain this information.
76
- * It also adds all of the job's parameters to the log context, which means that all log messages emitted during the execution
77
- of the job will contain this information as well.
77
+ * It also adds all of the job's parameters (by name) to the log context, which means that all log messages emitted
78
+ during the execution of the job will contain this information as well.
78
79
 
79
80
  ```ruby
80
81
  class TestWorker
81
- def perform(customer_id, name)
82
+ def perform(customer_id)
83
+ logger.warn 'Customer not found'
82
84
  end
83
85
  end
84
86
 
85
- #=> {"logger":"Sidekiq","timestamp":"2019-05-12T10:38:10+02:00","level":"INFO","hostname":"MacbookPro.local","pid":75538,"jid":"job id","queue":"job queue","worker":"TestWorker","created_at":"2019-05-12 10:38:10 +0200","enqueued_at":"2019-05-12 10:38:10 +0200","customer_id":1,"name":"name param","message":"TestWorker started"}
86
- #=> {"logger":"Sidekiq","timestamp":"2019-05-12T10:38:12+02:00","level":"INFO","hostname":"MacbookPro.local","pid":75538,"jid":"job id","queue":"job queue","worker":"TestWorker","created_at":"2019-05-12 10:38:10 +0200","enqueued_at":"2019-05-12 10:38:10 +0200","customer_id":1,"name":"name param","duration_sec":2.667,"message":"TestWorker finished"}
87
+ TestWorker.perform_async 42
88
+
89
+ #=> {"logger":"Sidekiq","timestamp":"2019-05-12T10:38:10+02:00","level":"INFO","hostname":"MacbookPro.local","pid":75538,"jid":"abcdef1234567890","queue":"default","worker":"TestWorker","created_at":"2019-05-12 10:38:10 +0200","enqueued_at":"2019-05-12 10:38:10 +0200","customer_id":42,"message":"TestWorker started"}
90
+ #=> {"logger":"Sidekiq","timestamp":"2019-05-12T10:38:10+02:00","level":"WARN","hostname":"MacbookPro.local","pid":75538,"jid":"abcdef1234567890","queue":"default","worker":"TestWorker","created_at":"2019-05-12 10:38:10 +0200","enqueued_at":"2019-05-12 10:38:10 +0200","customer_id":42,"message":"Customer not found"}
91
+ #=> {"logger":"Sidekiq","timestamp":"2019-05-12T10:38:12+02:00","level":"INFO","hostname":"MacbookPro.local","pid":75538,"jid":"abcdef1234567890","queue":"default","worker":"TestWorker","created_at":"2019-05-12 10:38:10 +0200","enqueued_at":"2019-05-12 10:38:10 +0200","customer_id":42,"duration_sec":2.667,"message":"TestWorker finished"}
87
92
  ```
88
93
 
89
94
  #### Configures Rack::Timeout logging
@@ -98,4 +103,4 @@ Ezlog is highly opinionated software and does in no way aim or claim to be usefu
98
103
 
99
104
  ## License
100
105
 
101
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
106
+ The gem is available as open source under the terms of the MIT License - see the [LICENSE](/LICENSE.txt) file for the full text.
@@ -1,4 +1,12 @@
1
- require 'ezlog/version'
2
- require 'ezlog/logging_layout'
1
+ require 'logging'
3
2
 
3
+ require 'ezlog/version'
4
4
  require 'ezlog/railtie' if defined? Rails
5
+
6
+ module Ezlog
7
+ autoload :LoggingLayout, 'ezlog/logging_layout'
8
+
9
+ def self.logger(name)
10
+ Logging::Logger[name]
11
+ end
12
+ end
@@ -1,6 +1,5 @@
1
1
  require 'time'
2
2
  require 'multi_json'
3
- require 'logging'
4
3
 
5
4
  module Ezlog
6
5
  class LoggingLayout < ::Logging::Layout
@@ -57,7 +56,7 @@ module Ezlog
57
56
  error: {
58
57
  class: exception.class.name,
59
58
  message: exception.message,
60
- backtrace: exception.backtrace.first(20)
59
+ backtrace: exception.backtrace&.first(20)
61
60
  }
62
61
  }
63
62
  end
@@ -21,11 +21,15 @@ module Ezlog
21
21
  private
22
22
 
23
23
  def initialize_sidekiq_logging
24
- ::Sidekiq.logger = Logging.logger['Sidekiq']
24
+ require 'ezlog/sidekiq/job_logger'
25
+ require 'ezlog/sidekiq/error_logger'
26
+
27
+ ::Sidekiq.logger = ::Logging.logger['Sidekiq']
25
28
  ::Sidekiq.logger.level = :info
26
29
  ::Sidekiq.configure_server do |config|
27
- require 'ezlog/sidekiq/job_logger'
28
30
  config.options[:job_logger] = Ezlog::Sidekiq::JobLogger
31
+ config.error_handlers << Ezlog::Sidekiq::ErrorLogger.new
32
+ config.error_handlers.delete_if { |handler| handler.is_a? ::Sidekiq::ExceptionHandler::Logger }
29
33
  end
30
34
  end
31
35
 
@@ -0,0 +1,11 @@
1
+ require 'sidekiq'
2
+
3
+ module Ezlog
4
+ module Sidekiq
5
+ class ErrorLogger
6
+ def call(error, job_hash)
7
+ ::Sidekiq.logger.warn error
8
+ end
9
+ end
10
+ end
11
+ end
@@ -33,7 +33,8 @@ module Ezlog
33
33
  'queue' => job['queue'],
34
34
  'worker' => job['class'],
35
35
  'created_at' => job['created_at'],
36
- 'enqueued_at' => job['enqueued_at']
36
+ 'enqueued_at' => job['enqueued_at'],
37
+ 'run_count' => (job['retry_count'] || -1) + 2
37
38
  }
38
39
  end
39
40
 
@@ -1,3 +1,3 @@
1
1
  module Ezlog
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zoltan Ormandi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-12 00:00:00.000000000 Z
11
+ date: 2019-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -117,6 +117,7 @@ files:
117
117
  - lib/ezlog/rspec.rb
118
118
  - lib/ezlog/rspec/helpers.rb
119
119
  - lib/ezlog/rspec/matchers.rb
120
+ - lib/ezlog/sidekiq/error_logger.rb
120
121
  - lib/ezlog/sidekiq/job_logger.rb
121
122
  - lib/ezlog/version.rb
122
123
  homepage: https://github.com/emartech/ezlog