Loading Log events from the database
Since the LogEvent class extends the Item class, and the LogEvents class extends the Items class, you can use them to load lists of LogEvent objects from the database to work with.
For example, let's load the last fifty LogEvent objects from the Log database, using what we learned in the Item lists section of the Items guide:
$logEvents = new \Cherrycake\Log\LogEvents([
"p" => [
"limit" => 50
foreach ($logEvents as $logEvent) {
"[".$e->Locale->formatTimestamp($logEvent->dateAdded, ["isHours" => true, "isSeconds" => true])."] ".
The LogEvents class accepts some additional keys on top of the usual Items::fillFromParameters keys:
  • type Retrieves only LogEvent objects of this class name. Must include the full namespace route to the class.
  • fromTimestamp Retrieves LogEvent objects triggered after this timestamp.
  • toTimestamp Retrieves LogEvent objects triggered up to this timestamp.
[5/26/20 11:22.24] CherrycakeApp\LogEventMovieSearch
[5/26/20 10:55.28] CherrycakeApp\LogEventMovieSearch
[5/26/20 10:55.25] CherrycakeApp\LogEventMovieSearch
See this example working in the Cherrycake documentation examples site.
Copy link