heavylog 0.0.20 → 0.0.23

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: 0d938340a9fc57747dc46c35aadb0a9b92c08da6466f3d333479e7b0c4de63d4
4
- data.tar.gz: f31b3c1ec5566d8de8c6199b21dfae45b00b22c5710dd1eecb07e676a55b3a2e
3
+ metadata.gz: 1e9bcdf11b686f9e5035d2d75e6ed92e412b7e7e05f085d06ef92166410d8329
4
+ data.tar.gz: f21daaea34d6422d4043f5078a34a08b904da8a25d5ba09d6bc4cd4d62254d0d
5
5
  SHA512:
6
- metadata.gz: 44fa9815cb453c895d70db9912558f9b16cf775caaa83d1d723fde9252ced6a6c4a07072d0b0db8b352236a11701330af9ec0adf7de8bc94c41a89e96c6e5dfa
7
- data.tar.gz: 993f3cb991245997f89827c4bd6581060b35eadd64d4c229419c5dbe6cbc1f8467319e66514c91af9d445bd683231144d8393419729b4ab513f7a7996ffe1854
6
+ metadata.gz: f89838a3639dcb7c3a0eee03b76f762b73a11494dac5af0e87b58e3f767a1a3b1c6e1d63b6084c5c5a6de29c971f17a7de09c905f3685d1150a2d0d18903e5da
7
+ data.tar.gz: 5b191bca2b91d8debfe0e55a7fb1e4dda0af1ab8df1d68ce83a92c9c99a59cafa8de0c6a6a210fd09de7826456a5cd8602dc38cddf12f70b9f07a635e4155c5e
@@ -12,7 +12,7 @@ jobs:
12
12
  - name: Set up Ruby
13
13
  uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 3.0.1
15
+ ruby-version: 3.1.1
16
16
 
17
17
  - uses: actions/cache@v1
18
18
  with:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heavylog (0.0.20)
4
+ heavylog (0.0.22)
5
5
  actionpack (>= 5)
6
6
  activesupport (>= 5)
7
7
  railties (>= 5)
@@ -10,93 +10,93 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actionpack (6.1.3.2)
14
- actionview (= 6.1.3.2)
15
- activesupport (= 6.1.3.2)
16
- rack (~> 2.0, >= 2.0.9)
13
+ actionpack (7.0.3.1)
14
+ actionview (= 7.0.3.1)
15
+ activesupport (= 7.0.3.1)
16
+ rack (~> 2.0, >= 2.2.0)
17
17
  rack-test (>= 0.6.3)
18
18
  rails-dom-testing (~> 2.0)
19
19
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
20
- actionview (6.1.3.2)
21
- activesupport (= 6.1.3.2)
20
+ actionview (7.0.3.1)
21
+ activesupport (= 7.0.3.1)
22
22
  builder (~> 3.1)
23
23
  erubi (~> 1.4)
24
24
  rails-dom-testing (~> 2.0)
25
25
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
26
- activesupport (6.1.3.2)
26
+ activesupport (7.0.3.1)
27
27
  concurrent-ruby (~> 1.0, >= 1.0.2)
28
28
  i18n (>= 1.6, < 2)
29
29
  minitest (>= 5.1)
30
30
  tzinfo (~> 2.0)
31
- zeitwerk (~> 2.3)
32
31
  ast (2.4.2)
33
- backport (1.1.2)
34
- benchmark (0.1.1)
32
+ backport (1.2.0)
33
+ benchmark (0.2.0)
35
34
  builder (3.2.4)
36
- concurrent-ruby (1.1.8)
35
+ concurrent-ruby (1.1.10)
37
36
  connection_pool (2.2.5)
38
37
  crass (1.0.6)
39
- diff-lcs (1.4.4)
40
- docile (1.3.5)
38
+ diff-lcs (1.5.0)
39
+ docile (1.4.0)
41
40
  e2mmap (0.1.0)
42
41
  erubi (1.10.0)
43
- i18n (1.8.10)
42
+ i18n (1.11.0)
44
43
  concurrent-ruby (~> 1.0)
45
44
  jaro_winkler (1.5.4)
46
- json (2.5.1)
47
- kramdown (2.3.1)
45
+ json (2.6.2)
46
+ kramdown (2.4.0)
48
47
  rexml
49
48
  kramdown-parser-gfm (1.1.0)
50
49
  kramdown (~> 2.0)
51
- loofah (2.9.1)
50
+ loofah (2.18.0)
52
51
  crass (~> 1.0.2)
53
52
  nokogiri (>= 1.5.9)
54
53
  method_source (1.0.0)
55
- mini_portile2 (2.5.1)
56
- minitest (5.14.4)
57
- nokogiri (1.11.3)
58
- mini_portile2 (~> 2.5.0)
54
+ mini_portile2 (2.8.0)
55
+ minitest (5.16.2)
56
+ nokogiri (1.13.7)
57
+ mini_portile2 (~> 2.8.0)
59
58
  racc (~> 1.4)
60
- parallel (1.20.1)
61
- parser (3.0.1.0)
59
+ parallel (1.22.1)
60
+ parser (3.1.2.0)
62
61
  ast (~> 2.4.1)
63
- racc (1.5.2)
64
- rack (2.2.3)
65
- rack-test (1.1.0)
66
- rack (>= 1.0, < 3)
62
+ racc (1.6.0)
63
+ rack (2.2.4)
64
+ rack-test (2.0.2)
65
+ rack (>= 1.3)
67
66
  rails-dom-testing (2.0.3)
68
67
  activesupport (>= 4.2.0)
69
68
  nokogiri (>= 1.6)
70
- rails-html-sanitizer (1.3.0)
69
+ rails-html-sanitizer (1.4.3)
71
70
  loofah (~> 2.3)
72
- railties (6.1.3.2)
73
- actionpack (= 6.1.3.2)
74
- activesupport (= 6.1.3.2)
71
+ railties (7.0.3.1)
72
+ actionpack (= 7.0.3.1)
73
+ activesupport (= 7.0.3.1)
75
74
  method_source
76
- rake (>= 0.8.7)
75
+ rake (>= 12.2)
77
76
  thor (~> 1.0)
78
- rainbow (3.0.0)
79
- rake (13.0.3)
80
- redis (4.2.5)
81
- regexp_parser (2.1.1)
82
- request_store (1.5.0)
77
+ zeitwerk (~> 2.5)
78
+ rainbow (3.1.1)
79
+ rake (13.0.6)
80
+ redis (4.7.1)
81
+ regexp_parser (2.5.0)
82
+ request_store (1.5.1)
83
83
  rack (>= 1.4)
84
- reverse_markdown (2.0.0)
84
+ reverse_markdown (2.1.1)
85
85
  nokogiri
86
86
  rexml (3.2.5)
87
- rspec (3.10.0)
88
- rspec-core (~> 3.10.0)
89
- rspec-expectations (~> 3.10.0)
90
- rspec-mocks (~> 3.10.0)
91
- rspec-core (3.10.1)
92
- rspec-support (~> 3.10.0)
93
- rspec-expectations (3.10.1)
87
+ rspec (3.11.0)
88
+ rspec-core (~> 3.11.0)
89
+ rspec-expectations (~> 3.11.0)
90
+ rspec-mocks (~> 3.11.0)
91
+ rspec-core (3.11.0)
92
+ rspec-support (~> 3.11.0)
93
+ rspec-expectations (3.11.0)
94
94
  diff-lcs (>= 1.2.0, < 2.0)
95
- rspec-support (~> 3.10.0)
96
- rspec-mocks (3.10.2)
95
+ rspec-support (~> 3.11.0)
96
+ rspec-mocks (3.11.1)
97
97
  diff-lcs (>= 1.2.0, < 2.0)
98
- rspec-support (~> 3.10.0)
99
- rspec-support (3.10.2)
98
+ rspec-support (~> 3.11.0)
99
+ rspec-support (3.11.0)
100
100
  rubocop (0.93.1)
101
101
  parallel (~> 1.10)
102
102
  parser (>= 2.7.1.5)
@@ -106,12 +106,12 @@ GEM
106
106
  rubocop-ast (>= 0.6.0)
107
107
  ruby-progressbar (~> 1.7)
108
108
  unicode-display_width (>= 1.4.0, < 2.0)
109
- rubocop-ast (1.4.1)
110
- parser (>= 2.7.1.5)
109
+ rubocop-ast (1.19.1)
110
+ parser (>= 3.1.1.0)
111
111
  rubocop-performance (1.5.2)
112
112
  rubocop (>= 0.71.0)
113
113
  ruby-progressbar (1.11.0)
114
- sidekiq (6.2.1)
114
+ sidekiq (6.5.1)
115
115
  connection_pool (>= 2.2.2)
116
116
  rack (~> 2.0)
117
117
  redis (>= 4.2.0)
@@ -120,10 +120,11 @@ GEM
120
120
  json (>= 1.8, < 3)
121
121
  simplecov-html (~> 0.10.0)
122
122
  simplecov-html (0.10.2)
123
- solargraph (0.40.4)
124
- backport (~> 1.1)
123
+ solargraph (0.45.0)
124
+ backport (~> 1.2)
125
125
  benchmark
126
126
  bundler (>= 1.17.2)
127
+ diff-lcs (~> 1.4)
127
128
  e2mmap
128
129
  jaro_winkler (~> 1.5)
129
130
  kramdown (~> 2.3)
@@ -134,13 +135,15 @@ GEM
134
135
  thor (~> 1.0)
135
136
  tilt (~> 2.0)
136
137
  yard (~> 0.9, >= 0.9.24)
137
- thor (1.1.0)
138
+ thor (1.2.1)
138
139
  tilt (2.0.10)
139
140
  tzinfo (2.0.4)
140
141
  concurrent-ruby (~> 1.0)
141
- unicode-display_width (1.7.0)
142
- yard (0.9.26)
143
- zeitwerk (2.4.2)
142
+ unicode-display_width (1.8.0)
143
+ webrick (1.7.0)
144
+ yard (0.9.28)
145
+ webrick (~> 1.7.0)
146
+ zeitwerk (2.6.0)
144
147
 
145
148
  PLATFORMS
146
149
  ruby
@@ -11,11 +11,14 @@ module Heavylog
11
11
  "messages" => "message",
12
12
  "request_id" => "http.request.id",
13
13
  "method" => "http.request.method",
14
- "format" => "http.request.mime_type",
14
+ "referrer" => "http.request.referrer",
15
+ "format" => "http.response.format",
15
16
  "status" => "http.response.status_code",
16
17
  "location" => "http.response.location",
17
18
  "ip" => "source.address",
19
+ "host" => "url.domain",
18
20
  "path" => "url.original",
21
+ "user_agent" => "user_agent.original",
19
22
  "controller" => "heavylog.controller",
20
23
  "action" => "heavylog.action",
21
24
  "unpermitted_params" => "heavylog.unpermitted_params",
@@ -27,22 +30,38 @@ module Heavylog
27
30
 
28
31
  def call(data)
29
32
  ECS_MAP.each do |original, correct|
30
- data[correct] = data.delete(original) if data[original]
33
+ dig_set(data, correct.split("."), data.delete(original)) if data.key?(original)
31
34
  end
32
35
 
33
- data["event.module"] = "heavylog"
34
- data["event.category"] = "web"
35
- data["event.dataset"] ||= data["heavylog.controller"] == "SidekiqLogger" ? "heavylog.sidekiq" : "heavylog.rails"
36
+ dig_set(data, %w[event module], "heavylog")
37
+ dig_set(data, %w[event category], "web")
36
38
 
37
- if data["http.response.status_code"]
38
- data["event.outcome"] = (200..399).cover?(data["http.response.status_code"]) ? "success" : "failure"
39
+ unless data.dig("event", "dataset")
40
+ value = data.dig("heavylog", "controller") == "SidekiqLogger" ? "heavylog.sidekiq" : "heavylog.rails"
41
+ dig_set(data, %w[event dataset], value)
39
42
  end
40
43
 
41
- data["source.ip"] ||= data["source.address"]
42
- data["url.path"] ||= data["url.original"]
44
+ if (code = data.dig("http", "response", "status_code"))
45
+ dig_set(data, %w[event outcome], (200..399).cover?(code) ? "success" : "failure")
46
+ end
47
+
48
+ dig_set(data, %w[source ip], data.dig("source", "address")) unless data.dig("source", "ip")
49
+ dig_set(data, %w[url path], data.dig("url", "original")) unless data.dig("url", "path")
43
50
 
44
51
  ::JSON.dump(data)
45
52
  end
53
+
54
+ private
55
+
56
+ def dig_set(obj, keys, value)
57
+ key = keys.first
58
+ if keys.length == 1
59
+ obj[key] = value
60
+ else
61
+ obj[key] = {} unless obj[key]
62
+ dig_set(obj[key], keys.slice(1..-1), value)
63
+ end
64
+ end
46
65
  end
47
66
  end
48
67
  end
@@ -31,6 +31,7 @@ module Heavylog
31
31
  data.merge!(extract_runtimes(event, payload))
32
32
  data.merge!(extract_location)
33
33
  data.merge!(extract_unpermitted_params)
34
+ data.merge!(extract_request_data(payload))
34
35
  data.merge!(custom_options(event))
35
36
  end
36
37
 
@@ -59,11 +60,11 @@ module Heavylog
59
60
  end
60
61
 
61
62
  def extract_status(payload)
62
- if (status = payload[:status])
63
- { status: status.to_i }
64
- elsif (error = payload[:exception])
63
+ if (error = payload[:exception])
65
64
  exception, message = error
66
- { status: get_error_status_code(exception), error: "#{exception}: #{message}" }
65
+ { status: payload[:status] || get_error_status_code(exception), error: "#{exception}: #{message}" }
66
+ elsif (status = payload[:status])
67
+ { status: status.to_i }
67
68
  else
68
69
  { status: 0 }
69
70
  end
@@ -101,5 +102,19 @@ module Heavylog
101
102
  RequestStore.store[:heavylog_unpermitted_params] = nil
102
103
  { unpermitted_params: unpermitted_params }
103
104
  end
105
+
106
+ def extract_request_data(payload)
107
+ if payload[:request].is_a?(ActionDispatch::Request)
108
+ data = {}
109
+
110
+ data[:referrer] = payload[:request].referrer if payload[:request].referrer
111
+ data[:host] = payload[:request].host
112
+ data[:user_agent] = payload[:request].user_agent
113
+
114
+ return data
115
+ end
116
+
117
+ {}
118
+ end
104
119
  end
105
120
  end
@@ -11,7 +11,9 @@ module Heavylog
11
11
  end
12
12
 
13
13
  def call(env)
14
- ignore = @sprockets && env["PATH_INFO"] =~ @assets_regex
14
+ ignore = (@sprockets && env["PATH_INFO"] =~ @assets_regex) ||
15
+ (Heavylog.ignore_path && env["PATH_INFO"] =~ Heavylog.ignore_path)
16
+
15
17
  unless ignore
16
18
  request = ActionDispatch::Request.new(env)
17
19
  RequestStore.store[:heavylog_request_id] = request.uuid
@@ -7,6 +7,7 @@ module Heavylog
7
7
  config.heavylog.path = "log/heavylog.log"
8
8
  config.heavylog.message_limit = 1024 * 1024 * 50 # 50MB
9
9
  config.heavylog.log_sidekiq = false
10
+ config.heavylog.ignore_path = nil
10
11
  config.heavylog.error_handler = lambda { |e|
11
12
  Kernel.puts "HeavyLog: Error writing to log: #{e.class}: #{e.message}\n #{e.backtrace.join("\n ")}"
12
13
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Heavylog
4
- VERSION = "0.0.20"
4
+ VERSION = "0.0.23"
5
5
  end
data/lib/heavylog.rb CHANGED
@@ -17,7 +17,7 @@ module Heavylog
17
17
  TRUNCATION = "[TRUNCATED]"
18
18
  ANSI_REGEX = /\e\[(\d+)m/.freeze
19
19
 
20
- mattr_accessor :logger, :application, :formatter, :log_level
20
+ mattr_accessor :logger, :application, :formatter, :log_level, :ignore_path
21
21
 
22
22
  def setup(app)
23
23
  self.application = app
@@ -43,6 +43,7 @@ module Heavylog
43
43
 
44
44
  Heavylog.formatter = config.formatter || Heavylog::Formatters::Raw.new
45
45
  Heavylog.log_level = config.log_level || :info
46
+ Heavylog.ignore_path = config.ignore_path || nil
46
47
  end
47
48
 
48
49
  def attach_to_action_controller
@@ -53,7 +54,7 @@ module Heavylog
53
54
  return unless config.log_sidekiq
54
55
 
55
56
  Sidekiq.configure_server do |config|
56
- config.options[:job_logger] = SidekiqLogger
57
+ config.job_logger = SidekiqLogger
57
58
  end
58
59
 
59
60
  Sidekiq.error_handlers << SidekiqExceptionHandler.new
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.20
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristjan Rang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-11 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -214,7 +214,7 @@ homepage: https://github.com/krisrang/heavylog
214
214
  licenses:
215
215
  - MIT
216
216
  metadata: {}
217
- post_install_message:
217
+ post_install_message:
218
218
  rdoc_options: []
219
219
  require_paths:
220
220
  - lib
@@ -229,8 +229,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements: []
232
- rubygems_version: 3.2.15
233
- signing_key:
232
+ rubygems_version: 3.3.7
233
+ signing_key:
234
234
  specification_version: 4
235
235
  summary: Format all Rails logging per request
236
236
  test_files: []