Path

ez components / documentation / api reference / 2006.2 / event


eZ Components 2006.2

EventLogDatabaseTiein

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Introduction

The EventLogDatabaseTieIn component provides an API to log events and audit trails using a database connection. See EventLog and Database for more information about the components for which this package is a tie-in.

The available log writers are:

  • ezcLogDatabaseWriter, which writes log messages to the database.

To write log messages to the database, the Database component is used. The table to which the log is written should already exist.

Class overview

The following classes are most important to use, customize, or extend:

ezcLogDatabaseWriter
The ezcLogDatabaseWriter writes the log message to a database.

For more information about these classes, see the class documentation.

Examples

Writing to a database

In this example, an MySQL database is used for writing log messages. The database "app" and the table "log" should already exist. The table should at least contain the columns: time, message, severity, source, category.

  1. <?php
  2. require_once 'tutorial_autoload.php';
  3. date_default_timezone_set"UTC" );
  4. 
  5. // Get the database instance
  6. $db ezcDbInstance::get();
  7. 
  8. // Get the log instance
  9. $log ezcLog::getInstance();
 10. 
 11. // Create a database writer attached to the database handler and the table "log"
 12. $writer = new ezcLogDatabaseWriter$db"log" );
 13. 
 14. // Specify that log messages will be written to the database
 15. $log->getMapper()->appendRule( new ezcLogFilterRule( new ezcLogFilter$writertrue ) );
 16. 
 17. // Write a log entry ( message, severity, source, category )
 18. $log->log"File '/images/spacer.gif' does not exist."ezcLog::WARNING, array( "source" => "Application""category" => "Design" ) );
 19. 
 20. // Write a log entry ( message, severity, source, category, file, line )
 21. $log->log"File '/images/spacer.gif' does not exist."ezcLog::WARNING, array( "source" => "Application""category" => "Design" ), array( "file" => "/index.php""line" => 123 ) );
 22. 
 23. ?>

An example sql query to create the table:

CREATE TABLE log (
    category varchar(255) NOT NULL,
    file varchar(255),
    id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY,
    line bigint,
    message varchar(255) NOT NULL,
    severity varchar(255) NOT NULL,
    source varchar(255) NOT NULL,
    time timestamp NOT NULL
);

The log table will have rows similar to:

array(16) {
  ["category"]=>
  string(6) "Design"
  [0]=>
  string(6) "Design"
  ["file"]=>
  NULL
  [1]=>
  NULL
  ["id"]=>
  string(1) "1"
  [2]=>
  string(1) "1"
  ["line"]=>
  NULL
  [3]=>
  NULL
  ["message"]=>
  string(41) "File '/images/spacer.gif' does not exist."
  [4]=>
  string(41) "File '/images/spacer.gif' does not exist."
  ["severity"]=>
  string(7) "Warning"
  [5]=>
  string(7) "Warning"
  ["source"]=>
  string(11) "Application"
  [6]=>
  string(11) "Application"
  ["time"]=>
  string(19) "2006-11-28 14:21:32"
  [7]=>
  string(19) "2006-11-28 14:21:32"
}
Last updated: Thu, 01 Nov 2007