![]()
|
Remote LoggingWant to use Log4r over a network? No problem! A Log4r::RemoteOutputter will send its LogEvents to a Log4r::LogServer. These two classes are as easy to set up and use as the rest of Log4r. Use ROMPThere 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/ LogServerLogServer 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. LogServer SetupSetup is easy. First, require 'log4r/logserver' The following sets up a LogServer named 'central' on localhost port 9999: LogServer.new('central', 'tcpromp://localhost: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 RemoteOutputterRemoteOutputter 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). RemoteOutputter SetupFirst, require 'log4r/outputter/remoteoutputter' 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' Using RemoteOutputterGive 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' XML ConfigurationRemoteOutputter 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"> ... DebuggingIt 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.
Module Log4r ::Class Log4r::BasicFormatter ::Class Log4r::ConfigError ::Class Log4r::Configurator ::Class Log4r::DefaultFormatter ::Class Log4r::EmailOutputter ::Class Log4r::FileOutputter ::Class Log4r::Formatter ::Class Log4r::IOOutputter ::Class Log4r::Log4rTools ::Class Log4r::LogEvent ::Class Log4r::LogServer ::Class Log4r::Logger ::Class Log4r::ObjectFormatter ::Class Log4r::Outputter ::Class Log4r::PatternFormatter ::Class Log4r::RemoteOutputter ::Class Log4r::RollingFileOutputter ::Class Log4r::RootLogger ::Class Log4r::SimpleFormatter ::Class Log4r::StderrOutputter ::Class Log4r::StdoutOutputter |