SOURCECODE

How to... implement the interface Loggable


Description:
In order to be able to log anything, i.e. to put a LogEntry into the LogOutputStream, you have to implement the interface Loggble, which hands over the LogEntry to the Log. This can be done within the class, you want to log an event in, but also in an extra class implementing the interface. Such an extra class may of course be used form anywhere within the application. The second advantage is that you don't have to define conditions for different events in the getLogData method, but use seperate Loggable implementations for each event to be logged.
The method public LogEntry getLogData() resolves the LogEntry that shall be put into the LogOutputStream.
The implementation of Loggable here is used to log the opening of a SalesPoint by returning the OpenLogEntry, which was written for the event of opening a SalesPoint. For more information on that, please refer to "How to define a LogEntry".

ToDo's:
  1. Create a new class, implementing Loggable
  2. Implement the getLogData() method to return the right LogEntry for the logged event. Here it is the OpenLogEntry
  3. Use the instance with Log.log(Loggable l) where you want to put the LogEntry into the LogOutputStream


Uses:
Loggable  LogEntry  



SourceCode

import log.*;

 1
//Here we use a new class to implement Loggable
//in order to have a seperate implementation of Loggable for the OpenLogEntry
public class OpenLoggable implements Loggable {

     2
    //This method just returns a new instance of OpenLogEntry
    //which is what will be put into the LogOutputstream
    //when calling Log.log(new OpenLoggable())
    public LogEntry getLogData() {
        return new OpenLogEntry();
    }
}