There is one catch though: ROMP is required to use this service. It is a DRb-like system with superb performance and better features. Get ROMP at rm-f.net/~cout/ruby/romp/
LogServer is simply a kind of Logger which embeds a ROMP::Server. Like a normal Logger, you can give it Outputters, set its level and so on. Its logging methods are accessible over a network and are called by a RemoteOutputter on another host.
Setup is easy. First,
The following sets up a LogServer named 'central' on localhost port 9999:
We manipulate it and give it outputters as normal:
serv = Logger['central'] # grab our new LogServer serv.add 'stdout' # make it log to $stdout
RemoteOutputter is simply a kind of Outputter that embeds a ROMP::Client. When RemoteOutputter gets a LogEvent, it will forward it to whatever LogServer it's connected to. In essence, RemoteOutputter behaves like a Logger that is forwarding a LogEvent to another Logger (as is done in heiarchial logging).
Unlike typical outputters, RemoteOutputter doesn't do any formatting. That's up to the LogServer's outputters. Otherwise, RemoteOutputter can be set up as usual. The ROMP uri of the LogServer must be specified.
RemoteOutputter.new 'client', :uri=>'tcpromp://localhost:9999'
Give our new RemoteOutputter to a logger:
mylog = Logger['mylog'] mylog.add 'client'
Now, whenever mylog generates a LogEvent, LogServer should get a copy. Doing the following:
mylog.info "This is a message from 'mylog'"
Produces this output on LogServer's console:
INFO mylog: This is a message from 'mylog'
RemoteOutputter is set up like normal Outputters. LogServer is set up like a normal Logger, but with an element name of logserver instead of logger:
<log4r_config> <logserver name="name" uri="tcpromp://localhost:9999"> ...
It is recommended to set up a logger named 'log4r' on both the server and client to see what LogServer and RemoteOutputter are up to. Both of the classes use Log4r's internal logging to report any problems. See the section What's Going on Inside? in log4r.rb for more info.
|Classes and Modules|