## Apache 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:

1. // Get the database instance
2. $db=ezcDbInstance :: get ();
4. // Get the log instance
5. $log=ezcLog :: getInstance ();
7. // Create a new ezcLogDatabaseWriter object based on the database instance
8. // and with the default table name "log".
9. // The "log" table must exist already in the database, and must have a compatible structure,
10. // with any additional fields that you may require, eg. you can use this example schema,
11. // where the default fields are: id, category, message, severity, source, time
12. // and the additional fields are: file, line
13. // DROP TABLE IF EXISTS log;
14. // CREATE TABLE log (
15. //   category varchar(255) NOT NULL,
16. //   file varchar(255),
17. //   id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY,
18. //   line bigint,
19. //   message varchar(255) NOT NULL,
20. //   severity varchar(255) NOT NULL,
21. //   source varchar(255) NOT NULL,
22. //   time timestamp NOT NULL
23. // );
24. $writer=new ezcLogDatabaseWriter ($db,"log");
26. // Specify that log messages will be written to the database
27. $log->getMapper()->appendRule(new ezcLogFilterRule (new ezcLogFilter ,$writer,true) );
29. // Write a log entry ( message, severity, source, category )
30. $log-> log ("File '/images/spacer.gif' does not exist.", ezcLog ::WARNING,
31. array("source"=>"Application","category"=>"Design") );
33. // Write a log entry ( message, severity, source, category, file, line )
34. $log-> log ("File '/images/spacer.gif' does not exist.", ezcLog ::WARNING,
35. array("source"=>"Application","category"=>"Design"),
36. array("file"=>"/index.php","line"=>123) );

Source for this file: /EventLogDatabaseTiein/src/writers/writer_database.php

### Implements interfaces:

- ezcLogWriter

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

ezcLogDatabaseWriter __construct( $databaseInstance , [string $defaultTable = false] )

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

array(string=>string) getColumnTranslations( )

Returns an array that describes the coupling between the logMessage information and the columns in the database.

#### setTable

void setTable( $logFilter , string $tableName )

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

void writeLogMessage( string $message , int $severity , $source , string $category , [array(string=>string) $optional = array()] )

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

Documentation generated by phpDocumentor 1.4.3