|
4112 - in trunk/EventLogDatabaseTiein: docs src/writers [eZComponents: Trun: msg#00285web.ezcomponents.cvs
Author: Alexandru Stanoi Date: 2006-11-28 15:10:30 +0100 (Tue, 28 Nov 2006) New Revision: 4112 Log: - Added a small tutorial. Added: trunk/EventLogDatabaseTiein/docs/tutorial.txt trunk/EventLogDatabaseTiein/docs/tutorial_autoload.php trunk/EventLogDatabaseTiein/docs/tutorial_database.php Modified: trunk/EventLogDatabaseTiein/src/writers/writer_database.php Added: trunk/EventLogDatabaseTiein/docs/tutorial.txt =================================================================== --- trunk/EventLogDatabaseTiein/docs/tutorial.txt 2006-11-28 14:04:46 UTC (rev 4111) +++ trunk/EventLogDatabaseTiein/docs/tutorial.txt 2006-11-28 14:10:30 UTC (rev 4112) @@ -0,0 +1,106 @@ +eZ components - EventLogDatabaseTieIn +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. contents:: Table of Contents + +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. + +.. include:: tutorial_database.php + :literal: + +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" + } + + +.. _EventLog: http://ez.no/doc/components/view/trunk/(file)/introduction_EventLog.html +.. _Database: http://ez.no/doc/components/view/trunk/(file)/introduction_Database.html + + + +.. + Local Variables: + mode: rst + fill-column: 79 + End: + vim: et syn=rst tw=79 Property changes on: trunk/EventLogDatabaseTiein/docs/tutorial.txt ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/EventLogDatabaseTiein/docs/tutorial_autoload.php =================================================================== --- trunk/EventLogDatabaseTiein/docs/tutorial_autoload.php 2006-11-28 14:04:46 UTC (rev 4111) +++ trunk/EventLogDatabaseTiein/docs/tutorial_autoload.php 2006-11-28 14:10:30 UTC (rev 4112) @@ -0,0 +1,20 @@ +<?php +$dir = dirname( __FILE__ ); +$dirParts = split( '/', $dir ); +switch ( $dirParts[count( $dirParts ) - 3] ) +{ + case 'doc': require_once 'ezc/Base/base.php'; break; // pear + case 'trunk': require_once "$dir/../../Base/src/base.php"; break; // svn + default: require_once "$dir/../../Base/src/base.php"; break; // bundle +} + +/** + * Autoload ezc classes + * + * @param string $className + */ +function __autoload( $className ) +{ + ezcBase::autoload( $className ); +} +?> Property changes on: trunk/EventLogDatabaseTiein/docs/tutorial_autoload.php ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/EventLogDatabaseTiein/docs/tutorial_database.php =================================================================== --- trunk/EventLogDatabaseTiein/docs/tutorial_database.php 2006-11-28 14:04:46 UTC (rev 4111) +++ trunk/EventLogDatabaseTiein/docs/tutorial_database.php 2006-11-28 14:10:30 UTC (rev 4112) @@ -0,0 +1,23 @@ +<?php +require_once 'tutorial_autoload.php'; +date_default_timezone_set( "UTC" ); + +// Get the database instance +$db = ezcDbInstance::get(); + +// Get the log instance +$log = ezcLog::getInstance(); + +// Create a database writer attached to the database handler and the table "log" +$writer = new ezcLogDatabaseWriter( $db, "log" ); + +// Specify that log messages will be written to the database +$log->getMapper()->appendRule( new ezcLogFilterRule( new ezcLogFilter, $writer, true ) ); + +// Write a log entry ( message, severity, source, category ) +$log->log( "File '/images/spacer.gif' does not exist.", ezcLog::WARNING, array( "source" => "Application", "category" => "Design" ) ); + +// Write a log entry ( message, severity, source, category, file, line ) +$log->log( "File '/images/spacer.gif' does not exist.", ezcLog::WARNING, array( "source" => "Application", "category" => "Design" ), array( "file" => "/index.php", "line" => 123 ) ); + +?> Property changes on: trunk/EventLogDatabaseTiein/docs/tutorial_database.php ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/EventLogDatabaseTiein/src/writers/writer_database.php =================================================================== --- trunk/EventLogDatabaseTiein/src/writers/writer_database.php 2006-11-28 14:04:46 UTC (rev 4111) +++ trunk/EventLogDatabaseTiein/src/writers/writer_database.php 2006-11-28 14:10:30 UTC (rev 4112) @@ -16,6 +16,9 @@ * // Get the database instance * $db = ezcDbInstance::get(); * + * // Get the log instance + * $log = ezcLog::getInstance(); + * * // Create a new ezcLogDatabaseWriter object based on the database instance * // and with the default table name "log". * // The "log" table must exist already in the database, and must have a compatible structure, @@ -33,13 +36,19 @@ * // source varchar(255) NOT NULL, * // time timestamp NOT NULL * // ); - * $log = new ezcLogDatabaseWriter( $db, "log" ); + * $writer = new ezcLogDatabaseWriter( $db, "log" ); * + * // Specify that log messages will be written to the database + * $log->getMapper()->appendRule( new ezcLogFilterRule( new ezcLogFilter, $writer, true ) ); + * * // Write a log entry ( message, severity, source, category ) - * $log->writeLogMessage( "File /images/spacer.gif does not exist.", ezcLog::WARNING, "Application", "Design" ); + * $log->log( "File '/images/spacer.gif' does not exist.", ezcLog::WARNING, + * array( "source" => "Application", "category" => "Design" ) ); * * // Write a log entry ( message, severity, source, category, file, line ) - * $log->writeLogMessage( "File /images/spacer.gif does not exist.", ezcLog::WARNING, "Application", "Design", array( "file" => "/index.php", "line" => 123 ) ); + * $log->log( "File '/images/spacer.gif' does not exist.", ezcLog::WARNING, + * array( "source" => "Application", "category" => "Design" ), + * array( "file" => "/index.php", "line" => 123 ) ); * </code> * * @property string $table |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | 4111 - in trunk/Template: src tests/regression_tests/array_append tests/regression_tests/array_fetch/incorrect tests/regression_tests/expressions/incorrect_array_fetch [eZComponents: Trunk]: 00285, Jan Borsodi |
|---|---|
| Next by Date: | 4112 - in trunk/EventLogDatabaseTiein: docs src/writers [eZComponents: Docs]: 00285, Alexandru Stanoi |
| Previous by Thread: | 4111 - in trunk/Template: src tests/regression_tests/array_append tests/regression_tests/array_fetch/incorrect tests/regression_tests/expressions/incorrect_array_fetch [eZComponents: Trunk]i: 00285, Jan Borsodi |
| Next by Thread: | 4112 - in trunk/EventLogDatabaseTiein: docs src/writers [eZComponents: Docs]: 00285, Alexandru Stanoi |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |