ezlog 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +30 -0
- data/README.md +3 -0
- data/ezlog.gemspec +4 -1
- data/lib/ezlog.rb +2 -0
- data/lib/ezlog/log_context_helper.rb +14 -0
- data/lib/ezlog/railtie.rb +0 -3
- data/lib/ezlog/sidekiq.rb +7 -0
- data/lib/ezlog/sidekiq/error_logger.rb +6 -2
- data/lib/ezlog/sidekiq/job_context.rb +36 -0
- data/lib/ezlog/sidekiq/job_logger.rb +11 -43
- data/lib/ezlog/version.rb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af49b0170f9c53fe3f0b41ced3fd1afe3a420402bbb64b62318bda81144d8c23
|
4
|
+
data.tar.gz: 6c85e8f81ee2848bba6ad407aafbf0ce8b567523801cf133ac3fa795fbb6b14c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7917365ade7f63164081e865efbcbac0b3f71e26f77abd0a2f32e0c15f2ca4465aabb55db07c64ab20c05ed089525e31319e89ef946e91394a51d73f8dc98da
|
7
|
+
data.tar.gz: 631f9ff0ef37d8fb1250e3713f8322e262d2e5366e1e46fa48da522b296cd3cf8445723fdc42f33ef039ad5ccdc2d32bebfaa1dd53749957b663d7f1206e06fd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
### 0.2.2 (2019-05-19)
|
2
|
+
|
3
|
+
[Full Changelog](https://github.com/emartech/ezlog/compare/v0.2.1...v0.2.2)
|
4
|
+
|
5
|
+
* Features & enhancements
|
6
|
+
* [Sidekiq](https://github.com/mperham/sidekiq) error handler now logs the same job context as the JobLogger
|
7
|
+
|
8
|
+
### 0.2.1 (2019-05-17)
|
9
|
+
|
10
|
+
[Full Changelog](https://github.com/emartech/ezlog/compare/v0.2.0...v0.2.1)
|
11
|
+
|
12
|
+
* Features & enhancements
|
13
|
+
* Provide logger creation mechanism so that projects don't explicitly depend on [Logging](https://github.com/TwP/logging)
|
14
|
+
* Error handler for [Sidekiq](https://github.com/mperham/sidekiq) which logs the error in a single message (instead of 3 messages)
|
15
|
+
* Add `run_count` to [Sidekiq](https://github.com/mperham/sidekiq) job log messages indicating how many times a job has run
|
16
|
+
|
17
|
+
* Bug fixes
|
18
|
+
* Fix bug where exceptions without a backtrace would not get logged
|
19
|
+
|
20
|
+
### 0.2.0 (2019-05-12)
|
21
|
+
|
22
|
+
First version of the gem including the following:
|
23
|
+
|
24
|
+
* Features & enhancements
|
25
|
+
* Use [Logging](https://github.com/TwP/logging) library for all logging
|
26
|
+
* Includes logging layout for JSON logging to STDOUT
|
27
|
+
* JobLogger for [Sidekiq](https://github.com/mperham/sidekiq)
|
28
|
+
* Filter [Rack::Timeout](https://github.com/heroku/rack-timeout) logs to WARN level and above
|
29
|
+
* [RSpec](https://rspec.info/) support
|
30
|
+
* Rails integration via Railtie
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Ezlog
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ezlog.svg)](https://badge.fury.io/rb/ezlog)
|
4
|
+
[![Build Status](https://travis-ci.com/emartech/ezlog.svg?branch=master)](https://travis-ci.com/emartech/ezlog)
|
5
|
+
|
3
6
|
Ezlog is intended to be a zero-configuration logging setup for pure Ruby or Rails projects using
|
4
7
|
[Sidekiq](https://github.com/mperham/sidekiq), [Rack::Timeout](https://github.com/heroku/rack-timeout),
|
5
8
|
[Sequel](https://sequel.jeremyevans.net/), etc. It uses Tim Pease's wonderful [Logging](https://github.com/TwP/logging)
|
data/ezlog.gemspec
CHANGED
@@ -7,11 +7,14 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = Ezlog::VERSION
|
8
8
|
spec.authors = ["Zoltan Ormandi"]
|
9
9
|
spec.email = ["zoltan.ormandi@emarsys.com"]
|
10
|
-
|
11
10
|
spec.summary = "A zero-configuration logging solution for projects using Sidekiq, Rails, Sequel, etc."
|
12
11
|
spec.homepage = "https://github.com/emartech/ezlog"
|
13
12
|
spec.license = "MIT"
|
14
13
|
|
14
|
+
spec.metadata = {
|
15
|
+
"changelog_uri" => "https://github.com/emartech/ezlog/blob/master/CHANGELOG.md",
|
16
|
+
}
|
17
|
+
|
15
18
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
16
19
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
20
|
end
|
data/lib/ezlog.rb
CHANGED
@@ -4,7 +4,9 @@ require 'ezlog/version'
|
|
4
4
|
require 'ezlog/railtie' if defined? Rails
|
5
5
|
|
6
6
|
module Ezlog
|
7
|
+
autoload :LogContextHelper, 'ezlog/log_context_helper'
|
7
8
|
autoload :LoggingLayout, 'ezlog/logging_layout'
|
9
|
+
autoload :Sidekiq, 'ezlog/sidekiq'
|
8
10
|
|
9
11
|
def self.logger(name)
|
10
12
|
Logging::Logger[name]
|
data/lib/ezlog/railtie.rb
CHANGED
@@ -21,9 +21,6 @@ module Ezlog
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def initialize_sidekiq_logging
|
24
|
-
require 'ezlog/sidekiq/job_logger'
|
25
|
-
require 'ezlog/sidekiq/error_logger'
|
26
|
-
|
27
24
|
::Sidekiq.logger = ::Logging.logger['Sidekiq']
|
28
25
|
::Sidekiq.logger.level = :info
|
29
26
|
::Sidekiq.configure_server do |config|
|
@@ -3,8 +3,12 @@ require 'sidekiq'
|
|
3
3
|
module Ezlog
|
4
4
|
module Sidekiq
|
5
5
|
class ErrorLogger
|
6
|
-
|
7
|
-
|
6
|
+
include LogContextHelper
|
7
|
+
|
8
|
+
def call(error, context)
|
9
|
+
within_log_context(JobContext.from_job_hash(context[:job])) do
|
10
|
+
::Sidekiq.logger.warn error
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Ezlog
|
2
|
+
module Sidekiq
|
3
|
+
class JobContext
|
4
|
+
class << self
|
5
|
+
def from_job_hash(job_hash)
|
6
|
+
basic_info_from(job_hash).merge named_arguments_from(job_hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def basic_info_from(job)
|
12
|
+
{
|
13
|
+
jid: job['jid'],
|
14
|
+
queue: job['queue'],
|
15
|
+
worker: job['class'],
|
16
|
+
created_at: job['created_at'],
|
17
|
+
enqueued_at: job['enqueued_at'],
|
18
|
+
run_count: (job['retry_count'] || -1) + 2
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def named_arguments_from(job)
|
23
|
+
{}.tap do |arguments|
|
24
|
+
method_parameters_of(job).each_with_index do |(_, param_name), index|
|
25
|
+
arguments[param_name] = job['args'][index]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_parameters_of(job)
|
31
|
+
Kernel.const_get(job['class'].to_sym).instance_method(:perform).parameters
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -3,64 +3,32 @@ require 'sidekiq'
|
|
3
3
|
module Ezlog
|
4
4
|
module Sidekiq
|
5
5
|
class JobLogger
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
include LogContextHelper
|
7
|
+
|
8
|
+
def call(job_hash, queue)
|
9
|
+
within_log_context(JobContext.from_job_hash(job_hash)) do
|
10
|
+
logger.info "#{job_hash['class']} started"
|
9
11
|
benchmark { yield }
|
10
|
-
logger.info message: "#{
|
12
|
+
logger.info message: "#{job_hash['class']} finished"
|
11
13
|
rescue Exception
|
12
|
-
logger.info message: "#{
|
14
|
+
logger.info message: "#{job_hash['class']} failed"
|
13
15
|
raise
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
|
-
def
|
20
|
-
|
21
|
+
def benchmark
|
22
|
+
start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
21
23
|
yield
|
22
24
|
ensure
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def log_context(job)
|
27
|
-
basic_info_for(job).merge arguments_of(job)
|
28
|
-
end
|
29
|
-
|
30
|
-
def basic_info_for(job)
|
31
|
-
{
|
32
|
-
'jid' => job['jid'],
|
33
|
-
'queue' => job['queue'],
|
34
|
-
'worker' => job['class'],
|
35
|
-
'created_at' => job['created_at'],
|
36
|
-
'enqueued_at' => job['enqueued_at'],
|
37
|
-
'run_count' => (job['retry_count'] || -1) + 2
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def arguments_of(job)
|
42
|
-
{}.tap do |arguments|
|
43
|
-
method_parameters_of(job).each_with_index do |(_, param_name), index|
|
44
|
-
arguments[param_name] = job['args'][index]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def method_parameters_of(job)
|
50
|
-
Kernel.const_get(job['class'].to_sym).instance_method(:perform).parameters
|
25
|
+
end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
26
|
+
add_to_log_context duration_sec: (end_time - start_time).round(3)
|
51
27
|
end
|
52
28
|
|
53
29
|
def logger
|
54
30
|
::Sidekiq.logger
|
55
31
|
end
|
56
|
-
|
57
|
-
def benchmark
|
58
|
-
start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
59
|
-
yield
|
60
|
-
ensure
|
61
|
-
end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
62
|
-
Logging.mdc[:duration_sec] = (end_time - start_time).round(3)
|
63
|
-
end
|
64
32
|
end
|
65
33
|
end
|
66
34
|
end
|
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.2
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
106
|
- ".travis.yml"
|
107
|
+
- CHANGELOG.md
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE.txt
|
109
110
|
- README.md
|
@@ -112,18 +113,22 @@ files:
|
|
112
113
|
- bin/setup
|
113
114
|
- ezlog.gemspec
|
114
115
|
- lib/ezlog.rb
|
116
|
+
- lib/ezlog/log_context_helper.rb
|
115
117
|
- lib/ezlog/logging_layout.rb
|
116
118
|
- lib/ezlog/railtie.rb
|
117
119
|
- lib/ezlog/rspec.rb
|
118
120
|
- lib/ezlog/rspec/helpers.rb
|
119
121
|
- lib/ezlog/rspec/matchers.rb
|
122
|
+
- lib/ezlog/sidekiq.rb
|
120
123
|
- lib/ezlog/sidekiq/error_logger.rb
|
124
|
+
- lib/ezlog/sidekiq/job_context.rb
|
121
125
|
- lib/ezlog/sidekiq/job_logger.rb
|
122
126
|
- lib/ezlog/version.rb
|
123
127
|
homepage: https://github.com/emartech/ezlog
|
124
128
|
licenses:
|
125
129
|
- MIT
|
126
|
-
metadata:
|
130
|
+
metadata:
|
131
|
+
changelog_uri: https://github.com/emartech/ezlog/blob/master/CHANGELOG.md
|
127
132
|
post_install_message:
|
128
133
|
rdoc_options: []
|
129
134
|
require_paths:
|