slack_log_device 5.1.3 → 5.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/slack_log_device/formatter.rb +15 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abd06c80c27bf0d22d5e646a6998a0fdba732665296bb13d79872ae67529d5b2
|
4
|
+
data.tar.gz: 826eb4eafe925c5b7411caa868cb2ec837bf22f78e0e9db763c2e70ed55288f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd156b4340ee81c5067b00d083d8838652d452818b52240ee5ca5ea88c02ac98aa1b7ff0992e2c42b331a27de080c2c352ddd61a96125fc598e9ca97624dd17a
|
7
|
+
data.tar.gz: 36fa2812286ef682b815fbb9c8d43cd8acdfcf0fdfb132d954eac2c5a4b7a8a45845c7363ab26228e2407ae11ab200cbe486cc00cd9360c65ae137320ceb6485
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.1.
|
1
|
+
5.1.4
|
@@ -10,7 +10,6 @@ class SlackLogDevice
|
|
10
10
|
'FATAL' => ':fire:',
|
11
11
|
'UNKNOWN' => ':interrobang:',
|
12
12
|
}.freeze
|
13
|
-
ENCODING = 'UTF-8'
|
14
13
|
MAX_MESSAGE_LENGTH = 4000
|
15
14
|
|
16
15
|
attr_reader :extra_metadata, :max_backtrace_lines
|
@@ -30,7 +29,7 @@ class SlackLogDevice
|
|
30
29
|
|
31
30
|
def call(severity, datetime, progname, message)
|
32
31
|
text = "*`#{severity}`*"
|
33
|
-
text << " (*#{progname
|
32
|
+
text << " (*#{to_utf8(progname)}*)" if progname.present?
|
34
33
|
text << ':'
|
35
34
|
if message.is_a?(Exception)
|
36
35
|
exception = message
|
@@ -90,26 +89,27 @@ class SlackLogDevice
|
|
90
89
|
|
91
90
|
def append_exception_backtrace(text, exception)
|
92
91
|
backtrace = format_backtrace(exception, MAX_MESSAGE_LENGTH - text.size - 2)
|
93
|
-
backtrace.present? ? "#{text}\n\n#{backtrace}" : text
|
92
|
+
backtrace.present? ? "#{to_utf8(text)}\n\n#{backtrace}" : text
|
94
93
|
end
|
95
94
|
|
96
95
|
def append_exception_cause(text, exception)
|
97
96
|
cause = exception.cause
|
97
|
+
text = to_utf8(text)
|
98
98
|
return text if cause.nil?
|
99
99
|
message = "\n\nCaused by `#{cause.class}`"
|
100
100
|
return text if (text + message).size > MAX_MESSAGE_LENGTH
|
101
|
-
text = truncate("#{text}#{message}: #{cause.message
|
101
|
+
text = truncate("#{text}#{message}: #{to_utf8(cause.message)}")
|
102
102
|
text = append_exception_backtrace(text, cause)
|
103
103
|
append_exception_cause(text, cause)
|
104
104
|
end
|
105
105
|
|
106
106
|
def append_metadata(text, message)
|
107
107
|
metadata = format_metadata(message, MAX_MESSAGE_LENGTH - text.size - 2)
|
108
|
-
metadata.present? ? "#{text}\n\n#{metadata}" : text
|
108
|
+
metadata.present? ? "#{to_utf8(text)}\n\n#{metadata}" : text
|
109
109
|
end
|
110
110
|
|
111
111
|
def convert_message(message)
|
112
|
-
@message_converter.call(message.to_s.strip).to_s.strip
|
112
|
+
to_utf8(@message_converter.call(to_utf8(message.to_s.strip)).to_s.strip)
|
113
113
|
end
|
114
114
|
|
115
115
|
def default_metadata(request)
|
@@ -128,14 +128,14 @@ class SlackLogDevice
|
|
128
128
|
})
|
129
129
|
metadata.keys.each do |key|
|
130
130
|
value = metadata[key]
|
131
|
-
metadata[key] = "`#{value.to_s.strip}`" if value.present?
|
131
|
+
metadata[key] = "`#{to_utf8(value.to_s.strip)}`" if value.present?
|
132
132
|
end
|
133
133
|
metadata
|
134
134
|
end
|
135
135
|
|
136
136
|
def format_backtrace(exception, size_available)
|
137
137
|
return nil if max_backtrace_lines == 0 || size_available < 7
|
138
|
-
backtrace = (exception.backtrace || []).select(&:present?).compact.map { |line| line
|
138
|
+
backtrace = (exception.backtrace || []).select(&:present?).compact.map { |line| to_utf8(line) }
|
139
139
|
return nil if backtrace.empty?
|
140
140
|
if max_backtrace_lines < 0
|
141
141
|
text = backtrace.join("\n")
|
@@ -154,7 +154,7 @@ class SlackLogDevice
|
|
154
154
|
options[:request] = request if request.present?
|
155
155
|
text = default_metadata(request).merge(extra_metadata).map do |name, value|
|
156
156
|
value = value.call(options) if value.respond_to?(:call)
|
157
|
-
value.present? ? "• *#{name
|
157
|
+
value.present? ? "• *#{to_utf8(name).strip}*: #{to_utf8(value).strip}" : nil
|
158
158
|
end.compact.join("\n")
|
159
159
|
return nil if text.blank?
|
160
160
|
truncate(text, size_available)
|
@@ -170,7 +170,12 @@ class SlackLogDevice
|
|
170
170
|
message = message.strip
|
171
171
|
return message if message.size <= max_length
|
172
172
|
return message[0, max_length] if max_length < 3
|
173
|
-
"#{message[0, max_length - 3]}..."
|
173
|
+
to_utf8("#{message[0, max_length - 3]}...")
|
174
|
+
end
|
175
|
+
|
176
|
+
def to_utf8(text)
|
177
|
+
return text if text.nil? || text.encoding == Encoding::UTF_8
|
178
|
+
text.encode(Encoding::UTF_8) rescue text.dup.force_encoding(Encoding::UTF_8)
|
174
179
|
end
|
175
180
|
|
176
181
|
end
|