Skip to content

Commit c99043b

Browse files
committed
Include team id, name and domain in log output.
1 parent 304eedc commit c99043b

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2019-07-20 16:45:38 -0400 using RuboCop version 0.61.1.
3+
# on 2019-07-21 10:11:39 -0400 using RuboCop version 0.61.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [#279](https://github.com/slack-ruby/slack-ruby-client/pull/279): Prevent ping worker from dying on unexpected errors - [@dblock](https://github.com/dblock).
44
* [#281](https://github.com/slack-ruby/slack-ruby-client/pull/281): Added `admin_users_session_reset` to Web API - [@dblock](https://github.com/dblock).
55
* [#283](https://github.com/slack-ruby/slack-ruby-client/pull/283): Fail when used with incompatible async-websocket > 0.8.0 - [@dblock](https://github.com/dblock).
6+
* [#284](https://github.com/slack-ruby/slack-ruby-client/pull/284): Include team id, name and domain in log output - [@dblock](https://github.com/dblock).
67
* Your contribution here.
78

89
### 0.14.2 (2019/4/12)

lib/slack/real_time/client.rb

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ def config
8282
def run_loop
8383
@socket.connect! do |driver|
8484
driver.on :open do |event|
85-
logger.debug("#{self.class}##{__method__}") { event.class.name }
85+
logger.debug("#{self}##{__method__}") { event.class.name }
8686
open(event)
8787
callback(event, :open)
8888
end
8989

9090
driver.on :message do |event|
91-
logger.debug("#{self.class}##{__method__}") { "#{event.class}, #{event.data}" }
91+
logger.debug("#{self}##{__method__}") { "#{event.class}, #{event.data}" }
9292
dispatch(event)
9393
end
9494

9595
driver.on :close do |event|
96-
logger.debug("#{self.class}##{__method__}") { event.class.name }
96+
logger.debug("#{self}##{__method__}") { event.class.name }
9797
callback(event, :close)
9898
close(event)
9999
callback(event, :closed)
@@ -127,20 +127,30 @@ def keep_alive?
127127
def run_ping!
128128
return if keep_alive?
129129

130+
logger.warn(to_s) { 'is offline' }
131+
130132
restart_async
131133
rescue StandardError => e
132134
# disregard all ping worker failures, keep pinging
133-
logger.debug("#{self.class}##{__method__}") { e }
135+
logger.debug("#{self}##{__method__}") { e }
134136
end
135137

136138
def run_ping?
137139
!websocket_ping.nil? && websocket_ping > 0
138140
end
139141

142+
def to_s
143+
if store && store.team
144+
"id=#{store.team.id}, name=#{store.team.name}, domain=#{store.team.domain}"
145+
else
146+
super
147+
end
148+
end
149+
140150
protected
141151

142152
def restart_async
143-
logger.debug("#{self.class}##{__method__}")
153+
logger.debug("#{self}##{__method__}")
144154
@socket.close
145155
start = web_client.send(rtm_start_method, start_options)
146156
data = Slack::Messages::Message.new(start)
@@ -186,7 +196,7 @@ def socket_class
186196
def send_json(data)
187197
raise ClientNotStartedError unless started?
188198

189-
logger.debug("#{self.class}##{__method__}") { data }
199+
logger.debug("#{self}##{__method__}") { data }
190200
@socket.send_data(data.to_json)
191201
end
192202

@@ -207,7 +217,7 @@ def callback(event, type)
207217
end
208218
true
209219
rescue StandardError => e
210-
logger.error e
220+
logger.error("#{self}##{__method__}") { e }
211221
false
212222
end
213223

@@ -219,11 +229,11 @@ def dispatch(event)
219229
return false unless type
220230

221231
type = type.to_s
222-
logger.debug("#{self.class}##{__method__}") { data.to_s }
232+
logger.debug("#{self}##{__method__}") { data.to_s }
223233
run_handlers(type, data) if @store
224234
run_callbacks(type, data)
225235
rescue StandardError => e
226-
logger.error e
236+
logger.error("#{self}##{__method__}") { e }
227237
false
228238
end
229239

@@ -235,7 +245,7 @@ def run_handlers(type, data)
235245
end
236246
end
237247
rescue StandardError => e
238-
logger.error e
248+
logger.error("#{self}##{__method__}") { e }
239249
false
240250
end
241251

@@ -248,7 +258,7 @@ def run_callbacks(type, data)
248258
end
249259
true
250260
rescue StandardError => e
251-
logger.error e
261+
logger.error("#{self}##{__method__}") { e }
252262
false
253263
end
254264
end

lib/slack/real_time/concurrency/async.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def start_reactor(client)
3030

3131
if client.run_ping?
3232
@ping_task = task.async do |subtask|
33-
subtask.annotate 'client keep-alive'
33+
subtask.annotate "#{client} keep-alive"
3434

3535
# The timer task will naturally exit after the driver is set to nil.
3636
while @restart
@@ -45,7 +45,7 @@ def start_reactor(client)
4545

4646
@client_task = task.async do |subtask|
4747
begin
48-
subtask.annotate 'client run-loop'
48+
subtask.annotate "#{client} run-loop"
4949
client.run_loop
5050
rescue ::Async::Wrapper::Cancelled => e
5151
# Will get restarted by ping worker.

spec/slack/real_time/client_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
it 'sets groups' do
8787
expect(client.groups.count).to eq 1
8888
end
89+
it 'includes team name in to_s' do
90+
expect(client.to_s).to eq "id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
91+
end
8992
end
9093
it 'uses web client to fetch url' do
9194
expect(client.web_client).to be_a Slack::Web::Client
@@ -159,6 +162,11 @@
159162
end
160163
end
161164
end
165+
describe 'to_s' do
166+
it 'defaults to class instance' do
167+
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
168+
end
169+
end
162170
end
163171
context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
164172
let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Starter) }
@@ -199,6 +207,9 @@
199207
it 'no groups' do
200208
expect(client.groups).to be_nil
201209
end
210+
it 'includes team name in to_s' do
211+
expect(client.to_s).to eq "id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
212+
end
202213
end
203214
it 'uses web client to fetch url' do
204215
expect(client.web_client).to be_a Slack::Web::Client
@@ -251,6 +262,11 @@
251262
it 'team' do
252263
expect(client.team).to be nil
253264
end
265+
describe 'to_s' do
266+
it 'defaults to class instance' do
267+
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
268+
end
269+
end
254270
end
255271
context 'client with defaults' do
256272
let(:client) { Slack::RealTime::Client.new }

0 commit comments

Comments
 (0)