Class: Riser::LoggingStream
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(io, logger) ⇒ LoggingStream
constructor
A new instance of LoggingStream.
- #read(size) ⇒ Object
- #readpartial(maxlen, outbuf = nil) ⇒ Object
- #write(message) ⇒ Object
Methods inherited from Stream
Constructor Details
#initialize(io, logger) ⇒ LoggingStream
Returns a new instance of LoggingStream.
106 107 108 109 110 111 |
# File 'lib/riser/stream.rb', line 106 def initialize(io, logger) super(io) @logger = logger @tag = self.class.make_tag(io) @logger.debug("#{@tag} start") if @logger.debug? end |
Class Method Details
.make_tag(io) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/riser/stream.rb', line 87 def self.make_tag(io) hex = Digest::SHA256.hexdigest(io.to_s)[0, 7] io = io.to_io fd = io.to_i if (io.respond_to? :remote_address) then addr = io.remote_address if (addr.ip?) then # expected only stream type "[#{hex},#{fd},tcp://#{io.remote_address.inspect_sockaddr}]" elsif (addr.unix?) then "[#{hex},#{fd},unix:#{io.remote_address.unix_path}]" else "[#{hex},#{fd},unknown:#{io.remote_address.inspect_sockaddr}]" end else "[#{hex},#{fd}]" end end |
Instance Method Details
#close ⇒ Object
143 144 145 146 147 |
# File 'lib/riser/stream.rb', line 143 def close ret_val = super @logger.info("#{@tag} close") if @logger.info? ret_val end |
#flush ⇒ Object
138 139 140 141 |
# File 'lib/riser/stream.rb', line 138 def flush @logger.info("#{@tag} flush") if @logger.info? super end |
#read(size) ⇒ Object
121 122 123 124 125 |
# File 'lib/riser/stream.rb', line 121 def read(size) data = super @logger.info("#{@tag} r #{data.inspect}") if @logger.info? data end |
#readpartial(maxlen, outbuf = nil) ⇒ Object
127 128 129 130 131 |
# File 'lib/riser/stream.rb', line 127 def readpartial(maxlen, outbuf=nil) data = super @logger.info("#{@tag} r #{data.inspect}") if @logger.info? data end |
#write(message) ⇒ Object
133 134 135 136 |
# File 'lib/riser/stream.rb', line 133 def write() @logger.info("#{@tag} w #{.inspect}") if @logger.info? super end |