slack_logger 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +41 -0
- data/lib/slack_logger.rb +90 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 492b61aeeeb707f5ddc6fdaab3268f66c077d4e2
|
4
|
+
data.tar.gz: b6078fbb007c8486082321a56c8ec9be21af0b48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72895c87a61315eeff0e71547c30534b49800201f527e401c262c14a460d1e914a86c9a7c00d33555484a7d129353ddbff248021ce2ef91a96ca15b8f7a9c303
|
7
|
+
data.tar.gz: bb0be277679520fd3808535b6ddfa9fdead2e7b61ba202df360725351558008a0f47f7f2370e343f2ff3315762c34fd4552a9afa42d3548461ba2fd0680bb235
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Fernando Tapia Rico
|
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
|
+
# SlackLogger
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/slack_logger`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'slack_logger'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install slack_logger
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slack_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/lib/slack_logger.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "json"
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
class SlackLogger < Logger
|
7
|
+
VERSION = [
|
8
|
+
VERSION_MAJOR = 1,
|
9
|
+
VERSION_MINOR = 0,
|
10
|
+
VERSION_TINY = 0,
|
11
|
+
VERSION_PRE = nil
|
12
|
+
].compact.join(".")
|
13
|
+
|
14
|
+
class Error < RuntimeError; end
|
15
|
+
class DatetimeFormatNotSupported < Error; end
|
16
|
+
class FormatterNotSupported < Error; end
|
17
|
+
class UndefinedSlackHookUrl < Error; end
|
18
|
+
class UndefinedSlackChannel < Error; end
|
19
|
+
|
20
|
+
attr_accessor :slack_channel
|
21
|
+
attr_accessor :slack_hook_url
|
22
|
+
attr_accessor :slack_icon_emoji
|
23
|
+
attr_accessor :slack_icon_url
|
24
|
+
attr_accessor :slack_username
|
25
|
+
|
26
|
+
def initialize(options = {})
|
27
|
+
@slack_hook_url = options.fetch(:slack_hook_url) { nil }
|
28
|
+
@slack_channel = options.fetch(:slack_channel) { nil }
|
29
|
+
@slack_username = options.fetch(:slack_username) { "Logger" }
|
30
|
+
@slack_icon_url = options.fetch(:slack_icon_url) { nil }
|
31
|
+
@slack_icon_emoji = options.fetch(:slack_icon_emoji) { nil }
|
32
|
+
@level = DEBUG
|
33
|
+
@logdev = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def formatter=(formatter)
|
37
|
+
raise(FormatterNotSupported)
|
38
|
+
end
|
39
|
+
|
40
|
+
def formatter
|
41
|
+
raise(FormatterNotSupported)
|
42
|
+
end
|
43
|
+
|
44
|
+
def datetime_format=(datetime_format)
|
45
|
+
raise(DatetimeFormatNotSupported)
|
46
|
+
end
|
47
|
+
|
48
|
+
def datetime_format
|
49
|
+
raise(DatetimeFormatNotSupported)
|
50
|
+
end
|
51
|
+
|
52
|
+
def <<(message)
|
53
|
+
error(message)
|
54
|
+
end
|
55
|
+
|
56
|
+
def add(severity, message = nil, progname = nil, &block)
|
57
|
+
raise(UndefinedSlackHookUrl) unless @slack_hook_url
|
58
|
+
raise(UndefinedSlackChannel) unless @slack_channel
|
59
|
+
|
60
|
+
severity ||= FATAL
|
61
|
+
message ||= block_given? ? yield : progname
|
62
|
+
|
63
|
+
return true if severity < @level
|
64
|
+
|
65
|
+
uri = URI.parse(slack_hook_url)
|
66
|
+
payload = slack_payload(severity, message).to_json
|
67
|
+
|
68
|
+
Net::HTTP.post_form(uri, payload: payload)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def slack_payload(severity, message)
|
74
|
+
{
|
75
|
+
channel: slack_channel,
|
76
|
+
username: slack_username,
|
77
|
+
icon_url: slack_icon_url,
|
78
|
+
icon_emoji: slack_icon_emoji,
|
79
|
+
text: "",
|
80
|
+
attachments: [{
|
81
|
+
color: slack_color(severity),
|
82
|
+
text: message
|
83
|
+
}]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def slack_color(severity)
|
88
|
+
["#e3e4e6", "#55acee", "warning", "danger"][severity] || "danger"
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fernando Tapia Rico
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.8'
|
55
|
+
description: Send messages to Slack using the standard Logger interface
|
56
|
+
email:
|
57
|
+
- fertapric@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- lib/slack_logger.rb
|
65
|
+
homepage: https://github.com/fertapric/slack_logger
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.4.5
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Send messages to Slack using Logger interface
|
89
|
+
test_files: []
|