Class: Slogger

Inherits:
Stomp::NullLogger show all
Defined in:
lib/stomp/slogger.rb

Overview

Example STOMP call back logger class.

Optional callback methods:

  • on_connecting: connection starting

  • on_connected: successful connect

  • on_connectfail: unsuccessful connect (will usually be retried)

  • on_disconnect: successful disconnect

  • on_miscerr: on miscellaneous xmit/recv errors

  • on_publish: publish called

  • on_subscribe: subscribe called

  • on_unsubscribe: unsubscribe called

  • on_begin: begin called

  • on_ack: ack called

  • on_nack: nack called

  • on_commit: commit called

  • on_abort: abort called

  • on_receive: receive called and successful

  • on_ssl_connecting: SSL connection starting

  • on_ssl_connected: successful SSL connect

  • on_ssl_connectfail: unsuccessful SSL connect (will usually be retried)

  • on_hbread_fail: unsuccessful Heartbeat read

  • on_hbwrite_fail: unsuccessful Heartbeat write

  • on_hbfire: on any send or receive heartbeat

All methods are optional, at the user's requirements.

If a method is not provided, it is not called (of course.)

IMPORTANT NOTE: in general, call back logging methods SHOULD not raise exceptions, otherwise the underlying STOMP connection may fail in mysterious ways.

There are two useful exceptions to this rule for:

  • on_connectfail

  • on_ssl_connectfail

These two methods can raise a Stomp::Errors::LoggerConnectionError. If this exception is raised, it is passed up the chain to the caller.

Callback parameters: are a copy of the @parameters instance variable for the Stomp::Connection.

Instance Method Summary collapse

Constructor Details

#initialize(init_parms = nil) ⇒ Slogger

Initialize a new callback logger instance.



57
58
59
60
# File 'lib/stomp/slogger.rb', line 57

def initialize(init_parms = nil)
  _init
  @log.info("Logger initialization complete.")
end

Instance Method Details

#_initObject



62
63
64
65
# File 'lib/stomp/slogger.rb', line 62

def _init
  @log = Logger::new(STDOUT)		# User preference
  @log.level = Logger::DEBUG		# User preference
end

#marshal_dumpObject



67
68
69
# File 'lib/stomp/slogger.rb', line 67

def marshal_dump
  []
end

#marshal_load(array) ⇒ Object



71
72
73
# File 'lib/stomp/slogger.rb', line 71

def marshal_load(array)
  _init
end

#on_abort(parms, headers) ⇒ Object

Log Abort



208
209
210
211
212
213
214
215
# File 'lib/stomp/slogger.rb', line 208

def on_abort(parms, headers)
  begin
    @log.debug "Abort Parms #{info(parms)}"
    @log.debug "Abort Result #{headers}"
  rescue
    @log.debug "Abort oops"
  end
end

#on_ack(parms, headers) ⇒ Object

Log Ack



178
179
180
181
182
183
184
185
# File 'lib/stomp/slogger.rb', line 178

def on_ack(parms, headers)
  begin
    @log.debug "Ack Parms #{info(parms)}"
    @log.debug "Ack Result #{headers}"
  rescue
    @log.debug "Ack oops"
  end
end

#on_begin(parms, headers) ⇒ Object

Log Begin



168
169
170
171
172
173
174
175
# File 'lib/stomp/slogger.rb', line 168

def on_begin(parms, headers)
  begin
    @log.debug "Begin Parms #{info(parms)}"
    @log.debug "Begin Result #{headers}"
  rescue
    @log.debug "Begin oops"
  end
end

#on_commit(parms, headers) ⇒ Object

Log Commit



198
199
200
201
202
203
204
205
# File 'lib/stomp/slogger.rb', line 198

def on_commit(parms, headers)
  begin
    @log.debug "Commit Parms #{info(parms)}"
    @log.debug "Commit Result #{headers}"
  rescue
    @log.debug "Commit oops"
  end
end

#on_connected(parms) ⇒ Object

Log connected events



85
86
87
88
89
90
91
# File 'lib/stomp/slogger.rb', line 85

def on_connected(parms)
  begin
    @log.debug "Connected: #{info(parms)}"
  rescue
    @log.debug "Connected oops"
  end
end

#on_connectfail(parms) ⇒ Object

Log connectfail events



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/stomp/slogger.rb', line 94

def on_connectfail(parms)
  begin
    @log.debug "Connect Fail #{info(parms)}"
  rescue
    @log.debug "Connect Fail oops"
  end
=begin
  # An example LoggerConnectionError raise
  @log.debug "Connect Fail, will raise"
  raise Stomp::Error::LoggerConnectionError.new("quit from connect fail")
=end
end

#on_connecting(parms) ⇒ Object

Log connecting events



76
77
78
79
80
81
82
# File 'lib/stomp/slogger.rb', line 76

def on_connecting(parms)
  begin
    @log.debug "Connecting: #{info(parms)}"
  rescue
    @log.debug "Connecting oops"
  end
end

#on_disconnect(parms) ⇒ Object

Log disconnect events



108
109
110
111
112
113
114
# File 'lib/stomp/slogger.rb', line 108

def on_disconnect(parms)
  begin
    @log.debug "Disconnected #{info(parms)}"
  rescue
    @log.debug "Disconnected oops"
  end
end

#on_hbfire(parms, srind, firedata = {}) ⇒ Object

Log heart beat fires



271
272
273
274
275
276
277
278
# File 'lib/stomp/slogger.rb', line 271

def on_hbfire(parms, srind, firedata = {})
  begin
    @log.debug "HeartBeat Fire Parms #{info(parms)}"
    @log.debug "HeartBeat Fire Send/Receive #{srind}"
  rescue
    @log.debug "HeartBeat Fire oops"
  end
end

#on_hbread_fail(parms, ticker_data = {}) ⇒ Object

Stomp 1.1+ - heart beat read (receive) failed.



218
219
220
221
222
223
224
225
# File 'lib/stomp/slogger.rb', line 218

def on_hbread_fail(parms, ticker_data = {})
  begin
    @log.debug "Hbreadf Parms #{info(parms)}"
    @log.debug "Hbreadf Result #{ticker_data.inspect}"
  rescue
    @log.debug "Hbreadf oops"
  end
end

#on_hbwrite_fail(parms, ticker_data = {}) ⇒ Object

Stomp 1.1+ - heart beat send (transmit) failed.



228
229
230
231
232
233
234
235
# File 'lib/stomp/slogger.rb', line 228

def on_hbwrite_fail(parms, ticker_data = {})
  begin
    @log.debug "Hbwritef Parms #{info(parms)}"
    @log.debug "Hbwritef Result #{ticker_data.inspect}"
  rescue
    @log.debug "Hbwritef oops"
  end
end

#on_miscerr(parms, errstr) ⇒ Object

Log miscellaneous errors



117
118
119
120
121
122
123
124
# File 'lib/stomp/slogger.rb', line 117

def on_miscerr(parms, errstr)
  begin
    @log.debug "Miscellaneous Error #{info(parms)}"
    @log.debug "Miscellaneous Error String #{errstr}"
  rescue
    @log.debug "Miscellaneous Error oops"
  end
end

#on_nack(parms, headers) ⇒ Object

Log NAck



188
189
190
191
192
193
194
195
# File 'lib/stomp/slogger.rb', line 188

def on_nack(parms, headers)
  begin
    @log.debug "NAck Parms #{info(parms)}"
    @log.debug "NAck Result #{headers}"
  rescue
    @log.debug "NAck oops"
  end
end

#on_publish(parms, message, headers) ⇒ Object

Log Publish



147
148
149
150
151
152
153
154
155
# File 'lib/stomp/slogger.rb', line 147

def on_publish(parms, message, headers)
  begin
    @log.debug "Publish Parms #{info(parms)}"
    @log.debug "Publish Message #{message}"
    @log.debug "Publish Headers #{headers}"
  rescue
    @log.debug "Publish oops"
  end
end

#on_receive(parms, result) ⇒ Object

Log Receive



158
159
160
161
162
163
164
165
# File 'lib/stomp/slogger.rb', line 158

def on_receive(parms, result)
  begin
    @log.debug "Receive Parms #{info(parms)}"
    @log.debug "Receive Result #{result}"
  rescue
    @log.debug "Receive oops"
  end
end

#on_ssl_connected(parms) ⇒ Object

Log a successful SSL connect.



247
248
249
250
251
252
253
# File 'lib/stomp/slogger.rb', line 247

def on_ssl_connected(parms)
  begin
    @log.debug "SSL Connected Parms #{info(parms)}"
  rescue
    @log.debug "SSL Connected oops"
  end
end

#on_ssl_connectfail(parms) ⇒ Object

Log an unsuccessful SSL connect.



256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/stomp/slogger.rb', line 256

def on_ssl_connectfail(parms)
  begin
    @log.debug "SSL Connect Fail Parms #{info(parms)}"
    @log.debug "SSL Connect Fail Exception #{parms[:ssl_exception]}, #{parms[:ssl_exception].message}"
  rescue
    @log.debug "SSL Connect Fail oops"
  end
=begin
  # An example LoggerConnectionError raise
  @log.debug "SSL Connect Fail, will raise"
  raise Stomp::Error::LoggerConnectionError.new("quit from SSL connect")
=end
end

#on_ssl_connecting(parms) ⇒ Object

Log SSL connection start.



238
239
240
241
242
243
244
# File 'lib/stomp/slogger.rb', line 238

def on_ssl_connecting(parms)
  begin
    @log.debug "SSL Connecting Parms #{info(parms)}"
  rescue
    @log.debug "SSL Connecting oops"
  end
end

#on_subscribe(parms, headers) ⇒ Object

Log Subscribe



127
128
129
130
131
132
133
134
# File 'lib/stomp/slogger.rb', line 127

def on_subscribe(parms, headers)
  begin
    @log.debug "Subscribe Parms #{info(parms)}"
    @log.debug "Subscribe Headers #{headers}"
  rescue
    @log.debug "Subscribe oops"
  end
end

#on_unsubscribe(parms, headers) ⇒ Object

Log UnSubscribe



137
138
139
140
141
142
143
144
# File 'lib/stomp/slogger.rb', line 137

def on_unsubscribe(parms, headers)
  begin
    @log.debug "UnSubscribe Parms #{info(parms)}"
    @log.debug "UnSubscribe Headers #{headers}"
  rescue
    @log.debug "UnSubscribe oops"
  end
end