The LogConnection
class functions as a repository for the hostname and port configuration for the Log Server you want to send the log request to.
The signature for a LogConnection
constructor looks like this:
//Create a Log Server connection LogConnection lsc = new LogConnection(logHost, logPort);
You call the following methods on a LogConnection
object to establish a connection with a Log Server and send it a log request:
The
log() method
sends a request to the Log Server but does not wait for a response.The
logAndWait()
method sends a log request to the Log Server and returns a boolean response that indicates whether the log entry was successful. Use this method if you need to make sure a log request is successful.The
logAsynchronously()
method queues up a log request to send to the Log Server asynchronously and without waiting for a response. Using this method can improve performance by preventing the Logging API from holding onto the thread while sending the log entry.
These methods use a LogEntry object as their argument when sending a log request to the Log Server. The following examples show the code to send a log request.
//Send the log request and do not wait for a response. lsc.log(logEntryObject); //Send the log request and wait for a response. lsc.logAndWait(logEntryObject); //Queue the log request and send it asynchronously. lsc.logAsynchronously(logEntryObject);
//Send the log request lsc.log(logEntryObject); //Send the log request and wait for the response. lsc.logAndWait(logEntryObject);
Note
The instantiation of a LogConnection
object does not open a persistent connection to the Log Server, nor does it initiate an HTTP socket connection. Instead, each issuance of the log()
method opens an HTTP socket connection, which is closed after the log request has been sent. For the logAndWait()
method, the HTTP socket connection remains open until the response indicating log entry success or failure is received. For the logAsynchronously()
method, the HTTP socket is not opened until after the method has returned.