webCOMAND

Event Logger

io_comand_log

The COMAND API logs events when there is an error, warning or other information of note about a task or operation that has been performed.

The Event Logger can be used to log your own events as well, either to the same main log COMAND uses, or to your own log.  It is even possible to chain logs together, so you can log to your own log, which in turn could log to the main COMAND log as well.

Logged events can be accessed by code, output to log files on disk, to standard output like the command line interface (CLI), HTML, JSON and other formats.

Events

An event log contains a simple array of events, but each event can have child events to represent a hierarchy.  Each logged event has the following information.

  • Timestamp - The time the event occurred in Unix time format, as returned by time::get_time().
  • Type - The type of event (ie. ERROR, WARNING or NOTICE).
  • Message - String of text that represents the main information about this event.
  • Children - Array of zero or more additional events subordinate to this event.
  • Extra - Variable containing additional information.  No specific type of format is required and it is up to the application that logged the event to interpret this information.

Repository System Log

The most commonly used event log is the repository System Log, which can be accessed with the repo::SystemLog property.  Any errors and other events logged by a query or other repository operation are logged to the System Log, which can be inspected or output.  Events logged from the last operation can be accessed with repo::get_last_action_log().

Example

$repo = comand::repo();

$repo->log_notice("This will log a NOTE.");

$collection = $repo->get("SELECT InvalidField FROM BogusType");
if($collection === FALSE) {
    echo("Last Action Log:" . $repo->get_last_action_log()->as_html());
    $repo->log_error("Query failed.");
}

echo("Entire System Log:" . $repo->SystemLog->as_html());