log_sanity 1.0.0 → 1.2.0

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: 3cd638933608ceaeffa6e4ac4f9dff3650128a21e7afee0d31f003b6f381c6ff
4
- data.tar.gz: c0753610f32d3828d8d667c06fd6c023c7ad08aed3b167d6851f99c579c446d6
3
+ metadata.gz: 4b955406c6e0a56ba3242cef72764433a08abc54fa8e0b0241eb85ed3038f5b2
4
+ data.tar.gz: d663a844b8eb827ff0f7693386b7c48e13ab609c1b229978d5626d41b4c4c6f7
5
5
  SHA512:
6
- metadata.gz: efbdfe624f62f7e5883cb4e7a10e0f32ad41dea981f8cad792c1b27c18cdd3452dbf8e2345601df786458a428f91fe2e5751979ffb2d318a0558f9352a98ddea
7
- data.tar.gz: 74bf53856c0eabfd35f3d0b90893bba70b7a671579253f2b2dc4440ae4a7017de97cd8410b01a869d7091f975641464b52ab0d7021952eaf09a4b84d05836b2b
6
+ metadata.gz: ebf2265262ef180c669376798887e66e92176e07fcc725f8ccfc6bdf0e642c450363d0214f0aed8519c9e1ac7369ac117e6f8ceb2f2d88cdf3da9d12bc17616b
7
+ data.tar.gz: d1eaf205cd088590de19326404fc59eb076a8cd6d9d8c3dc777a1fa681d017d213cc5796c43f88efba8a8ebc52e875bf39fd5e63da3d72ffdb82111d9c23c2a2
data/Gemfile.lock CHANGED
@@ -1,138 +1,136 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_sanity (1.0.0)
5
- rails (>= 5.2, < 6.2)
4
+ log_sanity (1.2.0)
5
+ rails (>= 5.2, < 7.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.1.0)
11
- actionpack (= 6.1.0)
12
- activesupport (= 6.1.0)
10
+ actioncable (6.1.4.6)
11
+ actionpack (= 6.1.4.6)
12
+ activesupport (= 6.1.4.6)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (6.1.0)
16
- actionpack (= 6.1.0)
17
- activejob (= 6.1.0)
18
- activerecord (= 6.1.0)
19
- activestorage (= 6.1.0)
20
- activesupport (= 6.1.0)
15
+ actionmailbox (6.1.4.6)
16
+ actionpack (= 6.1.4.6)
17
+ activejob (= 6.1.4.6)
18
+ activerecord (= 6.1.4.6)
19
+ activestorage (= 6.1.4.6)
20
+ activesupport (= 6.1.4.6)
21
21
  mail (>= 2.7.1)
22
- actionmailer (6.1.0)
23
- actionpack (= 6.1.0)
24
- actionview (= 6.1.0)
25
- activejob (= 6.1.0)
26
- activesupport (= 6.1.0)
22
+ actionmailer (6.1.4.6)
23
+ actionpack (= 6.1.4.6)
24
+ actionview (= 6.1.4.6)
25
+ activejob (= 6.1.4.6)
26
+ activesupport (= 6.1.4.6)
27
27
  mail (~> 2.5, >= 2.5.4)
28
28
  rails-dom-testing (~> 2.0)
29
- actionpack (6.1.0)
30
- actionview (= 6.1.0)
31
- activesupport (= 6.1.0)
29
+ actionpack (6.1.4.6)
30
+ actionview (= 6.1.4.6)
31
+ activesupport (= 6.1.4.6)
32
32
  rack (~> 2.0, >= 2.0.9)
33
33
  rack-test (>= 0.6.3)
34
34
  rails-dom-testing (~> 2.0)
35
35
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.1.0)
37
- actionpack (= 6.1.0)
38
- activerecord (= 6.1.0)
39
- activestorage (= 6.1.0)
40
- activesupport (= 6.1.0)
36
+ actiontext (6.1.4.6)
37
+ actionpack (= 6.1.4.6)
38
+ activerecord (= 6.1.4.6)
39
+ activestorage (= 6.1.4.6)
40
+ activesupport (= 6.1.4.6)
41
41
  nokogiri (>= 1.8.5)
42
- actionview (6.1.0)
43
- activesupport (= 6.1.0)
42
+ actionview (6.1.4.6)
43
+ activesupport (= 6.1.4.6)
44
44
  builder (~> 3.1)
45
45
  erubi (~> 1.4)
46
46
  rails-dom-testing (~> 2.0)
47
47
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.1.0)
49
- activesupport (= 6.1.0)
48
+ activejob (6.1.4.6)
49
+ activesupport (= 6.1.4.6)
50
50
  globalid (>= 0.3.6)
51
- activemodel (6.1.0)
52
- activesupport (= 6.1.0)
53
- activerecord (6.1.0)
54
- activemodel (= 6.1.0)
55
- activesupport (= 6.1.0)
56
- activestorage (6.1.0)
57
- actionpack (= 6.1.0)
58
- activejob (= 6.1.0)
59
- activerecord (= 6.1.0)
60
- activesupport (= 6.1.0)
61
- marcel (~> 0.3.1)
62
- mimemagic (~> 0.3.2)
63
- activesupport (6.1.0)
51
+ activemodel (6.1.4.6)
52
+ activesupport (= 6.1.4.6)
53
+ activerecord (6.1.4.6)
54
+ activemodel (= 6.1.4.6)
55
+ activesupport (= 6.1.4.6)
56
+ activestorage (6.1.4.6)
57
+ actionpack (= 6.1.4.6)
58
+ activejob (= 6.1.4.6)
59
+ activerecord (= 6.1.4.6)
60
+ activesupport (= 6.1.4.6)
61
+ marcel (~> 1.0.0)
62
+ mini_mime (>= 1.1.0)
63
+ activesupport (6.1.4.6)
64
64
  concurrent-ruby (~> 1.0, >= 1.0.2)
65
65
  i18n (>= 1.6, < 2)
66
66
  minitest (>= 5.1)
67
67
  tzinfo (~> 2.0)
68
68
  zeitwerk (~> 2.3)
69
69
  builder (3.2.4)
70
- concurrent-ruby (1.1.7)
70
+ concurrent-ruby (1.1.9)
71
71
  crass (1.0.6)
72
72
  erubi (1.10.0)
73
- globalid (0.4.2)
74
- activesupport (>= 4.2.0)
75
- i18n (1.8.5)
73
+ globalid (1.0.0)
74
+ activesupport (>= 5.0)
75
+ i18n (1.10.0)
76
76
  concurrent-ruby (~> 1.0)
77
- loofah (2.8.0)
77
+ loofah (2.14.0)
78
78
  crass (~> 1.0.2)
79
79
  nokogiri (>= 1.5.9)
80
80
  mail (2.7.1)
81
81
  mini_mime (>= 0.1.1)
82
- marcel (0.3.3)
83
- mimemagic (~> 0.3.2)
82
+ marcel (1.0.2)
84
83
  method_source (1.0.0)
85
- mimemagic (0.3.5)
86
- mini_mime (1.0.2)
87
- mini_portile2 (2.4.0)
88
- minitest (5.14.2)
89
- nio4r (2.5.4)
90
- nokogiri (1.10.10)
91
- mini_portile2 (~> 2.4.0)
84
+ mini_mime (1.1.2)
85
+ minitest (5.15.0)
86
+ nio4r (2.5.8)
87
+ nokogiri (1.13.3-x86_64-darwin)
88
+ racc (~> 1.4)
89
+ racc (1.6.0)
92
90
  rack (2.2.3)
93
91
  rack-test (1.1.0)
94
92
  rack (>= 1.0, < 3)
95
- rails (6.1.0)
96
- actioncable (= 6.1.0)
97
- actionmailbox (= 6.1.0)
98
- actionmailer (= 6.1.0)
99
- actionpack (= 6.1.0)
100
- actiontext (= 6.1.0)
101
- actionview (= 6.1.0)
102
- activejob (= 6.1.0)
103
- activemodel (= 6.1.0)
104
- activerecord (= 6.1.0)
105
- activestorage (= 6.1.0)
106
- activesupport (= 6.1.0)
93
+ rails (6.1.4.6)
94
+ actioncable (= 6.1.4.6)
95
+ actionmailbox (= 6.1.4.6)
96
+ actionmailer (= 6.1.4.6)
97
+ actionpack (= 6.1.4.6)
98
+ actiontext (= 6.1.4.6)
99
+ actionview (= 6.1.4.6)
100
+ activejob (= 6.1.4.6)
101
+ activemodel (= 6.1.4.6)
102
+ activerecord (= 6.1.4.6)
103
+ activestorage (= 6.1.4.6)
104
+ activesupport (= 6.1.4.6)
107
105
  bundler (>= 1.15.0)
108
- railties (= 6.1.0)
106
+ railties (= 6.1.4.6)
109
107
  sprockets-rails (>= 2.0.0)
110
108
  rails-dom-testing (2.0.3)
111
109
  activesupport (>= 4.2.0)
112
110
  nokogiri (>= 1.6)
113
- rails-html-sanitizer (1.3.0)
111
+ rails-html-sanitizer (1.4.2)
114
112
  loofah (~> 2.3)
115
- railties (6.1.0)
116
- actionpack (= 6.1.0)
117
- activesupport (= 6.1.0)
113
+ railties (6.1.4.6)
114
+ actionpack (= 6.1.4.6)
115
+ activesupport (= 6.1.4.6)
118
116
  method_source
119
- rake (>= 0.8.7)
117
+ rake (>= 0.13)
120
118
  thor (~> 1.0)
121
- rake (13.0.3)
119
+ rake (13.0.6)
122
120
  sprockets (4.0.2)
123
121
  concurrent-ruby (~> 1.0)
124
122
  rack (> 1, < 3)
125
- sprockets-rails (3.2.2)
126
- actionpack (>= 4.0)
127
- activesupport (>= 4.0)
123
+ sprockets-rails (3.4.2)
124
+ actionpack (>= 5.2)
125
+ activesupport (>= 5.2)
128
126
  sprockets (>= 3.0.0)
129
- thor (1.0.1)
127
+ thor (1.2.1)
130
128
  tzinfo (2.0.4)
131
129
  concurrent-ruby (~> 1.0)
132
- websocket-driver (0.7.3)
130
+ websocket-driver (0.7.5)
133
131
  websocket-extensions (>= 0.1.0)
134
132
  websocket-extensions (0.1.5)
135
- zeitwerk (2.4.2)
133
+ zeitwerk (2.5.4)
136
134
 
137
135
  PLATFORMS
138
136
  ruby
@@ -141,4 +139,4 @@ DEPENDENCIES
141
139
  log_sanity!
142
140
 
143
141
  BUNDLED WITH
144
- 1.17.3
142
+ 2.2.22
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017-2020 thomas morgan
1
+ Copyright 2017-2022 thomas morgan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -143,7 +143,7 @@ LogSanity takes these and adds them to the default request log entry (but _not_
143
143
 
144
144
  LogSanity is intended for production use at log_level info. At level debug, some logs are simply turned off. Others may continue to output as normal strings (such as ActiveRecord).
145
145
 
146
- There is no need to use ActiveSupport::TaggedLogging with your logger. Just set the logger directly (if not using the default):
146
+ If not using tags, there is no need to use ActiveSupport::TaggedLogging with your logger. Just set the logger directly (if not using the default):
147
147
  ```
148
148
  config.logger = ActiveSupport::Logger.new(STDOUT)
149
149
  ```
@@ -172,7 +172,7 @@ There are still some things that could be handled better (such as multi-line str
172
172
 
173
173
  Pull requests are welcomed and encouraged. The only goal is to avoid making things unnecessarily complex.
174
174
 
175
- Tested on Rails 5.2 through 6.1 (or later). Anything older is untested. Small patches for older compatibility will be considered.
175
+ Tested on Rails 5.2 through 7.0 (or later). Anything older is untested. Small patches for older compatibility will be considered.
176
176
 
177
177
  License: MIT
178
178
 
@@ -0,0 +1,39 @@
1
+ module LogSanity
2
+ module Extensions
3
+ module ActionCableConnection
4
+ extend ActiveSupport::Concern
5
+
6
+ def close(reason: nil, **args)
7
+ @close_reason = reason
8
+ super
9
+ end
10
+
11
+ def process
12
+ payload = { request: request }
13
+ ActiveSupport::Notifications.instrument("process.action_cable", payload) do
14
+ status, _, _ = response = super
15
+ payload[:status] = status==-1 ? 101 : status
16
+ response
17
+ end
18
+ end
19
+
20
+ def reject_unauthorized_connection
21
+ logger.instance_variable_get(:@logger).silence(Logger::FATAL) do
22
+ super
23
+ end
24
+ end
25
+
26
+ def on_close(reason, code)
27
+ payload = {
28
+ connection_sec: Time.now - @started_at,
29
+ request: request
30
+ }
31
+ payload[:reason] = @close_reason if @close_reason
32
+ ActiveSupport::Notifications.instrument("on_close.action_cable", payload) do
33
+ super
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -9,12 +9,16 @@
9
9
 
10
10
  module LogSanity
11
11
  class Formatter < Logger::Formatter
12
+ include ActiveSupport::TaggedLogging::Formatter
13
+ # tags are ignored when rendering as json
14
+ # however, tags are prepended when rendering with string_formatter
12
15
 
13
16
  def call(severity, timestamp, progname, msg)
14
17
  if msg.is_a? Hash
15
- msg['at'] = timestamp unless msg.key?('at')
18
+ msg.reverse_merge!('at' => timestamp) unless msg.key?('at')
16
19
  elsif msg.is_a? String
17
20
  if string_formatter
21
+ msg = "#{tags_text}#{msg}" if current_tags.any?
18
22
  return string_formatter.call(severity, timestamp, progname, msg)
19
23
  else
20
24
  msg = {'at' => timestamp, 'message' => msg}
@@ -22,22 +26,14 @@ module LogSanity
22
26
  else
23
27
  msg = {'at' => timestamp, 'object' => msg.inspect}
24
28
  end
25
- if msg['at'].is_a? Float
26
- monot = Process.clock_gettime(Process::CLOCK_MONOTONIC)
27
- msg['at'] = Time.now - (monot - msg['at'])
28
- end
29
29
  msg['at'] = msg['at'].utc
30
30
  "#{msg.to_json}\n"
31
31
  end
32
32
 
33
- # noop; for TaggedLogging compatibility
34
- def clear_tags! ; end
35
- def tagged(*_) ; yield self ; end
36
- def current_tags ; [] ; end
37
-
38
33
  attr_writer :string_formatter
39
34
 
40
35
  def string_formatter
36
+ return @string_formatter if defined?(@string_formatter)
41
37
  @string_formatter ||= ActiveSupport::Logger::SimpleFormatter.new
42
38
  end
43
39
 
@@ -0,0 +1,30 @@
1
+ module LogSanity
2
+ module LogSubscriber
3
+ class ActionCable < Base
4
+
5
+ def process(event)
6
+ payload = event.payload
7
+ log 'event', 'ws_connect'
8
+ log 'status', payload[:status]
9
+ # logged by the actiondispatch subscriber
10
+ end
11
+
12
+ def on_close(event)
13
+ payload = event.payload
14
+ request = payload[:request]
15
+ info do
16
+ e = {
17
+ 'at' => Time.now,
18
+ 'event' => 'ws_disconnect',
19
+ 'ip' => request.remote_ip,
20
+ 'rq' => request.uuid,
21
+ 'duration' => {'socket' => "#{payload[:connection_sec].round}s"}
22
+ }
23
+ e['reason'] = payload[:reason] if payload[:reason]
24
+ e
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -11,7 +11,7 @@ module LogSanity
11
11
  response = payload[:response]
12
12
  method = payload[:method] || (request.request_method rescue nil) || 'UNKNOWN'
13
13
  f2 = {
14
- 'at' => event.time,
14
+ 'at' => event_start(event),
15
15
  'event' => "#{request.scheme}_#{method.downcase}",
16
16
  'ip' => request.remote_ip,
17
17
  'rq' => request.uuid,
@@ -5,6 +5,15 @@ module LogSanity
5
5
  private
6
6
  delegate :fields, :log, to: LogSanity
7
7
 
8
+ def event_start(event)
9
+ if event.time.is_a? Float
10
+ # convert event's monotonic start .time to a Time
11
+ Time.current - event.duration/1000.0
12
+ else
13
+ event.time
14
+ end
15
+ end
16
+
8
17
  end
9
18
  end
10
19
  end
@@ -10,7 +10,11 @@ module LogSanity
10
10
  if app.config.logsanity.enabled
11
11
  orig_formatter = Rails.logger.formatter
12
12
  Rails.logger.formatter = LogSanity::Formatter.new
13
- Rails.logger.formatter.string_formatter = orig_formatter unless app.config.logsanity.json_strings
13
+ if app.config.logsanity.json_strings
14
+ Rails.logger.formatter.string_formatter = false
15
+ else
16
+ Rails.logger.formatter.string_formatter = orig_formatter if orig_formatter
17
+ end
14
18
 
15
19
  if defined?(ActionController)
16
20
  require 'action_controller/log_subscriber'
@@ -37,11 +41,25 @@ module LogSanity
37
41
  end
38
42
  end
39
43
  if defined?(ActiveRecord)
44
+ # require 'active_record/log_subscriber'
45
+ # ActiveRecord::LogSubscriber.detach_from :active_record
46
+ # this turns off measurements too
40
47
  if ActiveRecord::Base.logger.debug?
41
48
  Rails.logger.info '[LogSanity] ActiveRecord::Base.logger in debug mode and will still log queries'
42
49
  end
43
50
  end
44
51
 
52
+ ActiveSupport.on_load(:action_cable) do
53
+ orig_logger = logger || Rails.logger
54
+ self.logger = orig_logger.clone.tap do |l|
55
+ l.level = Logger::WARN
56
+ end
57
+ end
58
+ ActiveSupport.on_load(:action_cable_connection) do
59
+ prepend LogSanity::Extensions::ActionCableConnection
60
+ end
61
+
62
+ LogSanity::LogSubscriber::ActionCable.attach_to :action_cable
45
63
  LogSanity::LogSubscriber::ActionController.attach_to :action_controller
46
64
  LogSanity::LogSubscriber::ActionDispatch.attach_to :action_dispatch
47
65
  LogSanity::LogSubscriber::ActionMailer.attach_to :action_mailer
@@ -1,3 +1,3 @@
1
1
  module LogSanity
2
- VERSION = '1.0.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/lib/log_sanity.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  %w( formatter
2
2
  railtie
3
3
  log_subscribers/base
4
+ log_subscribers/action_cable
4
5
  log_subscribers/action_controller
5
6
  log_subscribers/action_dispatch
6
7
  log_subscribers/action_mailer
7
8
  log_subscribers/active_job
8
9
  middleware/request_logger
9
10
  middleware/routing_error_catcher
11
+ extensions/action_cable_connection
10
12
  extensions/action_controller_helper
11
13
  extensions/active_support_subscriber
12
14
  ).each do |fn|
data/log_sanity.gemspec CHANGED
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency 'rails', '>= 5.2', '< 6.2'
20
+ s.add_dependency 'rails', '>= 5.2', '< 7.1'
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_sanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.2'
32
+ version: '7.1'
33
33
  description: LogSanity - Bring sanity to Rails logs by reducing verbosity, using json
34
34
  output, and more.
35
35
  email:
@@ -45,9 +45,11 @@ files:
45
45
  - README.md
46
46
  - Rakefile
47
47
  - lib/log_sanity.rb
48
+ - lib/log_sanity/extensions/action_cable_connection.rb
48
49
  - lib/log_sanity/extensions/action_controller_helper.rb
49
50
  - lib/log_sanity/extensions/active_support_subscriber.rb
50
51
  - lib/log_sanity/formatter.rb
52
+ - lib/log_sanity/log_subscribers/action_cable.rb
51
53
  - lib/log_sanity/log_subscribers/action_controller.rb
52
54
  - lib/log_sanity/log_subscribers/action_dispatch.rb
53
55
  - lib/log_sanity/log_subscribers/action_mailer.rb
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  - !ruby/object:Gem::Version
122
124
  version: '0'
123
125
  requirements: []
124
- rubygems_version: 3.0.9
126
+ rubygems_version: 3.2.22
125
127
  signing_key:
126
128
  specification_version: 4
127
129
  summary: LogSanity - Bring sanity to Rails logs