SOURCECODE |
How to... log the opening and closing of a SalesPoint
Description:
It might be quite useful to log events like the opening or closing of a SalesPoint.
To be able to log these events, the SalesPoint already has the two methods protected void logSalesPointOpened()
and protected void logSalesPointClosed()
, which by default are empty. In order to have the two events logged, you have to make these methods put the right LogEntry into the desired Log.
In this example we only show how to log the opening of the videomachine's Counter. For the other logging it is almost the same procedure, but only in the logSalesPointClosed()
method.
ToDo's:
- Implement the method
protected void logSalesPointOpened()
in your subclass of SalesPoint
- Catch the LogNoOutputStreamException thrown by the getGlobalLog() method and the IOException thrown by the setGlobalOutputStream(OutputStream os), which is being called if no OutputStream exists, in order to create one
- Get the Global Log and put a new Loggable implementation into it's OutputStream by using the method
log(Loggable l)
. In our case it is a new instance of OpenLoggable
For more information on that example, please refer to "How to define a Log", "How to implement the interface Loggable", "How to define a new LogEntry", "How to display log file contents" and for general information please go to "How to understand logging".
Uses:
Log Loggable
1
//define the empty method to log the opening
protected void logSalesPointOpened() {
2
//remember to catch the two Exceptions
try {
3
//get the globalLog and put a new OpenLoggable into it
//this could also be logged into a local log
Log.getGlobalLog().log(new OpenLoggable());
} catch (LogNoOutputStreamException lnose) {
System.out.println(lnose);
} catch (java.io.IOException ie) {
System.out.println(ie);
}
}