+++ /dev/null
-<?php
-/**
- * Horde Log package
- *
- * This package is based on Zend_Log from the Zend Framework
- * (http://framework.zend.com). Both that package and this
- * one were written by Mike Naberezny and Chuck Hagenbuch.
- *
- * @author Mike Naberezny <mike@maintainable.com>
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @license http://opensource.org/licenses/bsd-license.php BSD
- * @package Log
- * @subpackage Handlers
- */
-
-/**
- * @author Mike Naberezny <mike@maintainable.com>
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @license http://opensource.org/licenses/bsd-license.php BSD
- * @package Log
- * @subpackage Handlers
- */
-class Horde_Log_Handler_Db extends Horde_Log_Handler_Base
-{
- /**
- * Database adapter instance.
- *
- * @var Horde_Db_Adapter
- */
- private $_db;
-
- /**
- * Name of the log table in the database.
- *
- * @var string
- */
- private $_table;
-
- /**
- * Options to be set by setOption().
- * Sets the field names in the database table.
- *
- * @var array
- */
- protected $_options = array(
- 'fieldMessage' => 'message',
- 'fieldLevel' => 'level'
- );
-
- /**
- * Constructor.
- *
- * @param Horde_Db_Adapter $db Database adapter instance.
- * @param string $table Log table in database.
- */
- public function __construct($db, $table)
- {
- $this->_db = $db;
- $this->_table = $table;
- }
-
- /**
- * Write a message to the log.
- *
- * @param array $event Log event.
- *
- * @return bool True.
- */
- public function write($event)
- {
- $fields = array(
- $this->_options['fieldMessage'] => $event['message'],
- $this->_options['fieldLevel'] => $event['level'],
- );
-
- $this->_db->insert($this->_table, $fields);
-
- return true;
- }
-
-}
</dir> <!-- /lib/Horde/Log/Formatter -->
<dir name="Handler">
<file name="Base.php" role="php" />
- <file name="Db.php" role="php" />
<file name="Firebug.php" role="php" />
<file name="Mock.php" role="php" />
<file name="Null.php" role="php" />
<install name="lib/Horde/Log/Formatter/Xml.php" as="Horde/Log/Formatter/Xml.php" />
<install name="lib/Horde/Log/Formatter.php" as="Horde/Log/Formatter.php" />
<install name="lib/Horde/Log/Handler/Base.php" as="Horde/Log/Handler/Base.php" />
- <install name="lib/Horde/Log/Handler/Db.php" as="Horde/Log/Handler/Db.php" />
<install name="lib/Horde/Log/Handler/Firebug.php" as="Horde/Log/Handler/Firebug.php" />
<install name="lib/Horde/Log/Handler/Mock.php" as="Horde/Log/Handler/Mock.php" />
<install name="lib/Horde/Log/Handler/Null.php" as="Horde/Log/Handler/Null.php" />
+++ /dev/null
-<?php
-/**
- * Horde Log package
- *
- * This package is based on Zend_Log from the Zend Framework
- * (http://framework.zend.com). Both that package and this
- * one were written by Mike Naberezny and Chuck Hagenbuch.
- *
- * @author Mike Naberezny <mike@maintainable.com>
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @license http://opensource.org/licenses/bsd-license.php BSD
- * @package Log
- * @subpackage UnitTests
- */
-
-/**
- * @author Mike Naberezny <mike@maintainable.com>
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @license http://opensource.org/licenses/bsd-license.php BSD
- * @package Log
- * @subpackage UnitTests
- */
-class Horde_Log_Handler_DbTest extends PHPUnit_Framework_TestCase
-{
- public function setUp()
- {
- $this->tableName = 'db-table-name';
-
- $this->db = new Horde_Log_Handler_DbTest_MockDbAdapter();
- $this->handler = new Horde_Log_Handler_Db($this->db, $this->tableName);
- }
-
- public function testWriteWithDefaults()
- {
- // log to the mock db adapter
- $message = 'message-to-log';
- $level = 2;
- $this->handler->write(array('message' => $message, 'level' => $level));
-
- // insert should be called once...
- $this->assertContains('insert', array_keys($this->db->calls));
- $this->assertEquals(1, count($this->db->calls['insert']));
-
- // ...with the correct table and binds for the database
- $binds = array('message' => $message,
- 'level' => $level);
- $this->assertEquals(array($this->tableName, $binds),
- $this->db->calls['insert'][0]);
- }
-
- public function testWriteUsesOptionalCustomColumns()
- {
- $this->handler->setOption('fieldMessage', $messageField = 'new-message-field');
- $this->handler->setOption('fieldLevel', $levelField = 'new-level-field');
-
- // log to the mock db adapter
- $message = 'message-to-log';
- $level = 2;
- $this->handler->write(array('message' => $message, 'level' => $level));
-
- // insert should be called once...
- $this->assertContains('insert', array_keys($this->db->calls));
- $this->assertEquals(1, count($this->db->calls['insert']));
-
- // ...with the correct table and binds for the database
- $binds = array($messageField => $message,
- $levelField => $level);
- $this->assertEquals(array($this->tableName, $binds),
- $this->db->calls['insert'][0]);
- }
-}
-
-
-class Horde_Log_Handler_DbTest_MockDbAdapter
-{
- public $calls = array();
-
- public function __call($method, $params)
- {
- $this->calls[$method][] = $params;
- }
-}