heavylog 0.0.9 → 0.0.10

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: 4aa084da3eb852633de1b48ab303da16e6f5177cf56995b135f483b92484159e
4
- data.tar.gz: 86fc4f5d4892b4c18719c74a7f7d626ea536360811a5ce2a15bcd761eae91a33
3
+ metadata.gz: a992292707767781335e5fcce642f511ab6fea56e4a35705a2f2e6048e244793
4
+ data.tar.gz: bf9022984632db4083c7d795aebb741a10e62756086914431a2713585c3c629c
5
5
  SHA512:
6
- metadata.gz: b904c1a842315c5a2aefea6e553c07b26b9055d3e5a72cc7a7cd0b0b4c129e6423161ff554284cdaa4a03d25f93247d7dc83587c719bdfcb4c62e51a4a10330b
7
- data.tar.gz: bf51e06cb88c89fd027c86152441e137742729210130d127320fd7c5a56a92785876645fd99777816d242f12355fdf530b2f0d5ae537204381b304ca93465c0c
6
+ metadata.gz: 8ac6113b7e8713b2e41126ee8a0f0222cea62122eec546dfc10842fef836b5a7dd5ea801b5ebb502617869baf81b06ec42ae14341d7a863429995a96bdf55099
7
+ data.tar.gz: b1639aafc80823c3b4eadac964e6583fd25947bc4606e2047652422e1eca7713797fa820684ae8da8bdf5d2ec66d0d6e615c49b7e908f3f575c335220c2475b0
data/.rubocop.yml ADDED
@@ -0,0 +1,150 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
6
+
7
+ # # Commonly used screens these days easily fit more than 80 characters.
8
+ Metrics/LineLength:
9
+ Max: 120
10
+
11
+ # Too short methods lead to extraction of single-use methods, which can make
12
+ # the code easier to read (by naming things), but can also clutter the class
13
+ Metrics/MethodLength:
14
+ Max: 125
15
+
16
+ # The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
17
+ Metrics/ClassLength:
18
+ Max: 1500
19
+
20
+ Metrics/AbcSize:
21
+ Max: 160
22
+
23
+ Metrics/CyclomaticComplexity:
24
+ Max: 45
25
+
26
+ Metrics/PerceivedComplexity:
27
+ Max: 45
28
+
29
+ Metrics/ParameterLists:
30
+ Max: 6
31
+
32
+ Metrics/ModuleLength:
33
+ Max: 125
34
+
35
+ Metrics/BlockLength:
36
+ Max: 45
37
+ Exclude:
38
+ - 'spec/**/*'
39
+
40
+ # Mixing the styles looks just silly.
41
+ Style/HashSyntax:
42
+ EnforcedStyle: ruby19_no_mixed_keys
43
+ Exclude:
44
+ - 'config/routes.rb'
45
+
46
+ # Single quotes being faster is hardly measurable and only affects parse time.
47
+ # Enforcing double quotes reduces the times where you need to change them
48
+ # when introducing an interpolation. Use single quotes only if their semantics
49
+ # are needed.
50
+ Style/StringLiterals:
51
+ EnforcedStyle: double_quotes
52
+
53
+ Style/StringLiteralsInInterpolation:
54
+ EnforcedStyle: double_quotes
55
+
56
+ # We do not need to support Ruby 1.9, so this is good to use.
57
+ Style/SymbolArray:
58
+ Enabled: true
59
+
60
+ # String#% is by far the least verbose and only object oriented variant.
61
+ Style/FormatString:
62
+ EnforcedStyle: percent
63
+
64
+ # Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
65
+ # The argument that fail should be used to abort the program is wrong too,
66
+ # there's Kernel#abort for that.
67
+ Style/SignalException:
68
+ EnforcedStyle: only_raise
69
+
70
+ # { ... } for multi-line blocks is okay, follow Weirichs rule instead:
71
+ # https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
72
+ Style/BlockDelimiters:
73
+ Enabled: false
74
+
75
+ # do / end blocks should be used for side effects,
76
+ # methods that run a block for side effects and have
77
+ # a useful return value are rare, assign the return
78
+ # value to a local variable for those cases.
79
+ Style/MethodCalledOnDoEndBlock:
80
+ Enabled: true
81
+
82
+ Style/Documentation:
83
+ Enabled: false
84
+
85
+ Style/MethodDefParentheses:
86
+ Enabled: true
87
+
88
+ Style/TrailingCommaInHashLiteral:
89
+ EnforcedStyleForMultiline: comma
90
+
91
+ Style/TrailingCommaInArrayLiteral:
92
+ EnforcedStyleForMultiline: comma
93
+
94
+ Style/NumericLiterals:
95
+ Enabled: false
96
+
97
+ Style/NumericPredicate:
98
+ EnforcedStyle: comparison
99
+
100
+ Style/ClassAndModuleChildren:
101
+ Enabled: false
102
+
103
+ Style/DoubleNegation:
104
+ Enabled: false
105
+
106
+ # Most readable form.
107
+ Layout/AlignHash:
108
+ EnforcedHashRocketStyle: table
109
+ EnforcedColonStyle: table
110
+
111
+ Layout/BlockEndNewline:
112
+ Enabled: false
113
+
114
+ # No space makes the method definition shorter and differentiates
115
+ # from a regular assignment.
116
+ Layout/SpaceAroundEqualsInParameterDefault:
117
+ EnforcedStyle: no_space
118
+
119
+ Layout/IndentationConsistency:
120
+ EnforcedStyle: normal
121
+
122
+ Layout/MultilineMethodCallIndentation:
123
+ EnforcedStyle: indented_relative_to_receiver
124
+
125
+ # Suppressing exceptions can be perfectly fine, and be it to avoid to
126
+ # explicitly type nil into the rescue since that's what you want to return,
127
+ # or suppressing LoadError for optional dependencies
128
+ Lint/HandleExceptions:
129
+ Enabled: false
130
+
131
+ # This is just silly. Calling the argument `other` in all cases makes no sense.
132
+ Naming/BinaryOperatorParameterName:
133
+ Enabled: false
134
+
135
+ Naming/UncommunicativeMethodParamName:
136
+ AllowedNames:
137
+ - io
138
+ - id
139
+ - to
140
+ - by
141
+ - on
142
+ - in
143
+ - at
144
+ - ip
145
+ - db
146
+ - x
147
+ - y
148
+
149
+ Bundler/OrderedGems:
150
+ Enabled: false
data/.travis.yml CHANGED
@@ -2,4 +2,5 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.5.0
5
- before_install: gem install bundler -v 1.16.0
5
+ before_install: gem install bundler -v 2.0.1
6
+ script: bundle exec rspec
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in heavylog.gemspec
6
8
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heavylog (0.0.5)
4
+ heavylog (0.0.9)
5
5
  actionpack (>= 5)
6
6
  activesupport (>= 5)
7
7
  railties (>= 5)
@@ -10,53 +10,59 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actionpack (5.1.6)
14
- actionview (= 5.1.6)
15
- activesupport (= 5.1.6)
13
+ actionpack (5.2.2)
14
+ actionview (= 5.2.2)
15
+ activesupport (= 5.2.2)
16
16
  rack (~> 2.0)
17
17
  rack-test (>= 0.6.3)
18
18
  rails-dom-testing (~> 2.0)
19
19
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
20
- actionview (5.1.6)
21
- activesupport (= 5.1.6)
20
+ actionview (5.2.2)
21
+ activesupport (= 5.2.2)
22
22
  builder (~> 3.1)
23
23
  erubi (~> 1.4)
24
24
  rails-dom-testing (~> 2.0)
25
25
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
26
- activesupport (5.1.6)
26
+ activesupport (5.2.2)
27
27
  concurrent-ruby (~> 1.0, >= 1.0.2)
28
28
  i18n (>= 0.7, < 2)
29
29
  minitest (~> 5.1)
30
30
  tzinfo (~> 1.1)
31
+ ast (2.4.0)
31
32
  builder (3.2.3)
32
- concurrent-ruby (1.0.5)
33
- crass (1.0.3)
33
+ concurrent-ruby (1.1.4)
34
+ crass (1.0.4)
34
35
  diff-lcs (1.3)
35
36
  erubi (1.7.1)
36
- i18n (1.0.0)
37
+ i18n (1.2.0)
37
38
  concurrent-ruby (~> 1.0)
38
- loofah (2.2.2)
39
+ jaro_winkler (1.5.2)
40
+ loofah (2.2.3)
39
41
  crass (~> 1.0.2)
40
42
  nokogiri (>= 1.5.9)
41
- method_source (0.9.0)
43
+ method_source (0.9.2)
42
44
  mini_portile2 (2.3.0)
43
45
  minitest (5.11.3)
44
- nokogiri (1.8.2)
46
+ nokogiri (1.8.5)
45
47
  mini_portile2 (~> 2.3.0)
46
- rack (2.0.4)
47
- rack-test (1.0.0)
48
+ parallel (1.17.0)
49
+ parser (2.6.3.0)
50
+ ast (~> 2.4.0)
51
+ rack (2.0.6)
52
+ rack-test (1.1.0)
48
53
  rack (>= 1.0, < 3)
49
54
  rails-dom-testing (2.0.3)
50
55
  activesupport (>= 4.2.0)
51
56
  nokogiri (>= 1.6)
52
57
  rails-html-sanitizer (1.0.4)
53
58
  loofah (~> 2.2, >= 2.2.2)
54
- railties (5.1.6)
55
- actionpack (= 5.1.6)
56
- activesupport (= 5.1.6)
59
+ railties (5.2.2)
60
+ actionpack (= 5.2.2)
61
+ activesupport (= 5.2.2)
57
62
  method_source
58
63
  rake (>= 0.8.7)
59
- thor (>= 0.18.1, < 2.0)
64
+ thor (>= 0.19.0, < 2.0)
65
+ rainbow (3.0.0)
60
66
  rake (10.5.0)
61
67
  request_store (1.4.1)
62
68
  rack (>= 1.4)
@@ -73,19 +79,29 @@ GEM
73
79
  diff-lcs (>= 1.2.0, < 2.0)
74
80
  rspec-support (~> 3.7.0)
75
81
  rspec-support (3.7.1)
76
- thor (0.20.0)
82
+ rubocop (0.71.0)
83
+ jaro_winkler (~> 1.5.1)
84
+ parallel (~> 1.10)
85
+ parser (>= 2.6)
86
+ rainbow (>= 2.2.2, < 4.0)
87
+ ruby-progressbar (~> 1.7)
88
+ unicode-display_width (>= 1.4.0, < 1.7)
89
+ ruby-progressbar (1.10.1)
90
+ thor (0.20.3)
77
91
  thread_safe (0.3.6)
78
92
  tzinfo (1.2.5)
79
93
  thread_safe (~> 0.1)
94
+ unicode-display_width (1.6.0)
80
95
 
81
96
  PLATFORMS
82
97
  ruby
83
98
 
84
99
  DEPENDENCIES
85
- bundler (~> 1.16)
100
+ bundler (~> 2.0)
86
101
  heavylog!
87
102
  rake (~> 10.0)
88
103
  rspec (~> 3.0)
104
+ rubocop (~> 0.71)
89
105
 
90
106
  BUNDLED WITH
91
- 1.16.0
107
+ 2.0.1
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Heavylog
1
+ # Heavylog [![Build Status](https://travis-ci.org/krisrang/heavylog.svg?branch=master)](https://travis-ci.org/krisrang/heavylog)
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/heavylog`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "heavylog"
data/heavylog.gemspec CHANGED
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require "heavylog/version"
5
6
 
@@ -21,12 +22,13 @@ Gem::Specification.new do |spec|
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "bundler", "~> 2.0"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
26
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "rubocop", "~> 0.71"
27
29
 
28
- spec.add_runtime_dependency 'activesupport', '>= 5'
29
- spec.add_runtime_dependency 'actionpack', '>= 5'
30
- spec.add_runtime_dependency 'railties', '>= 5'
31
- spec.add_runtime_dependency 'request_store', '~> 1.4'
30
+ spec.add_runtime_dependency "actionpack", ">= 5"
31
+ spec.add_runtime_dependency "activesupport", ">= 5"
32
+ spec.add_runtime_dependency "railties", ">= 5"
33
+ spec.add_runtime_dependency "request_store", "~> 1.4"
32
34
  end
@@ -1,4 +1,6 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
2
4
 
3
5
  module Heavylog
4
6
  module Formatters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Heavylog
2
4
  module Formatters
3
5
  class Raw
@@ -1,14 +1,15 @@
1
- require 'json'
2
- require 'action_pack'
3
- require 'active_support/core_ext/class/attribute'
4
- require 'active_support/log_subscriber'
5
- require 'request_store'
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "action_pack"
5
+ require "active_support/core_ext/class/attribute"
6
+ require "active_support/log_subscriber"
7
+ require "request_store"
6
8
 
7
9
  module Heavylog
8
10
  class LogSubscriber < ActiveSupport::LogSubscriber
9
11
  def process_action(event)
10
- payload = event.payload
11
- data = extract_request(event, payload)
12
+ data = extract_request(event)
12
13
  RequestStore.store[:heavylog_request_data] = data
13
14
  end
14
15
 
@@ -23,7 +24,7 @@ module Heavylog
23
24
 
24
25
  private
25
26
 
26
- def extract_request(event, payload)
27
+ def extract_request(event)
27
28
  payload = event.payload
28
29
  data = initial_data(payload)
29
30
  data.merge!(extract_status(payload))
@@ -35,11 +36,11 @@ module Heavylog
35
36
 
36
37
  def initial_data(payload)
37
38
  {
38
- method: payload[:method],
39
- path: extract_path(payload),
40
- format: extract_format(payload),
39
+ method: payload[:method],
40
+ path: extract_path(payload),
41
+ format: extract_format(payload),
41
42
  controller: payload[:controller],
42
- action: payload[:action]
43
+ action: payload[:action],
43
44
  }
44
45
  end
45
46
 
@@ -49,7 +50,7 @@ module Heavylog
49
50
  end
50
51
 
51
52
  def strip_query_string(path)
52
- index = path.index('?')
53
+ index = path.index("?")
53
54
  index ? path[0, index] : path
54
55
  end
55
56
 
@@ -79,7 +80,7 @@ module Heavylog
79
80
 
80
81
  def extract_runtimes(event, payload)
81
82
  data = { duration: event.duration.to_f.round(2) }
82
- [:view_runtime, :db_runtime].each do |key|
83
+ %i[view_runtime db_runtime].each do |key|
83
84
  data[key] = payload[key].to_f.round(2) if payload.key?(key)
84
85
  end
85
86
  data
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'rack/body_proxy'
2
+
3
+ require "rack/body_proxy"
3
4
 
4
5
  module Heavylog
5
6
  class Middleware
@@ -9,8 +10,8 @@ module Heavylog
9
10
  end
10
11
 
11
12
  def call(env)
12
- ignore = env['PATH_INFO'] =~ @assets_regex
13
- if !ignore
13
+ ignore = env["PATH_INFO"] =~ @assets_regex
14
+ unless ignore
14
15
  request = ActionDispatch::Request.new(env)
15
16
  RequestStore.store[:heavylog_request_id] = request.uuid
16
17
  RequestStore.store[:heavylog_request_start] = Time.now.iso8601
@@ -19,7 +20,7 @@ module Heavylog
19
20
 
20
21
  @app.call(env)
21
22
  ensure
22
- Heavylog.finish if !ignore
23
+ Heavylog.finish unless ignore
23
24
  end
24
25
  end
25
26
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'active_support/ordered_options'
2
+
3
+ require "active_support/ordered_options"
3
4
 
4
5
  module Heavylog
5
6
  class OrderedOptions < ActiveSupport::OrderedOptions
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Heavylog
3
4
  class Railtie < Rails::Railtie
4
5
  config.heavylog = Heavylog::OrderedOptions.new
5
6
  config.heavylog.enabled = false
6
- config.heavylog.path = 'log/heavylog.log'
7
+ config.heavylog.path = "log/heavylog.log"
7
8
  config.heavylog.message_limit = 1024 * 1024 * 50 # 50MB
8
9
  config.heavylog.log_sidekiq = false
9
10
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Heavylog
4
4
  module RequestLogger
5
- def add(severity, message = nil, progname = nil, &block)
5
+ def add(severity, message=nil, progname=nil, &block)
6
6
  super
7
7
  Heavylog.log(severity, message, progname, &block)
8
8
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Heavylog
2
4
  class SidekiqExceptionHandler
3
- def call(ex, ctxHash)
4
- Heavylog.log(:warn, Sidekiq.dump_json(ctxHash)) if !ctxHash.empty?
5
- Heavylog.log(:warn, "#{ex.class.name}: #{ex.message}")
6
- Heavylog.log(:warn, ex.backtrace.join("\n")) unless ex.backtrace.nil?
5
+ def call(exception, context)
6
+ Heavylog.log(:warn, Sidekiq.dump_json(context)) unless context.empty?
7
+ Heavylog.log(:warn, "#{exception.class.name}: #{exception.message}")
8
+ Heavylog.log(:warn, exception.backtrace.join("\n")) unless exception.backtrace.nil?
7
9
  Heavylog.finish_sidekiq
8
10
  end
9
11
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Heavylog
2
4
  class SidekiqLogger
3
- def call(item, queue)
4
- # item = {"class"=>"SuspiciousJob", "args"=>[12754545, [3858890], "invoice"], "retry"=>true, "queue"=>"default", "jid"=>"5ec968571e358497d70a3cf2", "created_at"=>1540484817.3950138, "enqueued_at"=>1540484817.395076}
5
+ def call(item, _queue)
6
+ # item = {"class"=>"SuspiciousJob", "args"=>[12754545, [3858890], "invoice"], "retry"=>true, "queue"=>"default",
7
+ # "jid"=>"5ec968571e358497d70a3cf2", "created_at"=>1540484817.3950138, "enqueued_at"=>1540484817.395076}
5
8
 
6
9
  Heavylog.log_sidekiq(item["jid"], item["class"], item["args"])
7
10
 
@@ -11,7 +14,7 @@ module Heavylog
11
14
  yield
12
15
  logger.info("done: #{elapsed(start)} sec")
13
16
  Heavylog.finish_sidekiq
14
- rescue Exception
17
+ rescue StandardError
15
18
  logger.info("fail: #{elapsed(start)} sec")
16
19
  raise
17
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Heavylog
2
- VERSION = "0.0.9"
4
+ VERSION = "0.0.10"
3
5
  end
data/lib/heavylog.rb CHANGED
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
- require 'heavylog/version'
3
- require 'heavylog/formatters/raw'
4
- require 'heavylog/formatters/json'
5
- require 'heavylog/log_subscriber'
6
- require 'heavylog/middleware'
7
- require 'heavylog/ordered_options'
8
- require 'heavylog/request_logger'
9
- require 'heavylog/sidekiq_logger'
10
- require 'heavylog/sidekiq_exception_handler'
2
+
3
+ require "heavylog/version"
4
+ require "heavylog/formatters/raw"
5
+ require "heavylog/formatters/json"
6
+ require "heavylog/log_subscriber"
7
+ require "heavylog/middleware"
8
+ require "heavylog/ordered_options"
9
+ require "heavylog/request_logger"
10
+ require "heavylog/sidekiq_logger"
11
+ require "heavylog/sidekiq_exception_handler"
11
12
 
12
13
  module Heavylog
13
14
  module_function
14
15
 
15
- TRUNCATION = '[TRUNCATED]'.freeze
16
+ TRUNCATION = "[TRUNCATED]"
16
17
 
17
18
  mattr_accessor :logger, :application, :formatter, :log_level
18
19
 
@@ -26,15 +27,18 @@ module Heavylog
26
27
  end
27
28
 
28
29
  def patch_loggers
29
- Rails.logger.extend(RequestLogger)
30
+ Rails.logger.extend(RequestLogger) if defined?(Rails)
30
31
  end
31
32
 
32
33
  def set_options
33
- f = File.open(config.path, 'a')
34
- f.binmode
35
- f.sync = true
34
+ if config.path
35
+ f = File.open(config.path, "a")
36
+ f.binmode
37
+ f.sync = true
38
+
39
+ Heavylog.logger = ActiveSupport::Logger.new(f)
40
+ end
36
41
 
37
- Heavylog.logger = ActiveSupport::Logger.new(f)
38
42
  Heavylog.formatter = config.formatter || Heavylog::Formatters::Raw.new
39
43
  Heavylog.log_level = config.log_level || :info
40
44
  end
@@ -44,7 +48,7 @@ module Heavylog
44
48
  end
45
49
 
46
50
  def attach_to_sidekiq
47
- return if !config.log_sidekiq
51
+ return unless config.log_sidekiq
48
52
 
49
53
  Sidekiq.configure_server do |config|
50
54
  config.options[:job_logger] = SidekiqLogger
@@ -72,21 +76,24 @@ module Heavylog
72
76
  end
73
77
  end
74
78
 
75
- def log(severity, message = nil, progname = nil, &block)
76
- return if !config.enabled
79
+ def log(_severity, message=nil, progname=nil)
80
+ return unless config.enabled
77
81
  return if !!RequestStore.store[:heavylog_truncated]
78
82
 
79
83
  uuid = RequestStore.store[:heavylog_request_id]
80
- return if !uuid
84
+ return unless uuid
81
85
 
82
86
  if message.nil?
83
- if block_given?
84
- message = yield
85
- else
86
- message = progname
87
- end
87
+ message =
88
+ if block_given?
89
+ yield
90
+ else
91
+ progname
92
+ end
88
93
  end
89
94
 
95
+ message = message.gsub(/\e\[(\d+)m/, "")
96
+
90
97
  RequestStore.store[:heavylog_buffer] ||= StringIO.new
91
98
 
92
99
  if RequestStore.store[:heavylog_buffer].length + message_size(message) > config.message_limit
@@ -99,7 +106,7 @@ module Heavylog
99
106
  end
100
107
 
101
108
  def log_sidekiq(jid, klass, args)
102
- return if !config.enabled
109
+ return unless config.enabled
103
110
 
104
111
  RequestStore.store[:heavylog_request_id] = jid
105
112
  RequestStore.store[:heavylog_request_start] = Time.now.iso8601
@@ -107,24 +114,24 @@ module Heavylog
107
114
 
108
115
  RequestStore.store[:heavylog_request_data] = {
109
116
  controller: "SidekiqLogger",
110
- action: klass,
111
- args: args.to_s,
117
+ action: klass,
118
+ args: args.to_s,
112
119
  }
113
120
 
114
121
  RequestStore.store[:heavylog_buffer] ||= StringIO.new
115
122
  end
116
123
 
117
124
  def finish
118
- return if !config.enabled
125
+ return unless config.enabled
119
126
 
120
127
  buffer = RequestStore.store[:heavylog_buffer]
121
- return if !buffer
128
+ return unless buffer && Heavylog.logger
122
129
 
123
130
  request = {
124
- request_id: RequestStore.store[:heavylog_request_id],
131
+ request_id: RequestStore.store[:heavylog_request_id],
125
132
  request_start: RequestStore.store[:heavylog_request_start],
126
- ip: RequestStore.store[:heavylog_request_ip],
127
- messages: buffer.string.dup
133
+ ip: RequestStore.store[:heavylog_request_ip],
134
+ messages: buffer.string.dup,
128
135
  }.merge(RequestStore.store[:heavylog_request_data] || {})
129
136
 
130
137
  formatted = Heavylog.formatter.call(request)
@@ -137,15 +144,17 @@ module Heavylog
137
144
  end
138
145
 
139
146
  def config
140
- return OrderedOptions.new if !application
147
+ return OrderedOptions.new unless application
148
+
141
149
  application.config.heavylog
142
150
  end
143
151
 
144
152
  def message_size(message)
145
153
  return message.bytesize if message.respond_to?(:bytesize)
146
154
  return message.map(&:to_s).sum(&:bytesize) if message.is_a?(Array)
155
+
147
156
  message.to_s.length
148
157
  end
149
158
  end
150
159
 
151
- require 'heavylog/railtie' if defined?(Rails)
160
+ require "heavylog/railtie" if defined?(Rails)
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.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristjan Rang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-25 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: activesupport
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.71'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.71'
69
+ - !ruby/object:Gem::Dependency
70
+ name: actionpack
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '5'
69
83
  - !ruby/object:Gem::Dependency
70
- name: actionpack
84
+ name: activesupport
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -117,6 +131,7 @@ extra_rdoc_files: []
117
131
  files:
118
132
  - ".gitignore"
119
133
  - ".rspec"
134
+ - ".rubocop.yml"
120
135
  - ".travis.yml"
121
136
  - Gemfile
122
137
  - Gemfile.lock
@@ -157,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
172
  version: '0'
158
173
  requirements: []
159
174
  rubyforge_project:
160
- rubygems_version: 2.7.6
175
+ rubygems_version: 2.7.6.2
161
176
  signing_key:
162
177
  specification_version: 4
163
178
  summary: Format all Rails logging per request