slack_log_device 5.1.2 → 6.0.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: eba340374298e2296f5ca22cfdad6b96b7590a0d69359cdfd8393dc07c42a7a5
4
- data.tar.gz: 2b53706938364ca14d6a50b852135eb04124d2a0dae29c97ed5fbeff927f9c04
3
+ metadata.gz: 75f3fd14091501e77cb9e2aec3df1f75c0d83b506161d990e9e3c05dd0fe78c3
4
+ data.tar.gz: b53bd12072de5c44a1c659ebd636545b291353d361fe429f843f5dba366b0b4c
5
5
  SHA512:
6
- metadata.gz: 575e3412f21bc9c8985642478612674d5ace56652398df981ef745592ab65e00bf684da7c0187091e8e3e8cf4d28d005d0ed8ec4458ed9ffe5372456a2414e2d
7
- data.tar.gz: 320c850a654bf1f115658c5c2466a0549a2ee7a4a4bf58ee4767e2191a9c55b2d82314bd40423f8b42d83f1bc0e8451490b2e1c9ecc2f1fbe7d08a04e80a355e
6
+ metadata.gz: 5428ca393ab3740400f003baf7c433e6da1ee09b21d212a2272fd40e35554ee9a48e08b5e196e15885180f5f0800f0c166d562677023c11d864d01b8077dc720
7
+ data.tar.gz: 1a4c62261c00e45ab94767bfc78f4cb96dcf65cb447d8fb70c33db8e830eb42c014ea02f20cb74566c1c11635bc956d123e570f8fb291be21dc16b85503d25da
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.2
1
+ 6.0.0
@@ -27,9 +27,9 @@ class SlackLogDevice
27
27
  @message_converter = block_given? ? Proc.new(&block) : -> (message) { message }
28
28
  end
29
29
 
30
- def call(severity, datetime, progname, message)
30
+ def call(severity, _datetime, progname, message)
31
31
  text = "*`#{severity}`*"
32
- text << " (*#{progname}*)" if progname.present?
32
+ text << " (*#{to_utf8(progname)}*)" if progname.present?
33
33
  text << ':'
34
34
  if message.is_a?(Exception)
35
35
  exception = message
@@ -63,7 +63,7 @@ class SlackLogDevice
63
63
 
64
64
  def icon_emoji=(value)
65
65
  value = value.to_s.strip.presence
66
- @icon_emojis.keys.each do |severity|
66
+ @icon_emojis.each_key do |severity|
67
67
  @icon_emojis[severity] = value
68
68
  end
69
69
  end
@@ -76,7 +76,6 @@ class SlackLogDevice
76
76
  values.each do |severity, emoji|
77
77
  @icon_emojis[parse_severity(severity)] = emoji.to_s.strip.presence
78
78
  end
79
- @icon_emojis
80
79
  end
81
80
 
82
81
  def max_backtrace_lines=(value)
@@ -89,26 +88,27 @@ class SlackLogDevice
89
88
 
90
89
  def append_exception_backtrace(text, exception)
91
90
  backtrace = format_backtrace(exception, MAX_MESSAGE_LENGTH - text.size - 2)
92
- backtrace.present? ? "#{text}\n\n#{backtrace}" : text
91
+ backtrace.present? ? "#{to_utf8(text)}\n\n#{backtrace}" : text
93
92
  end
94
93
 
95
94
  def append_exception_cause(text, exception)
96
95
  cause = exception.cause
96
+ text = to_utf8(text)
97
97
  return text if cause.nil?
98
98
  message = "\n\nCaused by `#{cause.class}`"
99
99
  return text if (text + message).size > MAX_MESSAGE_LENGTH
100
- text = truncate("#{text}#{message}: #{cause.message}")
100
+ text = truncate("#{text}#{message}: #{to_utf8(cause.message)}")
101
101
  text = append_exception_backtrace(text, cause)
102
102
  append_exception_cause(text, cause)
103
103
  end
104
104
 
105
105
  def append_metadata(text, message)
106
106
  metadata = format_metadata(message, MAX_MESSAGE_LENGTH - text.size - 2)
107
- metadata.present? ? "#{text}\n\n#{metadata}" : text
107
+ metadata.present? ? "#{to_utf8(text)}\n\n#{metadata}" : text
108
108
  end
109
109
 
110
110
  def convert_message(message)
111
- @message_converter.call(message.to_s.strip).to_s.strip
111
+ to_utf8(@message_converter.call(to_utf8(message.to_s.strip)).to_s.strip)
112
112
  end
113
113
 
114
114
  def default_metadata(request)
@@ -125,16 +125,16 @@ class SlackLogDevice
125
125
  'Machine' => Socket.gethostname,
126
126
  'PID' => Process.pid,
127
127
  })
128
- metadata.keys.each do |key|
128
+ metadata.each_key do |key|
129
129
  value = metadata[key]
130
- metadata[key] = "`#{value.to_s.strip}`" if value.present?
130
+ metadata[key] = "`#{to_utf8(value.to_s.strip)}`" if value.present?
131
131
  end
132
132
  metadata
133
133
  end
134
134
 
135
135
  def format_backtrace(exception, size_available)
136
136
  return nil if max_backtrace_lines == 0 || size_available < 7
137
- backtrace = (exception.backtrace || []).select(&:present?).compact
137
+ backtrace = (exception.backtrace || []).select(&:present?).compact.map { |line| to_utf8(line) }
138
138
  return nil if backtrace.empty?
139
139
  if max_backtrace_lines < 0
140
140
  text = backtrace.join("\n")
@@ -153,7 +153,7 @@ class SlackLogDevice
153
153
  options[:request] = request if request.present?
154
154
  text = default_metadata(request).merge(extra_metadata).map do |name, value|
155
155
  value = value.call(options) if value.respond_to?(:call)
156
- value.present? ? "• *#{name.strip}*: #{value.strip}" : nil
156
+ value.present? ? "• *#{to_utf8(name).strip}*: #{to_utf8(value).strip}" : nil
157
157
  end.compact.join("\n")
158
158
  return nil if text.blank?
159
159
  truncate(text, size_available)
@@ -169,7 +169,12 @@ class SlackLogDevice
169
169
  message = message.strip
170
170
  return message if message.size <= max_length
171
171
  return message[0, max_length] if max_length < 3
172
- "#{message[0, max_length - 3]}..."
172
+ to_utf8("#{message[0, max_length - 3]}...")
173
+ end
174
+
175
+ def to_utf8(text)
176
+ return text if text.nil? || text.encoding == Encoding::UTF_8
177
+ text.encode(Encoding::UTF_8) rescue text.dup.force_encoding(Encoding::UTF_8)
173
178
  end
174
179
 
175
180
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support/isolated_execution_state'
1
2
  require 'active_support/core_ext/hash'
2
3
  require 'active_support/core_ext/string'
3
4
  require 'httparty'
@@ -53,7 +54,7 @@ class SlackLogDevice
53
54
  end
54
55
 
55
56
  def flush
56
- while !@buffer.empty? do
57
+ until @buffer.empty?
57
58
  message = nil
58
59
  @mutex.synchronize do
59
60
  message = @buffer.pop
@@ -65,9 +66,11 @@ class SlackLogDevice
65
66
  data['icon_emoji'] = message.icon_emoji if message.respond_to?(:icon_emoji) && message.icon_emoji.present?
66
67
  data['username'] = username if username.present?
67
68
  begin
68
- HTTParty.post(webhook_url, body: data.to_json, headers: { 'Content-Type' => 'application/json' }, timeout: timeout)
69
+ HTTParty.post(webhook_url, body: data.to_json, headers: { 'Content-Type' => 'application/json' }, timeout:)
70
+ # rubocop:disable Lint/RescueException
69
71
  rescue Exception => e
70
- STDERR.puts(e)
72
+ # rubocop:enable Lint/RescueException
73
+ warn(e)
71
74
  end
72
75
  end
73
76
  nil
@@ -111,7 +114,7 @@ class SlackLogDevice
111
114
  @mutex.synchronize do
112
115
  @buffer << message
113
116
  end
114
- @flush_thread.kill if @flush_thread
117
+ @flush_thread&.kill
115
118
  if flush?
116
119
  flush
117
120
  else
@@ -9,16 +9,19 @@ Gem::Specification.new do |s|
9
9
  s.description = 'LogDevice implementation that post logs on a Slack channel'
10
10
  s.license = 'MIT'
11
11
 
12
- s.files = `git ls-files | grep -vE '^(spec/|test/|\\.|Gemfile|Rakefile)'`.split("\n")
13
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ s.files = %x(git ls-files | grep -vE '^(spec/|test/|\\.|Gemfile|Rakefile)').split("\n")
13
+ s.executables = %x(git ls-files -- bin/*).split("\n").map { |f| File.basename(f) }
14
14
  s.require_paths = ['lib']
15
15
 
16
16
  s.required_ruby_version = '>= 2.1.0'
17
17
 
18
- s.add_dependency 'activesupport', '>= 4.1.0', '< 7.0.0'
19
- s.add_dependency 'httparty', '>= 0.14.0', '< 0.18.0'
18
+ s.add_dependency 'activesupport', '>= 7.0.0', '< 8.0.0'
19
+ s.add_dependency 'httparty', '>= 0.14.0', '< 0.21.0'
20
20
 
21
21
  s.add_development_dependency 'byebug', '>= 9.0.0', '< 12.0.0'
22
- s.add_development_dependency 'rake', '>= 12.0.0', '< 13.0.0'
23
- s.add_development_dependency 'rspec', '>= 3.5.0', '< 3.9.0'
22
+ s.add_development_dependency 'rake', '>= 12.0.0', '< 14.0.0'
23
+ s.add_development_dependency 'rspec', '>= 3.5.0', '< 3.11.0'
24
+ s.add_development_dependency 'rubocop', '>= 1.25.0', '< 2.0.0'
25
+ s.add_development_dependency 'rubocop-rake', '>= 0.6.0', '< 1.0.0'
26
+ s.add_development_dependency 'rubocop-rspec', '>= 2.8.0', '< 3.0.0'
24
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_log_device
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Toulotte
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2022-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: 7.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 7.0.0
22
+ version: 8.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.1.0
29
+ version: 7.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 7.0.0
32
+ version: 8.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: httparty
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: 0.14.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: 0.18.0
42
+ version: 0.21.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: 0.14.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: 0.18.0
52
+ version: 0.21.0
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: byebug
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +79,7 @@ dependencies:
79
79
  version: 12.0.0
80
80
  - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: 13.0.0
82
+ version: 14.0.0
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: 12.0.0
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
- version: 13.0.0
92
+ version: 14.0.0
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rspec
95
95
  requirement: !ruby/object:Gem::Requirement
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: 3.5.0
100
100
  - - "<"
101
101
  - !ruby/object:Gem::Version
102
- version: 3.9.0
102
+ version: 3.11.0
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
@@ -109,7 +109,67 @@ dependencies:
109
109
  version: 3.5.0
110
110
  - - "<"
111
111
  - !ruby/object:Gem::Version
112
- version: 3.9.0
112
+ version: 3.11.0
113
+ - !ruby/object:Gem::Dependency
114
+ name: rubocop
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 1.25.0
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: 2.0.0
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 1.25.0
130
+ - - "<"
131
+ - !ruby/object:Gem::Version
132
+ version: 2.0.0
133
+ - !ruby/object:Gem::Dependency
134
+ name: rubocop-rake
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 0.6.0
140
+ - - "<"
141
+ - !ruby/object:Gem::Version
142
+ version: 1.0.0
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 0.6.0
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.0.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 2.8.0
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: 3.0.0
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: 2.8.0
170
+ - - "<"
171
+ - !ruby/object:Gem::Version
172
+ version: 3.0.0
113
173
  description: LogDevice implementation that post logs on a Slack channel
114
174
  email: al@alweb.org
115
175
  executables: []
@@ -129,7 +189,7 @@ homepage: https://github.com/alexistoulotte/slack_log_device
129
189
  licenses:
130
190
  - MIT
131
191
  metadata: {}
132
- post_install_message:
192
+ post_install_message:
133
193
  rdoc_options: []
134
194
  require_paths:
135
195
  - lib
@@ -144,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
204
  - !ruby/object:Gem::Version
145
205
  version: '0'
146
206
  requirements: []
147
- rubygems_version: 3.0.3
148
- signing_key:
207
+ rubygems_version: 3.3.3
208
+ signing_key:
149
209
  specification_version: 4
150
210
  summary: LogDevice for Slack
151
211
  test_files: []