# -*- encoding: utf-8 -*- require 'eventbus/common_init' # This is taken almost directly from the Stomp gem's example # logger, with minor modifications. Will work on customizing later. # == 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. # module EventBus module Connectors module Stomp class Slogger # Initialize a new callback logger instance. def initialize(init_parms = nil) EventBus.logger.info("Logger is: #{EventBus.logger.inspect}") EventBus.logger.info("Logger initialization complete.") end # Log connecting events def on_connecting(parms) begin EventBus.logger.info "Connecting: #{info(parms)}" rescue EventBus.logger.debug "Connecting oops" end end # Log connected events def on_connected(parms) begin EventBus.logger.info "Connected: #{info(parms)}" rescue EventBus.logger.debug "Connected oops" end end # Log connectfail events def on_connectfail(parms) begin EventBus.logger.error "Connect Fail #{info(parms)}" rescue EventBus.logger.debug "Connect Fail oops" end =begin # An example LoggerConnectionError raise EventBus.logger.debug "Connect Fail, will raise" raise Stomp::Error::LoggerConnectionError.new("quit from connect fail") =end end # Log disconnect events def on_disconnect(parms) begin EventBus.logger.info "Disconnected #{info(parms)}" rescue EventBus.logger.debug "Disconnected oops" end end # Log miscellaneous errors def on_miscerr(parms, errstr) begin EventBus.logger.unknown "Miscellaneous Error #{info(parms)}" EventBus.logger.unknown "Miscellaneous Error String #{errstr}" rescue EventBus.logger.debug "Miscellaneous Error oops" end end # Log Subscribe def on_subscribe(parms, headers) begin EventBus.logger.info "Subscribe Parms #{info(parms)}" EventBus.logger.info "Subscribe Headers #{headers}" rescue EventBus.logger.debug "Subscribe oops" end end # Log UnSubscribe def on_unsubscribe(parms, headers) begin EventBus.logger.info "UnSubscribe Parms #{info(parms)}" EventBus.logger.info "UnSubscribe Headers #{headers}" rescue EventBus.logger.debug "UnSubscribe oops" end end # Log Publish def on_publish(parms, message, headers) begin EventBus.logger.info "Publish Parms #{info(parms)}" EventBus.logger.info "Publish Message #{message}" EventBus.logger.info "Publish Headers #{headers}" rescue EventBus.logger.debug "Publish oops" end end # Log Receive def on_receive(parms, result) begin EventBus.logger.info "Receive Parms #{info(parms)}" EventBus.logger.info "Receive Result #{result}" rescue EventBus.logger.debug "Receive oops" end end # Log Begin def on_begin(parms, headers) begin EventBus.logger.info "Begin Parms #{info(parms)}" EventBus.logger.info "Begin Result #{headers}" rescue EventBus.logger.debug "Begin oops" end end # Log Ack def on_ack(parms, headers) begin EventBus.logger.debug "Ack Parms #{info(parms)}" EventBus.logger.debug "Ack Result #{headers}" rescue EventBus.logger.debug "Ack oops" end end # Log NAck def on_nack(parms, headers) begin EventBus.logger.debug "NAck Parms #{info(parms)}" EventBus.logger.debug "NAck Result #{headers}" rescue EventBus.logger.debug "NAck oops" end end # Log Commit def on_commit(parms, headers) begin EventBus.logger.info "Commit Parms #{info(parms)}" EventBus.logger.info "Commit Result #{headers}" rescue EventBus.logger.debug "Commit oops" end end # Log Abort def on_abort(parms, headers) begin EventBus.logger.info "Abort Parms #{info(parms)}" EventBus.logger.info "Abort Result #{headers}" rescue EventBus.logger.debug "Abort oops" end end # Stomp 1.1+ - heart beat read (receive) failed. def on_hbread_fail(parms, ticker_data) begin EventBus.logger.warn "Hbreadf Parms #{info(parms)}" EventBus.logger.warn "Hbreadf Result #{ticker_data.inspect}" rescue EventBus.logger.debug "Hbreadf oops" end end # Stomp 1.1+ - heart beat send (transmit) failed. def on_hbwrite_fail(parms, ticker_data) begin EventBus.logger.warn "Hbwritef Parms #{info(parms)}" EventBus.logger.warn "Hbwritef Result #{ticker_data.inspect}" rescue EventBus.logger.debug "Hbwritef oops" end end # Log SSL connection start. def on_ssl_connecting(parms) begin EventBus.logger.info "SSL Connecting Parms #{info(parms)}" rescue EventBus.logger.debug "SSL Connecting oops" end end # Log a successful SSL connect. def on_ssl_connected(parms) begin EventBus.logger.info "SSL Connected Parms #{info(parms)}" rescue EventBus.logger.debug "SSL Connected oops" end end # Log an unsuccessful SSL connect. def on_ssl_connectfail(parms) begin EventBus.logger.error "SSL Connect Fail Parms #{info(parms)}" EventBus.logger.error "SSL Connect Fail Exception #{parms[:ssl_exception]}, #{parms[:ssl_exception].message}" rescue EventBus.logger.debug "SSL Connect Fail oops" end =begin # An example LoggerConnectionError raise EventBus.logger.debug "SSL Connect Fail, will raise" raise Stomp::Error::LoggerConnectionError.new("quit from SSL connect") =end end # Log heart beat fires def on_hbfire(parms, srind, curt) begin EventBus.logger.debug "HeartBeat Fire Parms #{info(parms)}" EventBus.logger.debug "HeartBeat Fire Send/Receive #{srind}" rescue EventBus.logger.debug "HeartBeat Fire oops" end end private # Example information extract. def info(parms) # # Available in the parms Hash: # parms[:cur_host] # parms[:cur_port] # parms[:cur_login] # parms[:cur_passcode] # parms[:cur_ssl] # parms[:cur_recondelay] # parms[:cur_parseto] # parms[:cur_conattempts] # parms[:openstat] # # For the on_ssl_connectfail callback these are also available: # parms[:ssl_exception] # "Host: #{parms[:cur_host]}, Port: #{parms[:cur_port]}, Login: #{parms[:cur_login]}, Passcode: #{parms[:cur_passcode]}," + " ssl: #{parms[:cur_ssl]}, open: #{parms[:openstat]}" end end # module ends end end end