telegram-loggerbot-ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -47
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +2 -0
- data/{LICENSE → LICENSE.txt} +6 -6
- data/README.md +35 -18
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/telegram/{logger_bot.rb → loggerbot.rb} +4 -4
- data/lib/telegram/{logger_bot → loggerbot}/configuration.rb +1 -1
- data/lib/telegram/{logger_bot → loggerbot}/logger.rb +29 -12
- data/lib/telegram/loggerbot/loggerbot.rb +7 -0
- data/lib/telegram/{logger_bot → loggerbot}/version.rb +1 -1
- data/telegram-loggerbot-ruby.gemspec +19 -12
- metadata +46 -12
- data/lib/telegram/logger_bot/logger_bot.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28c42ae72e9892aca97bb0685c76f5ad38b5470d
|
4
|
+
data.tar.gz: b33a12d6e1e759432438a940ab4c08e710f68dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70e4315d2198a49daed350087eaabe0be4e8dd4f3e2c7e867d0289942d9e9ca62728b4b211bab3aa96dcebc6e4331d4de0da7a7a9687d50c5d047f02c4757b1b
|
7
|
+
data.tar.gz: b554b092dd8ea101f78a564a1e11cda2b43edfc806b12af67dec0fae9610c3207ee1a00190eb9b3962333efa9d699aac79e9d4675580bd6c91f1bef4da93173a
|
data/.gitignore
CHANGED
@@ -1,51 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
4
5
|
/coverage/
|
5
|
-
/
|
6
|
+
/doc/
|
6
7
|
/pkg/
|
7
8
|
/spec/reports/
|
8
|
-
/spec/examples.txt
|
9
|
-
/test/tmp/
|
10
|
-
/test/version_tmp/
|
11
9
|
/tmp/
|
12
|
-
.idea
|
13
|
-
|
14
|
-
# Used by dotenv library to load environment variables.
|
15
|
-
# .env
|
16
|
-
|
17
|
-
## Specific to RubyMotion:
|
18
|
-
.dat*
|
19
|
-
.repl_history
|
20
|
-
build/
|
21
|
-
*.bridgesupport
|
22
|
-
build-iPhoneOS/
|
23
|
-
build-iPhoneSimulator/
|
24
|
-
|
25
|
-
## Specific to RubyMotion (use of CocoaPods):
|
26
|
-
#
|
27
|
-
# We recommend against adding the Pods directory to your .gitignore. However
|
28
|
-
# you should judge for yourself, the pros and cons are mentioned at:
|
29
|
-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
30
|
-
#
|
31
|
-
# vendor/Pods/
|
32
|
-
|
33
|
-
## Documentation cache and generated files:
|
34
|
-
/.yardoc/
|
35
|
-
/_yardoc/
|
36
|
-
/doc/
|
37
|
-
/rdoc/
|
38
|
-
|
39
|
-
## Environment normalization:
|
40
|
-
/.bundle/
|
41
|
-
/vendor/bundle
|
42
|
-
/lib/bundler/man/
|
43
|
-
|
44
|
-
# for a library or gem, you might want to ignore these files since the code is
|
45
|
-
# intended to run in multiple environments; otherwise, check them in:
|
46
|
-
# Gemfile.lock
|
47
|
-
# .ruby-version
|
48
|
-
# .ruby-gemset
|
49
|
-
|
50
|
-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
-
.rvmrc
|
10
|
+
.idea
|
11
|
+
.ruby-*
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
MIT License
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2017
|
3
|
+
Copyright (c) 2017 Anton Osenenko
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
10
10
|
furnished to do so, subject to the following conditions:
|
11
11
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
copies or substantial portions of the Software.
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
14
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
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
|
-
SOFTWARE.
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -4,25 +4,21 @@
|
|
4
4
|
|
5
5
|
Allows to send event logs directly to the telegram chat
|
6
6
|
|
7
|
-
##Installation
|
7
|
+
## Installation
|
8
8
|
|
9
|
-
Add
|
9
|
+
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem '
|
12
|
+
gem 'loggerbot'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
|
18
|
-
$ bundle
|
19
|
-
```
|
17
|
+
$ bundle
|
20
18
|
|
21
|
-
Or install it
|
19
|
+
Or install it yourself as:
|
22
20
|
|
23
|
-
|
24
|
-
gem install telegram-loggerbot-ruby
|
25
|
-
```
|
21
|
+
$ gem install telegram-loggerbot-ruby
|
26
22
|
|
27
23
|
##Usage
|
28
24
|
|
@@ -33,29 +29,40 @@ gem install telegram-loggerbot-ruby
|
|
33
29
|
Require it to your code:
|
34
30
|
|
35
31
|
```ruby
|
36
|
-
require 'telegram/
|
32
|
+
require 'telegram/loggerbot'
|
37
33
|
```
|
38
34
|
|
39
|
-
|
35
|
+
Initialize with obtained TOKEN and TELEGRAM_USER_ID:
|
40
36
|
|
41
37
|
```ruby
|
42
38
|
Telegram::LoggerBot.configure do |config|
|
43
|
-
|
44
|
-
|
39
|
+
config.token = TOKEN # required
|
40
|
+
config.chat_id = USER_ID_OR_CHAT_ID # required
|
41
|
+
config.level = Logger::INFO # optional, default is Logger::DEBUG
|
42
|
+
config.next_logger = App.existing_logger_instance # optional
|
43
|
+
config.api = App.existing_telegram_bot_api_instance # optional
|
45
44
|
end
|
45
|
+
|
46
|
+
logger = Telegram::LoggerBot.new
|
46
47
|
```
|
47
48
|
|
48
|
-
|
49
|
+
or in classic style:
|
49
50
|
|
50
51
|
```ruby
|
51
|
-
logger = Telegram::LoggerBot.new
|
52
|
+
logger = Telegram::LoggerBot.new(
|
53
|
+
token: TOKEN, # required
|
54
|
+
chat_id: USER_ID_OR_CHAT_ID, # required
|
55
|
+
level: Logger::INFO, # optional, default is Logger::DEBUG
|
56
|
+
next_logger: App.existing_logger_instance, # optional
|
57
|
+
api: App.existing_telegram_bot_api_instance # optional
|
58
|
+
)
|
52
59
|
```
|
53
60
|
|
54
|
-
You can pass events through LoggerBot to
|
61
|
+
You can pass events through LoggerBot to any other logger:
|
55
62
|
|
56
63
|
```ruby
|
57
64
|
existing_logger = Logger.new(STDOUT)
|
58
|
-
logger = Telegram::LoggerBot.new(existing_logger)
|
65
|
+
logger = Telegram::LoggerBot.new(..., next_logger: existing_logger)
|
59
66
|
```
|
60
67
|
|
61
68
|
Log you events:
|
@@ -68,6 +75,12 @@ logger.error('MyProgram') { "Text of some errors" }
|
|
68
75
|
logger.fatal('MyProgram') { "Text of some errors" }
|
69
76
|
```
|
70
77
|
|
78
|
+
## Development
|
79
|
+
|
80
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
81
|
+
|
82
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
83
|
+
|
71
84
|
## Contributing
|
72
85
|
|
73
86
|
1. Fork it
|
@@ -75,3 +88,7 @@ logger.fatal('MyProgram') { "Text of some errors" }
|
|
75
88
|
3. Commit your changes (git commit -am 'Add some feature')
|
76
89
|
4. Push to the branch (git push origin my-new-feature)
|
77
90
|
5. Create new Pull Request
|
91
|
+
|
92
|
+
## License
|
93
|
+
|
94
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "telegram/loggerbot"
|
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
|
data/bin/setup
ADDED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'telegram/bot'
|
3
3
|
|
4
|
-
require 'telegram/
|
5
|
-
require 'telegram/
|
6
|
-
require 'telegram/
|
7
|
-
require 'telegram/
|
4
|
+
require 'telegram/loggerbot/logger'
|
5
|
+
require 'telegram/loggerbot/loggerbot'
|
6
|
+
require 'telegram/loggerbot/version'
|
7
|
+
require 'telegram/loggerbot/configuration'
|
8
8
|
|
9
9
|
module Telegram
|
10
10
|
module LoggerBot
|
@@ -1,11 +1,19 @@
|
|
1
1
|
module Telegram
|
2
2
|
module LoggerBot
|
3
|
+
TokenMissed = Class.new(ArgumentError)
|
4
|
+
ChatIdMissed = Class.new(ArgumentError)
|
5
|
+
|
3
6
|
class Logger < ::Logger
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
|
7
|
-
@
|
8
|
-
|
7
|
+
def initialize(args = {})
|
8
|
+
@default_formatter = args[:default_formatter] || Formatter.new
|
9
|
+
|
10
|
+
@level, @chat_id, @token, @next_logger, @api = args.values_at(:level, :chat_id, :token, :next_logger, :api)
|
11
|
+
|
12
|
+
@level ||= Telegram::LoggerBot.configuration.level || DEBUG
|
13
|
+
@chat_id ||= Telegram::LoggerBot.configuration.chat_id || fail(ChatIdMissed)
|
14
|
+
@token ||= Telegram::LoggerBot.configuration.token || fail(TokenMissed)
|
15
|
+
@next_logger ||= Telegram::LoggerBot.configuration.next_logger
|
16
|
+
@api ||= Telegram::LoggerBot.configuration.api || Telegram::Bot::Api.new(@token)
|
9
17
|
end
|
10
18
|
|
11
19
|
def clear_markdown(str)
|
@@ -68,7 +76,15 @@ module Telegram
|
|
68
76
|
|
69
77
|
def add(severity, message = nil, progname = nil, &block)
|
70
78
|
severity ||= UNKNOWN
|
71
|
-
|
79
|
+
|
80
|
+
if severity < @level
|
81
|
+
if @next_logger
|
82
|
+
return @next_logger.add(severity, message, progname, &block)
|
83
|
+
else
|
84
|
+
return true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
72
88
|
if message.nil?
|
73
89
|
if block_given?
|
74
90
|
message = block.dup.call
|
@@ -78,19 +94,20 @@ module Telegram
|
|
78
94
|
end
|
79
95
|
end
|
80
96
|
|
81
|
-
chat_id = Telegram::LoggerBot.configuration.chat_id
|
82
97
|
time = Time.now
|
83
98
|
|
84
99
|
text = "#{format_severity_icon(severity)}*#{format_severity(severity)}*"
|
85
100
|
text << " _#{clear_markdown(progname)}_" if progname
|
86
101
|
text << "\n#{format_time_icon(time)}#{time}"
|
87
102
|
|
88
|
-
@api.send_message(chat_id: chat_id, text: text, parse_mode: 'Markdown')
|
89
|
-
@api.send_message(chat_id: chat_id, text: message)
|
90
|
-
|
91
|
-
return true unless @next_logger
|
103
|
+
@api.send_message(chat_id: @chat_id, text: text, parse_mode: 'Markdown')
|
104
|
+
@api.send_message(chat_id: @chat_id, text: message)
|
92
105
|
|
93
|
-
@next_logger
|
106
|
+
if @next_logger
|
107
|
+
@next_logger.add(severity, message, progname, &block)
|
108
|
+
else
|
109
|
+
true
|
110
|
+
end
|
94
111
|
end
|
95
112
|
end
|
96
113
|
end
|
@@ -1,22 +1,29 @@
|
|
1
1
|
lib = File.expand_path('../lib', __FILE__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
|
4
|
-
require
|
4
|
+
require "telegram/loggerbot/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
7
|
+
spec.name = "telegram-loggerbot-ruby"
|
8
|
+
spec.version = Telegram::LoggerBot::VERSION
|
9
|
+
spec.authors = ["Anton Osenenko"]
|
10
|
+
spec.email = ["anton.osenenko@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary
|
13
|
-
spec.
|
14
|
-
spec.
|
12
|
+
spec.summary = "Telegram Logger Bot"
|
13
|
+
spec.description = "Log your events directly to the Telegram chat"
|
14
|
+
spec.homepage = "https://github.com/a0s/telegram-loggerbot-ruby"
|
15
|
+
spec.license = "MIT"
|
15
16
|
|
16
|
-
spec.files
|
17
|
-
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
18
23
|
|
19
|
-
spec.add_dependency
|
24
|
+
spec.add_dependency "telegram-bot-ruby"
|
20
25
|
|
21
|
-
spec.add_development_dependency
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
22
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telegram-loggerbot-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Osenenko
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: telegram-bot-ruby
|
@@ -30,15 +30,43 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.13'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
41
|
-
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Log your events directly to the Telegram chat
|
42
70
|
email:
|
43
71
|
- anton.osenenko@gmail.com
|
44
72
|
executables: []
|
@@ -46,15 +74,21 @@ extensions: []
|
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
76
|
- ".gitignore"
|
49
|
-
-
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
50
81
|
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
51
85
|
- img/preview1.jpg
|
52
86
|
- img/preview2.jpg
|
53
|
-
- lib/telegram/
|
54
|
-
- lib/telegram/
|
55
|
-
- lib/telegram/
|
56
|
-
- lib/telegram/
|
57
|
-
- lib/telegram/
|
87
|
+
- lib/telegram/loggerbot.rb
|
88
|
+
- lib/telegram/loggerbot/configuration.rb
|
89
|
+
- lib/telegram/loggerbot/logger.rb
|
90
|
+
- lib/telegram/loggerbot/loggerbot.rb
|
91
|
+
- lib/telegram/loggerbot/version.rb
|
58
92
|
- telegram-loggerbot-ruby.gemspec
|
59
93
|
homepage: https://github.com/a0s/telegram-loggerbot-ruby
|
60
94
|
licenses:
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Telegram
|
2
|
-
module LoggerBot
|
3
|
-
def self.new(obj = nil)
|
4
|
-
case obj
|
5
|
-
when ::Logger
|
6
|
-
Telegram::LoggerBot::Logger.new(obj)
|
7
|
-
when ::NilClass
|
8
|
-
Telegram::LoggerBot::Logger.new
|
9
|
-
else
|
10
|
-
fail("Unknown type of next logger #{obj.inspect}")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|