Reputation: 22643
I'm writing a client application which runs on a users computer and sends various requests to a server.
What I'd like to do is make logs from the client programs available on the server so that issues can be easily detected.
So, what I was thinking was to make the client log to a remote location over http.
Is this a good idea and are there any gems or libraries that will facilitate this?
Upvotes: 3
Views: 559
Reputation: 303253
You could use DRb + Logger for this. Both are part of the Ruby standard library, so you don't even need to install any gems on either machine.
Here's how it works:
Remote Logging Machine
require 'drb'
require 'logger'
DRb.start_service 'druby://0.0.0.0:9000', Logger.new('foo.log', 'weekly')
DRb.thread.join
Machine Doing the Logging
require 'drb'
$log = DRbObject.new_with_uri 'druby://remote.server.ip:9000'
begin
$log.info "Hello World"
rescue DRb::DRbConnError => e
warn "Could not log because: #{e}"
# Optionally re-log the message somewhere else.
end
puts "Yay, still running!"
I just tested this between two machines 1500 miles apart, where the client machine is even behind NAT, and it worked flawlessly.
Upvotes: 3