telegram-loggerbot-ruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/README.md +8 -4
- data/lib/telegram/loggerbot/configuration.rb +1 -1
- data/lib/telegram/loggerbot/logger.rb +17 -13
- data/lib/telegram/loggerbot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2a79a7791abf4b30dd3cf62eb81aea5d433b09d
|
4
|
+
data.tar.gz: bc64e07a38230ef3ec5e3e9f8f5055f390989c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69cf7a897084fe6d0dd28b822c028a02fefebdb6158b0ad139b6b617a97b90ecd1fb8321aa623b25922c9d5391aefc992c64c580c094580a678aa3c3490d458b
|
7
|
+
data.tar.gz: 2f2f40fa602754e1e757c1eab25d58a03473c2e391c515697617338241e5d378725c2353414e9cca80c2042781b858b16f7994591b495bad216e9c6e3beb873c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
1
|
+
#Telegram::LoggerBot
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/a0s/telegram-loggerbot-ruby.svg?branch=master)](https://travis-ci.org/a0s/telegram-loggerbot-ruby)
|
2
4
|
|
3
|
-
|
5
|
+
Telegram::LoggerBot allows to send event logs directly to the Telegram chat
|
4
6
|
|
5
|
-
|
7
|
+
![preview1](https://github.com/a0s/telegram-loggerbot-ruby/raw/master/img/preview1.jpg)![preview2](https://github.com/a0s/telegram-loggerbot-ruby/raw/master/img/preview2.jpg)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
10
12
|
|
11
13
|
```ruby
|
12
|
-
gem 'loggerbot'
|
14
|
+
gem 'telegram-loggerbot-ruby'
|
13
15
|
```
|
14
16
|
|
15
17
|
And then execute:
|
@@ -38,6 +40,7 @@ Initialize with obtained TOKEN and TELEGRAM_USER_ID:
|
|
38
40
|
Telegram::LoggerBot.configure do |config|
|
39
41
|
config.token = TOKEN # required
|
40
42
|
config.chat_id = USER_ID_OR_CHAT_ID # required
|
43
|
+
config.enabled = false # optional, true by default
|
41
44
|
config.level = Logger::INFO # optional, default is Logger::DEBUG
|
42
45
|
config.next_logger = App.existing_logger_instance # optional
|
43
46
|
config.api = App.existing_telegram_bot_api_instance # optional
|
@@ -52,6 +55,7 @@ or in classic style:
|
|
52
55
|
logger = Telegram::LoggerBot.new(
|
53
56
|
token: TOKEN, # required
|
54
57
|
chat_id: USER_ID_OR_CHAT_ID, # required
|
58
|
+
enabled: false, # optional, true by default
|
55
59
|
level: Logger::INFO, # optional, default is Logger::DEBUG
|
56
60
|
next_logger: App.existing_logger_instance, # optional
|
57
61
|
api: App.existing_telegram_bot_api_instance # optional
|
@@ -7,13 +7,15 @@ module Telegram
|
|
7
7
|
def initialize(args = {})
|
8
8
|
@default_formatter = args[:default_formatter] || Formatter.new
|
9
9
|
|
10
|
-
@level
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
16
|
-
@
|
10
|
+
@level = args[:level] || Telegram::LoggerBot.configuration.level || DEBUG
|
11
|
+
@chat_id = args[:chat_id] || Telegram::LoggerBot.configuration.chat_id || fail(ChatIdMissed)
|
12
|
+
@token = args[:token] || Telegram::LoggerBot.configuration.token || fail(TokenMissed)
|
13
|
+
@next_logger = args[:next_logger] || Telegram::LoggerBot.configuration.next_logger
|
14
|
+
@api = args[:api] || Telegram::LoggerBot.configuration.api || Telegram::Bot::Api.new(@token)
|
15
|
+
|
16
|
+
@enabled = args[:enabled] unless args[:enabled].nil?
|
17
|
+
@enabled = Telegram::LoggerBot.configuration.enabled unless Telegram::LoggerBot.configuration.enabled.nil?
|
18
|
+
@enabled = true if @enabled.nil?
|
17
19
|
end
|
18
20
|
|
19
21
|
def clear_markdown(str)
|
@@ -94,14 +96,16 @@ module Telegram
|
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
97
|
-
|
99
|
+
if @enabled
|
100
|
+
time = Time.now
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
+
text = "#{format_severity_icon(severity)}*#{format_severity(severity)}*"
|
103
|
+
text << " _#{clear_markdown(progname)}_" if progname
|
104
|
+
text << "\n#{format_time_icon(time)}#{time}"
|
102
105
|
|
103
|
-
|
104
|
-
|
106
|
+
@api.send_message(chat_id: @chat_id, text: text, parse_mode: 'Markdown')
|
107
|
+
@api.send_message(chat_id: @chat_id, text: message)
|
108
|
+
end
|
105
109
|
|
106
110
|
if @next_logger
|
107
111
|
@next_logger.add(severity, message, progname, &block)
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Osenenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: telegram-bot-ruby
|