01: package fr.aliacom.dbmjui;
02:
03: import java.text.SimpleDateFormat;
04: import java.util.Date;
05:
06: import com.sap.dbtech.powertoys.DBMException;
07: import com.sap.dbtech.rte.comm.RTEException;
08:
09: import fr.aliacom.common.ui.ITable;
10: import fr.aliacom.dbmjui.beans.ErrorLogEntry;
11: import fr.aliacom.form.common.IForm;
12: import fr.aliacom.form.common.ToolkitManager;
13:
14: /**
15: * @author tom
16: *
17: * (c) 2001, 2003 Thomas Cataldo
18: */
19: public final class UILogger {
20:
21: private static ITable logs;
22: private static SimpleDateFormat sdf;
23:
24: static {
25: // get the logger
26: IForm win = ToolkitManager.getToolkit().getMainWindow();
27: logs = (ITable) win.getFormContext().get("logs").getValue();
28: sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
29: }
30:
31: public static void log(String dbName, DBMException dbme) {
32: ErrorLogEntry ele = new ErrorLogEntry();
33: ele.setErrorCode("" + dbme.getErrorCode());
34: ele.setDescription(getErrorString(dbme));
35: ele.setSeverity(ErrorLogEntry.WARNING_SEVERITY);
36: addEntry(dbName, ele);
37: }
38:
39: public static void log(String dbName, RTEException rtee) {
40: ErrorLogEntry ele = new ErrorLogEntry();
41: ele.setErrorCode("" + rtee.getDetailErrorCode());
42: ele.setDescription(getErrorString(rtee));
43: ele.setSeverity(ErrorLogEntry.ERROR_SEVERITY);
44: addEntry(dbName, ele);
45: }
46:
47: public static void log(String dbName, Exception e) {
48: ErrorLogEntry ele = new ErrorLogEntry();
49: ele.setDescription(e.getMessage());
50: ele.setSeverity(ErrorLogEntry.ERROR_SEVERITY);
51: addEntry(dbName, ele);
52: }
53:
54: private static void addEntry(String dbName, ErrorLogEntry ele) {
55: ele.setDatabase(dbName);
56: ele.setDateTime(sdf.format(new Date()));
57: logs.addRow(ele);
58: }
59:
60: private static String getErrorString(Exception e) {
61: String str = e.toString();
62: int idx = str.indexOf(' ');
63: String ret = str.substring(idx + 1, str.length() - 1);
64: return ret;
65: }
66:
67: }
|