SOURCECODE |
How to... display log file contents
Description:
In a logfile you can log any event of your framework-application, wether it is a commited process or a rollback, a User logging on, a wrong password entered, just anything.
To display a logfile in a FormSheet, use the LogTableForm, which is a subclass of FormSheet and contains a JLogTable. Remember that the information in that table is being read at creation time and won't be updated when the logfile changes.
In this example we take a look at the LogTableForm in the Action() of a MenuItem in the Office.
ToDo's:
- Create a FileInputStream to process the logfile
- Lead that stream into the LogInputStream which will look at the chosen file as a logfile
- Initialize a new LogTableForm that is made for displaying LogInputStreams
- Set the LogTableForm to the FormSheet of the Salespoint by calling setFormSheet(SaleProcess sp, FormSheet fs)
- Catch the FileNotFoundEception
- Catch the IOException
- And finally catch the InterruptedException
//create a new MenuSheetItem to be displayed in the submenu
MenuSheetItem msi2 = new MenuSheetItem (
"See log file", //the caption
new sale.Action() {
//the action to be performed when the MenuSheetItem is being chosen
//as you can see, such an action can also be quite complex and
//even contain FormSheets and dialogs
public void doAction (SaleProcess p, SalesPoint sp) {
try {
1
//create a FileInputStream
FileInputStream fis = new FileInputStream ("machine.log");
2
//hand it over to a LogInputStream
LogInputStream lis = new LogInputStream (fis);
3
//and finally have the stream being displayed on the LogTableForm
LogTableForm ltf = new LogTableForm ("View log file", lis);
//no logfile specific action. just a removal of the cancelbutton
ltf.removeButton (FormSheet.BTNID_CANCEL);
4
//setup the window with the LogTableForm
setFormSheet (null, ltf);
//looks like lots of exceptions to be caught,
//but only the three of them refer to the InputStreams,
//the InterruptedExceptions (except number 8) belong to the setFormSheet(...) method
5
//this
} catch (FileNotFoundException fnfexc) {
//this
try {
setFormSheet(null, new MsgForm("Error", "Log file not found."));
} catch (InterruptedException iexc) {
System.out.println(iexc);
}
6
//this
} catch (IOException ioexc) {
try {
setFormSheet( null,
new MsgForm("Error",
"Log file corrupt. It might be empty."));
} catch (InterruptedException iexc) {
System.out.println(iexc);
}
7
//and this
} catch (InterruptedException iexc) {
try {
setFormSheet (null, new MsgForm ("Error", iexc.toString()));
} catch (InterruptedException iexc2) {
System.out.println(iexc2);
}
}
}
});
//add the MenuSheetItem to the msSubMenu
msSubMenu.add(msi2);