eZ components - EventLog ~~~~~~~~~~~~~~~~~~~~~~~~ .. contents:: Table of Contents Introduction ============ The EventLog component provides an API to log events and audit trails. These events and audit trails are written to files or other storage spaces in various formats. How and where the log messages (events and audit trails) are written depends on the chosen or customized log writer. The available log writers are: - ezcLogDatabaseWriter, which writes log messages to the database. - ezcLogUnixFileWriter, which writes log messages to a file in an 'Unix' file format. Each of these writers can be customized or extended. An incoming log message can be written to zero or more writers. The writers that write the log message depends on the variables of the log message itself and the ezcLogMapper implementation. An implementation of the ezcLogMapper checks the severity, source, and category from the log message and forwards the message to the matching writers. Class overview ============== The following classes are most important to use, customize, or extend: ezcLog The ezcLog is a singleton, meaning that only one instance to the log can exist. This class provides methods to configure and record log messages. The recorded log messages are sent to an implementation of the ezcLogMapper, deciding which writers should write the log message. ezcLogMapper The ezcLogMapper provides an interface for the log message mapping. Log messages are dispatched from the ezcLog to a writer. To which writer a message is dispatched is determined in the class that implements ezclogMapper and is assigned in the ezcLog. ezcLogFilterSet The ezcLogFilterSet is an implementation of the ezcLogMapper. The ezcLogFilterSet contains a set of ezcLogFilterRules. These rules are processed sequentially. The rule assigned first will be processed first. Each rule determines whether the log message matches with the filter rule. If the log message matches, it calls the writer and decide whether the filter set stops processing. The ezclogFilterSet is inspired by modern mail applications regarding the mail filter settings. Normally these mail filter settings sort the incoming mail and stores it in the correct mail folder. ezcLogWriter The ezcLogWriter provides an interface for the writers. An implementation of this interface is a valid writer, and can be addressed by the ezcLogMapper. The writer itself can determine how and where the log message is stored. ezcLogUnixFileWriter The ezcLogUnixFileWriter writes the log message to a file. ezcLogDatabaseWriter The ezcLogDatabaseWriter writes the log message to a database. ezcLogFilter The ezcLogFilter is a structure to specify which log messages are accepted in a filter set. For more information about these classes, see the class documentation. Examples ======== Writing a log message to a file. -------------------------------- This example creates a file writer, and assigns it to the default log mapper. .. include:: tutorial_simple_file_writer.php :literal: First the tutorial_autoload.php is included. The included file loads the correct php files for the EventLog component. Hereafter the log is set up, and a message is written to the log file "default.log" and the file will be placed in the "/tmp/log" directory. After execution, the file "/tmp/log/default.php" contains something like:: Jan 24 14:39:57 [Warning] [default] [default] Could not connect with the payment server. Respectively the date, severity, source, category, and message are shown. The source and category are both set to default, because they were not specified in the message. Assigning sources and categories -------------------------------- The default source and category from the ezcLog can be set via the properties: "source" and "category". The next example demonstrates how the default properties can be set and how extra variables can be added to the log. .. include:: tutorial_sources_categories.php :literal: After execution, the file "/tmp/log/default.php" contains something like:: Jan 24 15:45:04 [Warning] [Payment module] [Template] Could not find cache file: . Jan 24 15:45:04 [Error] [Payment module] [SQL] Cannot execute query: