_tableStorageConnection = $tableStorageConnection; $this->_tableName = $tableName; // create the logging table if it does not exist. It will add some overhead, so it's optional if ($createTable) { $this->_tableStorageConnection->createTableIfNotExists( $this->_tableName ); } // keep messages to be logged in an internal buffer and only send them over the wire when // the script execution ends if ($bufferMessages) { $this->_bufferMessages = $bufferMessages; } $this->_formatter = new Zend_Service_WindowsAzure_Log_Formatter_WindowsAzure(); } /** * If the log messages have been stored in the internal buffer, just send them * to table storage. */ public function shutdown() { parent::shutdown(); if ($this->_bufferMessages) { $this->_tableStorageConnection->startBatch(); foreach ($this->_messageBuffer as $logEntity) { $this->_tableStorageConnection->insertEntity( $this->_tableName, $logEntity ); } $this->_tableStorageConnection->commit(); } } /** * Create a new instance of Zend_Service_Log_Writer_WindowsAzure * * @param array $config * @return Zend_Service_Log_Writer_WindowsAzure * @throws Zend_Service_Log_Exception */ static public function factory($config) { $config = self::_parseConfig($config); $config = array_merge( array( 'connection' => null, 'tableName' => null, 'createTable' => true, ), $config ); return new self( $config['connection'], $config['tableName'], $config['createTable'] ); } /** * The only formatter accepted is already loaded in the constructor * * @todo enable custom formatters using the WindowsAzure_Storage_DynamicTableEntity class */ public function setFormatter( Zend_Service_Log_Formatter_Interface $formatter ) { #require_once 'Zend/Service/Log/Exception.php'; throw new Zend_Service_Log_Exception( get_class($this) . ' does not support formatting'); } /** * Write a message to the table storage. If buffering is activated, then messages will just be * added to an internal buffer. * * @param array $event * @return void * @todo format the event using a formatted, not in this method */ protected function _write($event) { $logEntity = $this->_formatter->format($event); if ($this->_bufferMessages) { $this->_messageBuffer[] = $logEntity; } else { $this->_tableStorageConnection->insertEntity( $this->_tableName, $logEntity ); } } }