lita-log 0.1.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 +7 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +36 -0
- data/Rakefile +8 -0
- data/lib/lita-log.rb +12 -0
- data/lib/lita/handlers/log.rb +30 -0
- data/lita-log.gemspec +27 -0
- data/locales/en.yml +10 -0
- data/spec/lita/handlers/log_spec.rb +43 -0
- data/spec/spec_helper.rb +14 -0
- data/templates/.gitkeep +0 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aefe79b6d9c34c113510fa54055503666b92e250
|
4
|
+
data.tar.gz: 8fe1a8717d17c892ec19d3bd2b6afda0062da4ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58190bfe29365aaf331fcfec401edd84bd911f903034731cb68391d65e4fa9d431a7c3cd5d8cb002d714e2f8edd467878886516ae7d17af8d981c054adcb7339
|
7
|
+
data.tar.gz: 596939074ea5c4a9670e397ad7c721a1bd758f4d61ab8c12eb1a0843bcbf5a2fb6055ed37f31254c9dc41dc203f30a636fbe97088cb0b020b4dc1a6dfe859be0
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 Tristan Chong
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# lita-log
|
2
|
+
|
3
|
+
[](https://travis-ci.org/tristaneuan/lita-log)
|
4
|
+
[](https://coveralls.io/r/tristaneuan/lita-log)
|
5
|
+
|
6
|
+
**lita-log** is a handler for [Lita](https://github.com/litaio/lita) that logs arbitrary messages to the bot's Logger object.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add lita-log to your Lita instance's Gemfile:
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
gem "lita-log"
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
In order to record a message in Lita's log, a user must be a member of the `:log_admins` [authorization group](http://docs.lita.io/getting-started/usage/#authorization-groups). Valid log levels are: UNKNOWN, FATAL, ERROR, WARN, INFO, DEBUG
|
19
|
+
|
20
|
+
```
|
21
|
+
<me> lita: log info Hello world!
|
22
|
+
<lita> Successfully logged 'Hello world!' with level INFO
|
23
|
+
<me> lita: log fatal This is a test. This is a test of the incident alerting system. This is only a test.
|
24
|
+
<lita> Successfully logged 'This is a test. This is a test of the incident alerting system. This is only a test.' with level FATAL
|
25
|
+
```
|
26
|
+
|
27
|
+
The resulting log entries will look like this:
|
28
|
+
|
29
|
+
```
|
30
|
+
[2015-12-15 19:45:36 UTC] INFO: Hello world!
|
31
|
+
[2015-12-15 19:45:44 UTC] FATAL: This is a test. This is a test of the incident alerting system. This is only a test.
|
32
|
+
```
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
data/lib/lita-log.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'lita'
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join('..', '..', 'locales', '*.yml'), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require 'lita/handlers/log'
|
8
|
+
|
9
|
+
Lita::Handlers::Log.template_root File.expand_path(
|
10
|
+
File.join('..', '..', 'templates'),
|
11
|
+
__FILE__
|
12
|
+
)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Lita
|
2
|
+
# What about us loggers?
|
3
|
+
module Handlers
|
4
|
+
# Hard-workin' men who like to stand up after they've taken a poo and then
|
5
|
+
# turn around and cut their poo in half with their urine?
|
6
|
+
class Log < Handler
|
7
|
+
LEVELS = %w(unknown fatal error warn info debug)
|
8
|
+
|
9
|
+
route(
|
10
|
+
/^log\s+(?<level>\w+)\s+(?<message>.*)/i,
|
11
|
+
:log_message,
|
12
|
+
command: true,
|
13
|
+
restrict_to: :log_admins,
|
14
|
+
help: { t('help.log_key') => t('help.log_value') }
|
15
|
+
)
|
16
|
+
|
17
|
+
def log_message(response)
|
18
|
+
level = response.match_data[:level].downcase
|
19
|
+
message = response.match_data[:message].strip
|
20
|
+
|
21
|
+
return response.reply(t('log.invalid', level: level)) unless LEVELS.include?(level)
|
22
|
+
|
23
|
+
log.send(level.to_sym, message)
|
24
|
+
response.reply(t('log.success', level: level.upcase, message: message))
|
25
|
+
end
|
26
|
+
|
27
|
+
Lita.register_handler(self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lita-log.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'lita-log'
|
3
|
+
spec.version = '0.1.0'
|
4
|
+
spec.authors = ['Tristan Chong']
|
5
|
+
spec.email = ['ong@tristaneuan.ch']
|
6
|
+
spec.description = "A Lita handler that logs arbitrary messages to Lita's Logger object"
|
7
|
+
spec.summary = spec.description
|
8
|
+
spec.homepage = 'https://github.com/tristaneuan/lita-log'
|
9
|
+
spec.license = 'MIT'
|
10
|
+
spec.metadata = { 'lita_plugin_type' => 'handler' }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'lita', '>= 4.6'
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
20
|
+
spec.add_development_dependency 'pry-byebug'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rack-test'
|
23
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
24
|
+
spec.add_development_dependency 'rubocop'
|
25
|
+
spec.add_development_dependency 'simplecov'
|
26
|
+
spec.add_development_dependency 'coveralls'
|
27
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
en:
|
2
|
+
lita:
|
3
|
+
handlers:
|
4
|
+
log:
|
5
|
+
help:
|
6
|
+
log_key: "log LEVEL MESSAGE"
|
7
|
+
log_value: "Log a message to Lita's Logger object. Valid levels: UNKNOWN, FATAL, ERROR, WARN, INFO, DEBUG"
|
8
|
+
log:
|
9
|
+
invalid: "%{level} is not a valid log level. Try: UNKNOWN, FATAL, ERROR, WARN, INFO, DEBUG"
|
10
|
+
success: "Successfully logged '%{message}' with level %{level}"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lita::Handlers::Log, lita_handler: true do
|
4
|
+
let(:alice) { Lita::User.create('U1', name: 'Alice', mention_name: 'alice') }
|
5
|
+
let(:bob) { Lita::User.create('U2', name: 'Bob', mention_name: 'bob') }
|
6
|
+
let(:logger) { double('Logger') }
|
7
|
+
|
8
|
+
before do
|
9
|
+
robot.auth.add_user_to_group!(alice, :log_admins)
|
10
|
+
allow_any_instance_of(described_class).to receive(:log).and_return(logger)
|
11
|
+
end
|
12
|
+
|
13
|
+
it { is_expected.not_to route_command('log info foo bar').to(:log_message) }
|
14
|
+
it { is_expected.not_to route_command('log foo bar baz').to(:log_message) }
|
15
|
+
it { is_expected.to route_command('log info foo bar').with_authorization_for(:log_admins).to(:log_message) }
|
16
|
+
it { is_expected.to route_command('LOG foo bar baz').with_authorization_for(:log_admins).to(:log_message) }
|
17
|
+
|
18
|
+
describe '#log_message' do
|
19
|
+
context 'when the user is authorized' do
|
20
|
+
it 'logs a message with a valid level' do
|
21
|
+
expect(logger).to receive(:info).with('foo bar baz')
|
22
|
+
send_command('log Info foo bar baz', as: alice)
|
23
|
+
expect(replies.count).to eq(1)
|
24
|
+
expect(replies.last).to eq("Successfully logged 'foo bar baz' with level INFO")
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'complains with an invalid level' do
|
28
|
+
expect(logger).not_to receive(:foo)
|
29
|
+
send_command('log foo bar baz', as: alice)
|
30
|
+
expect(replies.count).to eq(1)
|
31
|
+
expect(replies.last).to eq('foo is not a valid log level. Try: UNKNOWN, FATAL, ERROR, WARN, INFO, DEBUG')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when the user is not authorized' do
|
36
|
+
it 'does nothing' do
|
37
|
+
expect(logger).not_to receive(:info)
|
38
|
+
send_command('log info foo bar baz', as: bob)
|
39
|
+
expect(replies.count).to eq(0)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start { add_filter '/spec/' }
|
8
|
+
|
9
|
+
require 'lita-log'
|
10
|
+
require 'lita/rspec'
|
11
|
+
|
12
|
+
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
13
|
+
# was generated with Lita 4, the compatibility mode should be left disabled.
|
14
|
+
Lita.version_3_compatibility_mode = false
|
data/templates/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tristan Chong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: A Lita handler that logs arbitrary messages to Lita's Logger object
|
140
|
+
email:
|
141
|
+
- ong@tristaneuan.ch
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rubocop.yml"
|
148
|
+
- ".travis.yml"
|
149
|
+
- Gemfile
|
150
|
+
- LICENSE
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- lib/lita-log.rb
|
154
|
+
- lib/lita/handlers/log.rb
|
155
|
+
- lita-log.gemspec
|
156
|
+
- locales/en.yml
|
157
|
+
- spec/lita/handlers/log_spec.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- templates/.gitkeep
|
160
|
+
homepage: https://github.com/tristaneuan/lita-log
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata:
|
164
|
+
lita_plugin_type: handler
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.4.5
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: A Lita handler that logs arbitrary messages to Lita's Logger object
|
185
|
+
test_files:
|
186
|
+
- spec/lita/handlers/log_spec.rb
|
187
|
+
- spec/spec_helper.rb
|