I am a total beginner to Ruby and am hoping for some advice. My goal is to log all (for example) socket operations with a Ruby program with as little code modification as possible.
As a tiny example, pretend I have a super simple server like so:
require 'socket'
server = TCPServer.open(2017)
loop {
client = server.accept
client.puts "hello world"
client.close
}
In python, I could use sys.addAuditHook
to catch the socket operations (open/write/etc) buried somewhere within the depths of TCPServer.open
/server.accept
/client.puts
without having to resort to wrapping the entire TCPServer api or something like that.
I am interested in system events, not object writes, so Rails' Active Record Callbacks doesn't look like what I'm looking for.
Does anyone know if there's anything remotely equivalent for Ruby/Ruby on Rails, or am I stuck doing this the slow way?
Thank you!
No, ruby doesn't have that level of logging built in. The bulk of that use case is generally achieved through APM/instrumentation tools or services, but those generally target higher level (gem) libraries, rather than the low level stdlib stuff.