slack_webhook_logger 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -5
- data/.rubocop.yml +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +65 -53
- data/README.md +1 -1
- data/lib/generators/templates/slack_webhook_logger.rb +4 -0
- data/lib/slack_webhook_logger/formatter.rb +29 -25
- data/lib/slack_webhook_logger/request_io.rb +7 -3
- data/lib/slack_webhook_logger/version.rb +1 -1
- data/lib/slack_webhook_logger.rb +3 -0
- data/slack_webhook_logger.gemspec +4 -1
- metadata +5 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ecc18a809cc554fe9a8f5f071a55967fa16fbda0ab506ea6e334c45f4219336
|
|
4
|
+
data.tar.gz: ea0a4ecfa30ef3049ceb8edfc2dac750f3d5521a263e82a79fc18e65c7e7b496
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a2904814cc6e2e50431ef9eae41e33032c507d27d0a7e3ccea4e348ba19baafc60b7592abe7fb8e4217d49609a14954874579c958e39c5453f975d7e09175b73
|
|
7
|
+
data.tar.gz: c0fa12a9dade9ba87ab019fed19fff3f1cbd016d7e75a672c5f2da765dc53680929617f7a34408b681d054de0b65205bf0437789e0b48a80640378bcf8f4ee3c
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
name: Ruby CI
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
types: [opened, synchronize, reopened]
|
|
6
4
|
push:
|
|
7
|
-
branches:
|
|
8
|
-
- main
|
|
9
5
|
|
|
10
6
|
jobs:
|
|
11
7
|
test:
|
|
@@ -14,7 +10,7 @@ jobs:
|
|
|
14
10
|
strategy:
|
|
15
11
|
fail-fast: false
|
|
16
12
|
matrix:
|
|
17
|
-
ruby-version: [
|
|
13
|
+
ruby-version: [3.0.2]
|
|
18
14
|
|
|
19
15
|
steps:
|
|
20
16
|
- uses: actions/checkout@v2
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,102 +1,113 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
slack_webhook_logger (0.
|
|
4
|
+
slack_webhook_logger (0.3.0)
|
|
5
5
|
activesupport (>= 5.0, < 7.0)
|
|
6
6
|
railties (>= 5.0, < 7.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actionpack (
|
|
12
|
-
actionview (=
|
|
13
|
-
activesupport (=
|
|
14
|
-
rack (~> 2.0, >= 2.0.
|
|
11
|
+
actionpack (6.1.4.4)
|
|
12
|
+
actionview (= 6.1.4.4)
|
|
13
|
+
activesupport (= 6.1.4.4)
|
|
14
|
+
rack (~> 2.0, >= 2.0.9)
|
|
15
15
|
rack-test (>= 0.6.3)
|
|
16
16
|
rails-dom-testing (~> 2.0)
|
|
17
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
|
18
|
-
actionview (
|
|
19
|
-
activesupport (=
|
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
18
|
+
actionview (6.1.4.4)
|
|
19
|
+
activesupport (= 6.1.4.4)
|
|
20
20
|
builder (~> 3.1)
|
|
21
21
|
erubi (~> 1.4)
|
|
22
22
|
rails-dom-testing (~> 2.0)
|
|
23
|
-
rails-html-sanitizer (~> 1.
|
|
24
|
-
activesupport (
|
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
24
|
+
activesupport (6.1.4.4)
|
|
25
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
26
|
-
i18n (>=
|
|
27
|
-
minitest (
|
|
28
|
-
tzinfo (~>
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
i18n (>= 1.6, < 2)
|
|
27
|
+
minitest (>= 5.1)
|
|
28
|
+
tzinfo (~> 2.0)
|
|
29
|
+
zeitwerk (~> 2.3)
|
|
30
|
+
addressable (2.8.0)
|
|
31
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
32
|
+
ast (2.4.2)
|
|
33
|
+
awesome_print (1.9.2)
|
|
31
34
|
builder (3.2.4)
|
|
32
|
-
concurrent-ruby (1.1.
|
|
35
|
+
concurrent-ruby (1.1.9)
|
|
36
|
+
crack (0.4.5)
|
|
37
|
+
rexml
|
|
33
38
|
crass (1.0.6)
|
|
34
39
|
erubi (1.10.0)
|
|
35
|
-
|
|
40
|
+
hashdiff (1.0.1)
|
|
41
|
+
i18n (1.8.11)
|
|
36
42
|
concurrent-ruby (~> 1.0)
|
|
37
|
-
loofah (2.
|
|
43
|
+
loofah (2.13.0)
|
|
38
44
|
crass (~> 1.0.2)
|
|
39
45
|
nokogiri (>= 1.5.9)
|
|
40
46
|
method_source (1.0.0)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
parser (2.7.2.0)
|
|
47
|
+
minitest (5.15.0)
|
|
48
|
+
nokogiri (1.12.5-arm64-darwin)
|
|
49
|
+
racc (~> 1.4)
|
|
50
|
+
parallel (1.21.0)
|
|
51
|
+
parser (3.0.3.2)
|
|
47
52
|
ast (~> 2.4.1)
|
|
53
|
+
public_suffix (4.0.6)
|
|
54
|
+
racc (1.6.0)
|
|
48
55
|
rack (2.2.3)
|
|
49
56
|
rack-test (1.1.0)
|
|
50
57
|
rack (>= 1.0, < 3)
|
|
51
58
|
rails-dom-testing (2.0.3)
|
|
52
59
|
activesupport (>= 4.2.0)
|
|
53
60
|
nokogiri (>= 1.6)
|
|
54
|
-
rails-html-sanitizer (1.
|
|
61
|
+
rails-html-sanitizer (1.4.2)
|
|
55
62
|
loofah (~> 2.3)
|
|
56
|
-
railties (
|
|
57
|
-
actionpack (=
|
|
58
|
-
activesupport (=
|
|
63
|
+
railties (6.1.4.4)
|
|
64
|
+
actionpack (= 6.1.4.4)
|
|
65
|
+
activesupport (= 6.1.4.4)
|
|
59
66
|
method_source
|
|
60
|
-
rake (>= 0.
|
|
61
|
-
thor (
|
|
67
|
+
rake (>= 0.13)
|
|
68
|
+
thor (~> 1.0)
|
|
62
69
|
rainbow (3.0.0)
|
|
63
70
|
rake (12.3.3)
|
|
64
|
-
regexp_parser (2.
|
|
65
|
-
rexml (3.2.
|
|
66
|
-
rubocop (1.
|
|
71
|
+
regexp_parser (2.2.0)
|
|
72
|
+
rexml (3.2.5)
|
|
73
|
+
rubocop (1.23.0)
|
|
67
74
|
parallel (~> 1.10)
|
|
68
|
-
parser (>=
|
|
75
|
+
parser (>= 3.0.0.0)
|
|
69
76
|
rainbow (>= 2.2.2, < 4.0)
|
|
70
77
|
regexp_parser (>= 1.8, < 3.0)
|
|
71
78
|
rexml
|
|
72
|
-
rubocop-ast (>= 1.
|
|
79
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
|
73
80
|
ruby-progressbar (~> 1.7)
|
|
74
|
-
unicode-display_width (>= 1.4.0, <
|
|
75
|
-
rubocop-ast (1.
|
|
76
|
-
parser (>=
|
|
77
|
-
rubocop-minitest (0.
|
|
78
|
-
rubocop (>= 0.
|
|
79
|
-
rubocop-performance (1.
|
|
80
|
-
rubocop (>=
|
|
81
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
82
|
+
rubocop-ast (1.15.0)
|
|
83
|
+
parser (>= 3.0.1.1)
|
|
84
|
+
rubocop-minitest (0.17.0)
|
|
85
|
+
rubocop (>= 0.90, < 2.0)
|
|
86
|
+
rubocop-performance (1.12.0)
|
|
87
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
81
88
|
rubocop-ast (>= 0.4.0)
|
|
82
|
-
rubocop-rails (2.
|
|
89
|
+
rubocop-rails (2.12.4)
|
|
83
90
|
activesupport (>= 4.2.0)
|
|
84
91
|
rack (>= 1.1)
|
|
85
|
-
rubocop (>=
|
|
86
|
-
rubocop-rake (0.
|
|
87
|
-
rubocop
|
|
92
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
93
|
+
rubocop-rake (0.6.0)
|
|
94
|
+
rubocop (~> 1.0)
|
|
88
95
|
rubocop-standard (5.1.2)
|
|
89
96
|
rubocop
|
|
90
97
|
rubocop-minitest
|
|
91
98
|
rubocop-performance
|
|
92
99
|
rubocop-rails
|
|
93
100
|
rubocop-rake
|
|
94
|
-
ruby-progressbar (1.
|
|
95
|
-
thor (1.0
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
ruby-progressbar (1.11.0)
|
|
102
|
+
thor (1.1.0)
|
|
103
|
+
tzinfo (2.0.4)
|
|
104
|
+
concurrent-ruby (~> 1.0)
|
|
105
|
+
unicode-display_width (2.1.0)
|
|
106
|
+
webmock (3.14.0)
|
|
107
|
+
addressable (>= 2.8.0)
|
|
108
|
+
crack (>= 0.3.2)
|
|
109
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
110
|
+
zeitwerk (2.5.1)
|
|
100
111
|
|
|
101
112
|
PLATFORMS
|
|
102
113
|
ruby
|
|
@@ -109,6 +120,7 @@ DEPENDENCIES
|
|
|
109
120
|
rubocop-performance (~> 1.9)
|
|
110
121
|
rubocop-standard (~> 5.1)
|
|
111
122
|
slack_webhook_logger!
|
|
123
|
+
webmock (~> 3.11)
|
|
112
124
|
|
|
113
125
|
BUNDLED WITH
|
|
114
|
-
2.
|
|
126
|
+
2.2.33
|
data/README.md
CHANGED
|
@@ -38,4 +38,4 @@ end
|
|
|
38
38
|
|
|
39
39
|
## Configuration
|
|
40
40
|
|
|
41
|
-
You can change the log level or the format of the logging text if you wish. See the generated slack_webhook_logger.rb file for more
|
|
41
|
+
You can change the log level or the format of the logging text if you wish. See the generated slack_webhook_logger.rb file for more information on that.
|
|
@@ -14,4 +14,8 @@ SlackWebhookLogger.setup do |config|
|
|
|
14
14
|
# The formatter must construct a JSON blob that adheres to Slack's expected
|
|
15
15
|
# POST payload for `chat.postMessage`: https://api.slack.com/methods/chat.postMessage
|
|
16
16
|
# config.formatter = SomeOtherFormatter.new
|
|
17
|
+
|
|
18
|
+
# You can provide an array of regular expressions to ignore certain messages
|
|
19
|
+
# from being sent to Slack. This is optional.
|
|
20
|
+
# config.ignore_patterns = []
|
|
17
21
|
end
|
|
@@ -5,7 +5,7 @@ module SlackWebhookLogger
|
|
|
5
5
|
attr_writer :format
|
|
6
6
|
|
|
7
7
|
def format
|
|
8
|
-
@format ||= proc
|
|
8
|
+
@format ||= proc do |severity, time, _progname, msg|
|
|
9
9
|
heading = case severity
|
|
10
10
|
when 'FATAL'
|
|
11
11
|
"📛 *#{severity}*"
|
|
@@ -21,41 +21,45 @@ module SlackWebhookLogger
|
|
|
21
21
|
'🪵 *Logger*'
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
title = "#{heading} (#{time})"
|
|
24
|
+
title = "#{heading} (#{time}) [#{ENV['RAILS_ENV']}]"
|
|
25
25
|
|
|
26
26
|
text = <<~MSG
|
|
27
27
|
#{msg2str(msg)}
|
|
28
28
|
MSG
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
blocks: [
|
|
33
|
-
{
|
|
34
|
-
type: 'section',
|
|
35
|
-
text: {
|
|
36
|
-
type: 'mrkdwn',
|
|
37
|
-
text: title
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
type: 'divider'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
type: 'section',
|
|
45
|
-
text: {
|
|
46
|
-
"type": 'plain_text',
|
|
47
|
-
"text": text
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
30
|
+
slackify(title, text)
|
|
31
|
+
end
|
|
53
32
|
end
|
|
54
33
|
|
|
55
34
|
def call(severity, time, progname, msg)
|
|
56
35
|
format.call(severity, time, progname, msg)
|
|
57
36
|
end
|
|
58
37
|
|
|
38
|
+
def slackify(title, text)
|
|
39
|
+
{
|
|
40
|
+
text: [title, text].join("\n").to_s,
|
|
41
|
+
blocks: [
|
|
42
|
+
{
|
|
43
|
+
type: 'section',
|
|
44
|
+
text: {
|
|
45
|
+
type: 'mrkdwn',
|
|
46
|
+
text: title
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'divider'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'section',
|
|
54
|
+
text: {
|
|
55
|
+
type: 'plain_text',
|
|
56
|
+
text: text
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
59
63
|
private def msg2str(msg)
|
|
60
64
|
case msg
|
|
61
65
|
when ::String
|
|
@@ -9,11 +9,15 @@ module SlackWebhookLogger
|
|
|
9
9
|
true
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def self.write(
|
|
13
|
-
return if
|
|
12
|
+
def self.write(hash)
|
|
13
|
+
return if hash.blank?
|
|
14
|
+
|
|
15
|
+
return if SlackWebhookLogger.ignore_patterns.any? { |ignore_pattern| hash[:text].match(ignore_pattern) }
|
|
16
|
+
|
|
17
|
+
payload = hash.to_json
|
|
14
18
|
|
|
15
19
|
req = Net::HTTP::Post.new(SlackWebhookLogger.webhook_uri.path)
|
|
16
|
-
req.set_form_data(payload: payload
|
|
20
|
+
req.set_form_data(payload: payload)
|
|
17
21
|
SlackWebhookLogger.https.request(req)
|
|
18
22
|
end
|
|
19
23
|
end
|
data/lib/slack_webhook_logger.rb
CHANGED
|
@@ -16,6 +16,7 @@ module SlackWebhookLogger
|
|
|
16
16
|
mattr_accessor :webhook_url
|
|
17
17
|
mattr_accessor :level
|
|
18
18
|
mattr_accessor :formatter
|
|
19
|
+
mattr_accessor :ignore_patterns
|
|
19
20
|
|
|
20
21
|
# Used internally
|
|
21
22
|
mattr_reader :webhook_uri
|
|
@@ -37,6 +38,8 @@ module SlackWebhookLogger
|
|
|
37
38
|
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
38
39
|
|
|
39
40
|
@@https = https
|
|
41
|
+
|
|
42
|
+
@@ignore_patterns ||= []
|
|
40
43
|
end
|
|
41
44
|
# rubocop:enable Style/ClassVars
|
|
42
45
|
end
|
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.summary = 'A slim wrapper for posting to Rails logs to Slack'
|
|
12
12
|
spec.homepage = 'https://github.com/gjtorikian/slack_webhook_logger'
|
|
13
13
|
spec.license = 'MIT'
|
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new('~>
|
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('~> 3.0')
|
|
15
15
|
|
|
16
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
17
17
|
spec.metadata['source_code_uri'] = spec.homepage
|
|
@@ -26,4 +26,7 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
|
|
27
27
|
spec.add_dependency 'activesupport', '>= 5.0', '< 7.0'
|
|
28
28
|
spec.add_dependency 'railties', '>= 5.0', '< 7.0' # for the generators
|
|
29
|
+
spec.metadata = {
|
|
30
|
+
'rubygems_mfa_required' => 'true'
|
|
31
|
+
}
|
|
29
32
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slack_webhook_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Garen J. Torikian
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-12-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -82,8 +82,7 @@ homepage: https://github.com/gjtorikian/slack_webhook_logger
|
|
|
82
82
|
licenses:
|
|
83
83
|
- MIT
|
|
84
84
|
metadata:
|
|
85
|
-
|
|
86
|
-
source_code_uri: https://github.com/gjtorikian/slack_webhook_logger
|
|
85
|
+
rubygems_mfa_required: 'true'
|
|
87
86
|
post_install_message:
|
|
88
87
|
rdoc_options: []
|
|
89
88
|
require_paths:
|
|
@@ -92,14 +91,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
92
91
|
requirements:
|
|
93
92
|
- - "~>"
|
|
94
93
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: '
|
|
94
|
+
version: '3.0'
|
|
96
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
96
|
requirements:
|
|
98
97
|
- - ">="
|
|
99
98
|
- !ruby/object:Gem::Version
|
|
100
99
|
version: '0'
|
|
101
100
|
requirements: []
|
|
102
|
-
rubygems_version: 3.
|
|
101
|
+
rubygems_version: 3.2.33
|
|
103
102
|
signing_key:
|
|
104
103
|
specification_version: 4
|
|
105
104
|
summary: A slim wrapper for posting to Rails logs to Slack
|