Showing log entries in the actual sequence they were made

Permalink
I have been playing with code and inserting notes to the Log system to work out what is going on and to debug blocks on my development system. Unfortunately, the standard Log::getList method seems to return them out of sequence. I suspect because on any particular page request they are within a second of each other and so all have the same timestamp, so sorting within a 1 second period is arbitrary and system dependant.

Below is my hack to fix this, changing a copy of Log to sort by timestamp and logID. I suspect that logID alone (without the timestamp) would be just as effective and faster, but for now am just tweaking what is already there rather than changing it.

public static function getList($keywords, $type, $limit) {
   $db = Loader::db();
   if ($keywords != '') {
      $kw = 'and logText like ' . $db->quote('%' . $keywords . '%');
   }
   if ($type != false) {
      $v = array($type);
      $r = $db->Execute('select logID from Logs where logType = ? ' . $kw . ' order by timestamp desc, logID desc limit ' . $limit, $v); // HACK order by logID after timestamp
   } else {
      $r = $db->Execute('select logID from Logs where 1=1 ' . $kw . ' order by timestamp desc, logID desc limit ' . $limit); // HACK order by logID after timestamp
   }
   $entries = array();
   while ($row = $r->FetchRow()) {
      $entries[] = LogEntry::getByID($row['logID']);
   }

JohntheFish