stompgem / stomp

A ruby gem for sending and receiving messages from a Stomp protocol compliant message queue. Includes: failover logic, ssl support.
http://stomp.github.com
Apache License 2.0
152 stars 80 forks source link

Added a NullLogger, made it the default. #77

Closed ismith closed 10 years ago

ismith commented 10 years ago

This lets us remove several instances of if @logger && @logger.respond_to?(:some_method)

(https://gist.github.com/ppaul/6540400, #9)

rtyler commented 10 years ago

:thumbsup:

gmallard commented 10 years ago

Consider doing the require of the null logger in lib/stomp.rb. One place rather than two.

stomp.gemspec appears to be updated by user edit. Use:

rake gemspec

to auto generate and validate a currently complete gemspec file.

PaulGale commented 10 years ago

Ian,

Some thoughts,

Thanks, Paul

On Mon, Sep 23, 2013 at 6:59 PM, Guy M. Allard notifications@github.com wrote:

Consider doing the require of the null logger in lib/stomp.rb. One place rather than two.

stomp.gemspec appears to be updated by user edit. Use:

rake gemspec

to auto generate and validate a currently complete gemspec file.

— Reply to this email directly or view it on GitHub.

ismith commented 10 years ago

@gmallard Good call on moving the require. I regenerated the gemspec as noted.

@ppaul Moved Slogger as suggested, and made it inherit from NullLogger. Can't easily Marshal Slogger, I think, because Logger isn't marshallable - it's got IO in it. So I may have to take logger out of the params hash and just use attr_accessor, unless you have other suggestions.

PaulGale commented 10 years ago

This works:

class Slogger < Stomp::NullLogger
  def initialize(init_parms = nil)
    _init
    @log.info('Logger initialization complete.')
  end

  def marshal_dump
    []
  end

  def marshal_load(array)
    _init
  end

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

  # ...etc
end