LogRecord stores two types of logs.
This code executes an update operation and examines the log records for the Customer MBO:
int id = 101; Customer result = Customer.findById(id); result.setFname("newFname"); result.save(); result.submitPending(); SMP101DB.synchronize(); result = Customer.findById(id); ObjectList logs = result.getLogRecords(); for (int i = 0; i < logs.count(); i ) { com.sybase.persistence.LogRecord logRecord = (com.sybase.persistence.LogRecord)logs.elementAt(i); // working with logRecord }
The code in the log record is an HTTP status code. See Developer Guide: BlackBerry Object API Applications >Client Object API Usage >Exceptions > Handling Exceptions > HTTP Error Codes.
There is no logRecord generated for a successful operation replay. The SAP Mobile Server only creates a logRecord when an operation fails or completes with warnings.
This sample code shows how to find the corresponding MBO with the LogRecord and to delete the log record when a record is processed.
private void processLogRecords() { Query query = new Query(); ObjectList logRecords = SMP101DB.getLogRecords(query); for(int i = 0; i < logRecords.size(); ++i) { LogRecord log = (LogRecord)logRecords.elementAt(i); // log warning message Log.warning("log " + log.getComponent() + ":" + log.getEntityKey() + " code:" + log.getCode() + " msg:" + log.getMessage()); if (log.getComponent().equals("Customer")) { long surrogateKey = Long.parseLong(log.getEntityKey()); Customer c = Customer.find(surrogateKey); if (c.isPending()) { c.cancelPending(); } log.delete(); log.submitPending(); } } SMP101DB.beginSynchronize(null, null); }
private void processLogs() { Query query = new Query(); GenericList<LogRecord> logRecords = SMP101DB.getLogRecords(query); for(LogRecord log : logRecords) { // log warning message Log.warning("log " + log.getComponent() + ":" + log.getEntityKey() + " code:" + log.getCode() + " msg:" + log.getMessage()); if (log.getComponent().equals("Customer")) { long surrogateKey = Long.parseLong(log.getEntityKey()); Customer c = Customer.find(surrogateKey); if (c.isPending()) { c.cancelPending(); } // delete the LogRecord after it is processed log.delete(); log.submitPending(); } }SAP Mobile Server is responsible for deleting client log records uploaded by the application. These application logs are used for audit and/or support services. Determine and set the retention policy from SAP Control Center after consulting with the application's developers. If there are multiple applications using the same package, retain them based on the maximum required time for each application. Client log records are removed that are outside the retention window, and deleted records removed from the client database the next time the application synchronizes. See Improve Synchronization Performance by Reducing the Log Record Size in Troubleshooting for details about reducing the Log Record size.