slack_webhook_logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +12 -0
- data/.github/workflows/ci.yml +32 -0
- data/.github/workflows/lint.yml +21 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +114 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +16 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/slack_webhook_logger/install_generator.rb +15 -0
- data/lib/generators/templates/slack_webhook_logger.rb +17 -0
- data/lib/slack_webhook_logger.rb +42 -0
- data/lib/slack_webhook_logger/formatter.rb +71 -0
- data/lib/slack_webhook_logger/logger.rb +12 -0
- data/lib/slack_webhook_logger/request_io.rb +20 -0
- data/lib/slack_webhook_logger/version.rb +5 -0
- data/slack_webhook_logger.gemspec +29 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a171da397b47aa75106d933b8569c53c2e4030c8f2e862a5e97619b76930a1c
|
4
|
+
data.tar.gz: d356b7f9f480004281b65b8531520f94de86edef6d25304e0cf4cf4fb2528070
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5604f4ebd14b80aaa29aa4ac5189c706fa0643ea4d0e7f1fc901bf5a3463ed8439089022b4d3304635901b7ddf1b412043ec32bd179d7850e2724d883174d958
|
7
|
+
data.tar.gz: 4b59ab65a5ddef012752238629a8f303096d99ad2f6b0a96210fd524d0b4907ae8fbde86528af5de299c94a16084d259fc6db1bb4bf582e71fe044dd79f9b2d4
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: gjtorikian
|
4
|
+
patreon: gjtorikian
|
5
|
+
open_collective: garen-torikian
|
6
|
+
#ko_fi: # Replace with a single Ko-fi username
|
7
|
+
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
#liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: gjtorikian
|
11
|
+
#otechie: # Replace with a single Otechie username
|
12
|
+
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [opened, synchronize, reopened]
|
6
|
+
push:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
fail-fast: false
|
16
|
+
matrix:
|
17
|
+
ruby-version: [2.7.2, 2.6.6, 2.5.8]
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby-version }}
|
26
|
+
bundler-cache: true
|
27
|
+
|
28
|
+
- name: Install dependencies
|
29
|
+
run: bundle install
|
30
|
+
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rake
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Linting
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [opened, synchronize, reopened]
|
6
|
+
push:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.7
|
18
|
+
bundler-cache: true
|
19
|
+
- run: bundle install
|
20
|
+
- name: Rubocop
|
21
|
+
run: bundle exec rake rubocop
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at gjtorikian@users.noreply.github.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in slack-webhooklogger.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'awesome_print', '~> 1.8'
|
9
|
+
gem 'minitest', '~> 5.0'
|
10
|
+
gem 'rake', '~> 12.0'
|
11
|
+
gem 'rubocop', '~> 1.6'
|
12
|
+
gem 'rubocop-performance', '~> 1.9'
|
13
|
+
gem 'rubocop-standard', '~> 5.1'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slack_webhook_logger (0.1.0)
|
5
|
+
activesupport (>= 5.0, < 7.0)
|
6
|
+
railties (>= 5.0, < 7.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (5.2.4.4)
|
12
|
+
actionview (= 5.2.4.4)
|
13
|
+
activesupport (= 5.2.4.4)
|
14
|
+
rack (~> 2.0, >= 2.0.8)
|
15
|
+
rack-test (>= 0.6.3)
|
16
|
+
rails-dom-testing (~> 2.0)
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
18
|
+
actionview (5.2.4.4)
|
19
|
+
activesupport (= 5.2.4.4)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
24
|
+
activesupport (5.2.4.4)
|
25
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
|
+
i18n (>= 0.7, < 2)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
tzinfo (~> 1.1)
|
29
|
+
ast (2.4.1)
|
30
|
+
awesome_print (1.8.0)
|
31
|
+
builder (3.2.4)
|
32
|
+
concurrent-ruby (1.1.7)
|
33
|
+
crass (1.0.6)
|
34
|
+
erubi (1.10.0)
|
35
|
+
i18n (1.8.5)
|
36
|
+
concurrent-ruby (~> 1.0)
|
37
|
+
loofah (2.8.0)
|
38
|
+
crass (~> 1.0.2)
|
39
|
+
nokogiri (>= 1.5.9)
|
40
|
+
method_source (1.0.0)
|
41
|
+
mini_portile2 (2.4.0)
|
42
|
+
minitest (5.14.2)
|
43
|
+
nokogiri (1.10.10)
|
44
|
+
mini_portile2 (~> 2.4.0)
|
45
|
+
parallel (1.20.1)
|
46
|
+
parser (2.7.2.0)
|
47
|
+
ast (~> 2.4.1)
|
48
|
+
rack (2.2.3)
|
49
|
+
rack-test (1.1.0)
|
50
|
+
rack (>= 1.0, < 3)
|
51
|
+
rails-dom-testing (2.0.3)
|
52
|
+
activesupport (>= 4.2.0)
|
53
|
+
nokogiri (>= 1.6)
|
54
|
+
rails-html-sanitizer (1.3.0)
|
55
|
+
loofah (~> 2.3)
|
56
|
+
railties (5.2.4.4)
|
57
|
+
actionpack (= 5.2.4.4)
|
58
|
+
activesupport (= 5.2.4.4)
|
59
|
+
method_source
|
60
|
+
rake (>= 0.8.7)
|
61
|
+
thor (>= 0.19.0, < 2.0)
|
62
|
+
rainbow (3.0.0)
|
63
|
+
rake (12.3.3)
|
64
|
+
regexp_parser (2.0.0)
|
65
|
+
rexml (3.2.4)
|
66
|
+
rubocop (1.6.1)
|
67
|
+
parallel (~> 1.10)
|
68
|
+
parser (>= 2.7.1.5)
|
69
|
+
rainbow (>= 2.2.2, < 4.0)
|
70
|
+
regexp_parser (>= 1.8, < 3.0)
|
71
|
+
rexml
|
72
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
73
|
+
ruby-progressbar (~> 1.7)
|
74
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
75
|
+
rubocop-ast (1.3.0)
|
76
|
+
parser (>= 2.7.1.5)
|
77
|
+
rubocop-minitest (0.10.1)
|
78
|
+
rubocop (>= 0.87)
|
79
|
+
rubocop-performance (1.9.1)
|
80
|
+
rubocop (>= 0.90.0, < 2.0)
|
81
|
+
rubocop-ast (>= 0.4.0)
|
82
|
+
rubocop-rails (2.9.0)
|
83
|
+
activesupport (>= 4.2.0)
|
84
|
+
rack (>= 1.1)
|
85
|
+
rubocop (>= 0.90.0, < 2.0)
|
86
|
+
rubocop-rake (0.5.1)
|
87
|
+
rubocop
|
88
|
+
rubocop-standard (5.1.2)
|
89
|
+
rubocop
|
90
|
+
rubocop-minitest
|
91
|
+
rubocop-performance
|
92
|
+
rubocop-rails
|
93
|
+
rubocop-rake
|
94
|
+
ruby-progressbar (1.10.1)
|
95
|
+
thor (1.0.1)
|
96
|
+
thread_safe (0.3.6)
|
97
|
+
tzinfo (1.2.8)
|
98
|
+
thread_safe (~> 0.1)
|
99
|
+
unicode-display_width (1.7.0)
|
100
|
+
|
101
|
+
PLATFORMS
|
102
|
+
ruby
|
103
|
+
|
104
|
+
DEPENDENCIES
|
105
|
+
awesome_print (~> 1.8)
|
106
|
+
minitest (~> 5.0)
|
107
|
+
rake (~> 12.0)
|
108
|
+
rubocop (~> 1.6)
|
109
|
+
rubocop-performance (~> 1.9)
|
110
|
+
rubocop-standard (~> 5.1)
|
111
|
+
slack_webhook_logger!
|
112
|
+
|
113
|
+
BUNDLED WITH
|
114
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Garen J. Torikian
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Slack::WebhookLogger
|
2
|
+
|
3
|
+
A simple Slack logger using ActiveSupport broadcast and a slim HTTPS call.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'slack-webhooklogger'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install slack-webhooklogger
|
23
|
+
```
|
24
|
+
|
25
|
+
Then, run the install generator:
|
26
|
+
|
27
|
+
```
|
28
|
+
$ rails generate slack-webhooklogger:install
|
29
|
+
```
|
30
|
+
|
31
|
+
Provide the webhook URL in the config, and finally, extend the logger:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
config.after_initialize do
|
35
|
+
Rails.logger.extend ActiveSupport::Logger.broadcast(SlackWebhookLogger.logger)
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Configuration
|
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 infomation on that.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :test
|
13
|
+
|
14
|
+
require 'rubocop/rake_task'
|
15
|
+
|
16
|
+
RuboCop::RakeTask.new(:rubocop)
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "slack/webhook_logger"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module SlackWebhookLogger
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("..#{File::SEPARATOR}..#{File::SEPARATOR}templates", __FILE__)
|
8
|
+
|
9
|
+
desc 'Create a Slack::WebhookLogger initializer'
|
10
|
+
|
11
|
+
def copy_initializer
|
12
|
+
template 'slack_webhook_logger.rb', 'config/initializers/slack_webhook_logger.rb'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SlackWebhookLogger.setup do |config|
|
4
|
+
# The URL where messages will be sent. This is required.
|
5
|
+
config.webhook_url = 'https://hooks.slack.com/services/xxx/yyy/zzz'
|
6
|
+
|
7
|
+
# The minimum error level to see in Slack. This is optional; the default is :WARN.
|
8
|
+
#
|
9
|
+
# All log levels are supported, but don't rely on anything less then :WARN
|
10
|
+
# since Slack only allows one message per minute.
|
11
|
+
# config.level = :WARN
|
12
|
+
|
13
|
+
# You can provide a custom log formatter if you want to. This is optional.
|
14
|
+
# The formatter must construct a JSON blob that adheres to Slack's expected
|
15
|
+
# POST payload for `chat.postMessage`: https://api.slack.com/methods/chat.postMessage
|
16
|
+
# config.formatter = SomeOtherFormatter.new
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/logger'
|
4
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
5
|
+
|
6
|
+
require 'net/http'
|
7
|
+
require 'net/https'
|
8
|
+
require 'uri'
|
9
|
+
|
10
|
+
require 'slack_webhook_logger/logger'
|
11
|
+
require 'slack_webhook_logger/formatter'
|
12
|
+
require 'slack_webhook_logger/request_io'
|
13
|
+
|
14
|
+
module SlackWebhookLogger
|
15
|
+
# Can be modified in Rails app
|
16
|
+
mattr_accessor :webhook_url
|
17
|
+
mattr_accessor :level
|
18
|
+
mattr_accessor :formatter
|
19
|
+
|
20
|
+
# Used internally
|
21
|
+
mattr_reader :webhook_uri
|
22
|
+
mattr_reader :logger
|
23
|
+
mattr_reader :https
|
24
|
+
|
25
|
+
# rubocop:disable Style/ClassVars
|
26
|
+
def self.setup
|
27
|
+
@@logger = SlackWebhookLogger::Logger.new(SlackWebhookLogger::RequestIO)
|
28
|
+
|
29
|
+
yield self
|
30
|
+
|
31
|
+
@@logger.formatter = @@formatter || SlackWebhookLogger::Formatter.new
|
32
|
+
@@logger.level = @@level || :warn
|
33
|
+
|
34
|
+
@@webhook_uri = URI.parse(@@webhook_url)
|
35
|
+
https = Net::HTTP.new(@@webhook_uri.host, @@webhook_uri.port)
|
36
|
+
https.use_ssl = true
|
37
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
38
|
+
|
39
|
+
@@https = https
|
40
|
+
end
|
41
|
+
# rubocop:enable Style/ClassVars
|
42
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlackWebhookLogger
|
4
|
+
class Formatter < ::Logger::Formatter
|
5
|
+
attr_writer :format
|
6
|
+
|
7
|
+
def format
|
8
|
+
@format ||= proc { |severity, time, _progname, msg|
|
9
|
+
heading = case severity
|
10
|
+
when 'FATAL'
|
11
|
+
"📛 *#{severity}*"
|
12
|
+
when 'ERROR'
|
13
|
+
"🛑 *#{severity}*"
|
14
|
+
when 'WARN'
|
15
|
+
"⚠️ *#{severity}*"
|
16
|
+
when 'INFO'
|
17
|
+
"ℹ️ *#{severity}*"
|
18
|
+
when 'DEBUG'
|
19
|
+
"🐛 *#{severity}*"
|
20
|
+
else
|
21
|
+
'🪵 *Logger*'
|
22
|
+
end
|
23
|
+
|
24
|
+
title = "#{heading} (#{time})"
|
25
|
+
|
26
|
+
text = <<~MSG
|
27
|
+
#{msg2str(msg)}
|
28
|
+
MSG
|
29
|
+
|
30
|
+
{
|
31
|
+
text: [title, text].join("\n").to_s,
|
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
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def call(severity, time, progname, msg)
|
56
|
+
format.call(severity, time, progname, msg)
|
57
|
+
end
|
58
|
+
|
59
|
+
private def msg2str(msg)
|
60
|
+
case msg
|
61
|
+
when ::String
|
62
|
+
msg
|
63
|
+
when ::Exception
|
64
|
+
"#{msg.message} (#{msg.class})\n" <<
|
65
|
+
(msg.backtrace || []).join("\n")
|
66
|
+
else
|
67
|
+
msg.inspect
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
|
5
|
+
module SlackWebhookLogger
|
6
|
+
class Logger < ::ActiveSupport::Logger
|
7
|
+
class << self
|
8
|
+
delegate :fatal, :error, :warn, :info, :debug, \
|
9
|
+
:add, :log, to: :instance
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module SlackWebhookLogger
|
7
|
+
class RequestIO
|
8
|
+
def self.close
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.write(payload)
|
13
|
+
return if payload.blank?
|
14
|
+
|
15
|
+
req = Net::HTTP::Post.new(SlackWebhookLogger.webhook_uri.path)
|
16
|
+
req.set_form_data(payload: payload.to_json)
|
17
|
+
SlackWebhookLogger.https.request(req)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/slack_webhook_logger/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'slack_webhook_logger'
|
7
|
+
spec.version = SlackWebhookLogger::VERSION
|
8
|
+
spec.authors = ['Garen J. Torikian']
|
9
|
+
spec.email = ['gjtorikian@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A slim wrapper for posting to Rails logs to Slack'
|
12
|
+
spec.homepage = 'https://github.com/gjtorikian/slack_webhook_logger'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_dependency 'activesupport', '>= 5.0', '< 7.0'
|
28
|
+
spec.add_dependency 'railties', '>= 5.0', '< 7.0' # for the generators
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack_webhook_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Garen J. Torikian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: railties
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '5.0'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '7.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '5.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '7.0'
|
53
|
+
description:
|
54
|
+
email:
|
55
|
+
- gjtorikian@gmail.com
|
56
|
+
executables: []
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- ".github/FUNDING.yml"
|
61
|
+
- ".github/workflows/ci.yml"
|
62
|
+
- ".github/workflows/lint.yml"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/generators/slack_webhook_logger/install_generator.rb
|
74
|
+
- lib/generators/templates/slack_webhook_logger.rb
|
75
|
+
- lib/slack_webhook_logger.rb
|
76
|
+
- lib/slack_webhook_logger/formatter.rb
|
77
|
+
- lib/slack_webhook_logger/logger.rb
|
78
|
+
- lib/slack_webhook_logger/request_io.rb
|
79
|
+
- lib/slack_webhook_logger/version.rb
|
80
|
+
- slack_webhook_logger.gemspec
|
81
|
+
homepage: https://github.com/gjtorikian/slack_webhook_logger
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata:
|
85
|
+
homepage_uri: https://github.com/gjtorikian/slack_webhook_logger
|
86
|
+
source_code_uri: https://github.com/gjtorikian/slack_webhook_logger
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2.5'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubygems_version: 3.1.4
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: A slim wrapper for posting to Rails logs to Slack
|
106
|
+
test_files: []
|