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 +4 -4
- data/README.md +13 -8
- data/lib/ezlog.rb +10 -2
- data/lib/ezlog/logging_layout.rb +1 -2
- data/lib/ezlog/railtie.rb +6 -2
- data/lib/ezlog/sidekiq/error_logger.rb +11 -0
- data/lib/ezlog/sidekiq/job_logger.rb +2 -1
- data/lib/ezlog/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07eba79fc447346727af12f30a5eb9867740056fed910ba8c6e6f005b8b78597
|
4
|
+
data.tar.gz: '08ddf4b8dcd4a22062bfdd0c5134be05698e1426bbc7fcb8704b49a1b846463c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
70
|
-
|
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
|
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
|
82
|
+
def perform(customer_id)
|
83
|
+
logger.warn 'Customer not found'
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
|
-
|
86
|
-
|
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
|
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.
|
data/lib/ezlog.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
require '
|
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
|
data/lib/ezlog/logging_layout.rb
CHANGED
@@ -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
|
59
|
+
backtrace: exception.backtrace&.first(20)
|
61
60
|
}
|
62
61
|
}
|
63
62
|
end
|
data/lib/ezlog/railtie.rb
CHANGED
@@ -21,11 +21,15 @@ module Ezlog
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def initialize_sidekiq_logging
|
24
|
-
|
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
|
|
data/lib/ezlog/version.rb
CHANGED
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.
|
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-
|
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
|