00001 <?php 00024 require_once 'Zend/Log/Writer/Abstract.php'; 00025 00034 class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract 00035 { 00040 private $_db; 00041 00046 private $_table; 00047 00053 private $_columnMap; 00054 00062 public function __construct($db, $table, $columnMap = null) 00063 { 00064 $this->_db = $db; 00065 $this->_table = $table; 00066 $this->_columnMap = $columnMap; 00067 } 00068 00072 public function setFormatter($formatter) 00073 { 00074 require_once 'Zend/Log/Exception.php'; 00075 throw new Zend_Log_Exception(get_class() . ' does not support formatting'); 00076 } 00077 00083 public function shutdown() 00084 { 00085 $this->_db = null; 00086 } 00087 00094 protected function _write($event) 00095 { 00096 if ($this->_db === null) { 00097 require_once 'Zend/Log/Exception.php'; 00098 throw new Zend_Log_Exception('Database adapter is null'); 00099 } 00100 00101 if ($this->_columnMap === null) { 00102 $dataToInsert = $event; 00103 } else { 00104 $dataToInsert = array(); 00105 foreach ($this->_columnMap as $columnName => $fieldKey) { 00106 $dataToInsert[$columnName] = $event[$fieldKey]; 00107 } 00108 } 00109 00110 $this->_db->insert($this->_table, $dataToInsert); 00111 } 00112 00113 }