Zeta Components Manual :: Docs For Class ezcLogDatabaseWriter
EventLogDatabaseTiein::ezcLogDatabaseWriter
Class ezcLogDatabaseWriter
The ezcLogDatabaseWriter provides an implementation to write log messages to the database.
Example to use the ezcLogDatabaseWriter:
- // Get the database instance
- // Get the log instance
- // 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,
- // with any additional fields that you may require, eg. you can use this example schema,
- // where the default fields are: id, category, message, severity, source, time
- // and the additional fields are: file, line
- // DROP TABLE IF EXISTS log;
- // 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
- // );
- // Specify that log messages will be written to the database
- // Write a log entry ( message, severity, source, category )
- array( "source" => "Application", "category" => "Design" ) );
- // Write a log entry ( message, severity, source, category, file, line )
- array( "source" => "Application", "category" => "Design" ),
- array( "file" => "/index.php", "line" => 123 ) );
Source for this file: /EventLogDatabaseTiein/src/writers/writer_database.php
Implements interfaces:
Version: | //autogentag// |
Properties
string | read/write |
$category
The name of the column category. |
string | read/write |
$datetime
The name of the column datetime. |
string | read/write |
$message
The name of the column message. |
string | read/write |
$severity
The name of the column severity. |
string | read/write |
$source
The name of the column source. |
string | read/write |
$table
The table name. |
Method Summary
public ezcLogDatabaseWriter |
__construct(
$databaseInstance
, [ $defaultTable
= false] )
Construct a new database log-writer. |
public array(string=>string) |
getColumnTranslations(
)
Returns an array that describes the coupling between the logMessage information and the columns in the database. |
public void |
setTable(
$logFilter
, $tableName
)
Maps the table $tableName to the messages specified by the ezcLogFilter $logFilter. |
public void |
writeLogMessage(
$message
, $severity
, $source
, $category
, [ $optional
= array()] )
Writes the message $message to the log. |
Methods
__construct
Construct a new database log-writer.
If $databaseInstance is given, that instance will be used for writing. If it is omitted the default database instance will be retrieved.
This constructor is a tie-in.
Parameters:
Name | Type | Description |
---|---|---|
$databaseInstance |
ezcDbHandler | |
$defaultTable |
string |
getColumnTranslations
Returns an array that describes the coupling between the logMessage information and the columns in the database.
setTable
Maps the table $tableName to the messages specified by the ezcLogFilter $logFilter.
Log messages that matches with the filter are written to the table $tableName. This method works the same as ezclog::map().
Parameters:
Name | Type | Description |
---|---|---|
$logFilter |
ezcLogFilter | |
$tableName |
string |
writeLogMessage
Writes the message $message to the log.
The writer can use the severity, source, and category to filter the incoming messages and determine the location where the messages should be written.
$optional may contain extra information that can be added to the log. For example: line numbers, file names, usernames, etc.
Parameters:
Name | Type | Description |
---|---|---|
$message |
string | |
$severity |
int | ezcLog:: DEBUG, SUCCES_AUDIT, FAILED_AUDIT, INFO, NOTICE, WARNING, ERROR or FATAL. $param string $source |
$category |
string | |
$optional |
array(string=>string) | |
$source |
Exceptions:
Type | Description |
---|---|
ezcLogWriterException |
If the log writer was unable to write the log message |