Sha256: 4eac48cfb24f4c0efd060a739e5e7a1381ccacbbe320cc721d03e325845426ae
Contents?: true
Size: 942 Bytes
Versions: 2
Compression:
Stored size: 942 Bytes
Contents
# Provides a way of wrapping another broadcaster with logging module Wisper module Broadcasters class LoggerBroadcaster def initialize(logger, broadcaster) @logger = logger @broadcaster = broadcaster end def broadcast(subscriber, publisher, event, args) @logger.info("[WISPER] #{name(publisher)} published #{event} to #{name(subscriber)} with #{arg_names(args)}") @broadcaster.broadcast(subscriber, publisher, event, args) end private def name(object) id_method = %w(id uuid key object_id).find { |id_method| object.respond_to?(id_method) } id = object.send(id_method) class_name = object.class == Class ? object.name : object.class.name "#{class_name}##{id}" end def arg_names(args) return 'no arguments' if args.empty? args.map { |arg| name(arg) }.join(', ') end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wisper-1.6.0 | lib/wisper/broadcasters/logger_broadcaster.rb |
wisper-1.5.0 | lib/wisper/broadcasters/logger_broadcaster.rb |