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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07eba79fc447346727af12f30a5eb9867740056fed910ba8c6e6f005b8b78597
4
- data.tar.gz: '08ddf4b8dcd4a22062bfdd0c5134be05698e1426bbc7fcb8704b49a1b846463c'
3
+ metadata.gz: af49b0170f9c53fe3f0b41ced3fd1afe3a420402bbb64b62318bda81144d8c23
4
+ data.tar.gz: 6c85e8f81ee2848bba6ad407aafbf0ce8b567523801cf133ac3fa795fbb6b14c
5
5
  SHA512:
6
- metadata.gz: 6441fe41467856a284f8ffd4cb534793020b83a749d575da453b37a45a15b4632f82014f853aca89e33af314c1ee02c31254d54242d7e66c52033cf485c1593e
7
- data.tar.gz: 91c51f43684577fff83692f58230b9988e530878ddb255a8bbcea43133ceb9a9084fc75b159000d25061407ac5423736f5f3f7903b30f96eaeb7ddc50a442787
6
+ metadata.gz: a7917365ade7f63164081e865efbcbac0b3f71e26f77abd0a2f32e0c15f2ca4465aabb55db07c64ab20c05ed089525e31319e89ef946e91394a51d73f8dc98da
7
+ data.tar.gz: 631f9ff0ef37d8fb1250e3713f8322e262d2e5366e1e46fa48da522b296cd3cf8445723fdc42f33ef039ad5ccdc2d32bebfaa1dd53749957b663d7f1206e06fd
@@ -3,5 +3,5 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.6.1
6
+ - 2.5.0
7
7
  before_install: gem install bundler -v 2.0.1
@@ -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)
@@ -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
@@ -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]
@@ -0,0 +1,14 @@
1
+ module Ezlog
2
+ module LogContextHelper
3
+ def within_log_context(context)
4
+ Logging.mdc.push context
5
+ yield
6
+ ensure
7
+ Logging.mdc.pop
8
+ end
9
+
10
+ def add_to_log_context(context)
11
+ Logging.mdc.update context
12
+ end
13
+ end
14
+ end
@@ -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|
@@ -0,0 +1,7 @@
1
+ module Ezlog
2
+ module Sidekiq
3
+ autoload :ErrorLogger, 'ezlog/sidekiq/error_logger'
4
+ autoload :JobContext, 'ezlog/sidekiq/job_context'
5
+ autoload :JobLogger, 'ezlog/sidekiq/job_logger'
6
+ end
7
+ end
@@ -3,8 +3,12 @@ require 'sidekiq'
3
3
  module Ezlog
4
4
  module Sidekiq
5
5
  class ErrorLogger
6
- def call(error, job_hash)
7
- ::Sidekiq.logger.warn error
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
- def call(item, queue)
7
- within_log_context_of(item) do
8
- logger.info "#{item['class']} started"
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: "#{item['class']} finished"
12
+ logger.info message: "#{job_hash['class']} finished"
11
13
  rescue Exception
12
- logger.info message: "#{item['class']} failed"
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 within_log_context_of(item)
20
- Logging.mdc.push log_context(item)
21
+ def benchmark
22
+ start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
21
23
  yield
22
24
  ensure
23
- Logging.mdc.pop
24
- end
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
@@ -1,3 +1,3 @@
1
1
  module Ezlog
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
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.1
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-17 00:00:00.000000000 Z
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: