使用/不使用自定义助手在 Zend_Cache/Zend_Registry 中存储 Zend_Log 实例

发布于 2024-11-28 06:17:13 字数 18391 浏览 2 评论 0原文

我试图将 Zend_Log 的实例(使用 Zend_Log_Writer_Stream)存储到 Zend_Cache(最好)或 Zend_Registry(后备),但使用自定义助手作为抽象层而不是直接访问。

问题

  • 除了直接使用 Zend_Registry 时,每次 Zend_Log_Writer_Stream 的 _stream 属性都会消失。

我在下面附上了我的代码及其生成的输出。

我没有遵循这些 链接 因为我有另一个作家 Zend_Log_Writer_Database它写入与应用程序不同的数据库,所以我需要对其进行初始化。现在我已经将其注释掉了。

Bootstrap.php - 剪辑

    protected function _initLog() {
        // instantiate CacheOrRegistry variable.
        $this->_cor = Helper_SCacheOrRegistry::getInstance();

        // make sure its not already cached and config for this resource exists.
        if ($this->_cor->exists('logger') || !($config = $this->_config->resources->log))
            return;


        $logger = new Zend_Log();
        $config = $config->toArray();

        /*

    if (isset($config['db']) && is_array($config['db'])) {
        $dbParams = $config['db'];
        $writerDb = new Zend_Log_Writer_Db(
                        $this->_cor->get('logDb'),
                        $dbParams['writerParams']['table'],
                        $dbParams['writerParams']['columnMapping']);

        if (isset($dbParams['filterName'])) {

            switch ($dbParams['filterName']) {
                case 'Priority':
                    $writerDb->addFilter(new Zend_Log_Filter_Priority($dbParams['filterParams']['priority']));
                    break;
            }
        }

        $logger->addWriter($writerDb);
    }
    */

        if( 'development' === APPLICATION_ENV) {
        $fileParams = $this->_options['resources']['log']['file'];
        if(!isset($fileParams) || !(is_array($fileParams)))
            return;

        $writerFile = new Zend_Log_Writer_Stream($fileParams['writerParams']['path'],$fileParams['writerParams']['mode']);
        $writerFile->setFormatter(new Zend_Log_Formatter_Simple($fileParams['writerParams']['format']));

        if (isset($fileParams['filterName'])) {
            switch ($fileParams['filterName']) {
                case 'Priority':
                    $writerFile->addFilter(new Zend_Log_Filter_Priority($fileParams['filterParams']['priority']));
                    break;
            }
        }

        $logger->addWriter($writerFile);
        }



        $logger->setEventItem('user_agent', $_SERVER['HTTP_USER_AGENT']);
        $logger->setEventItem('get_vars', serialize($_GET));
        $logger->setEventItem('post_vars', serialize($_POST));
        $logger->setEventItem('ip', $_SERVER['REMOTE_ADDR']);
        $logger->setEventItem('username', $this->_username);



        // This has issue of missing _stream, Using Custom Helper with Registry use force.
        $this->_cor->set('logger', $logger, true);
        $loggerRC = $this->_cor->get('logger', true);

        // This also has issue of missing _stream, Using Custom Helper with apc Cache
        $this->_cor->set('logger', $logger);
        $loggerCC = $this->_cor->get('logger');

        // This works perfectly.
        Zend_Registry::set($this->_cor->createCacheId('loggerR'), $logger);
        $loggerZ = Zend_Registry::get($this->_cor->createCacheId('loggerR'));

        // This also seems to have issue of missing _stream, Using apc Cache directly
        $cache = Zend_Registry::get('apcCache');
        $cache->save($logger, $this->_cor->createCacheId('loggerC'));
        $loggerC = $cache->load($this->_cor->createCacheId('loggerC'));


        echo "<h3>Logger, local variable</h3>";
        var_dump($logger);

        echo "<h3>Logger, from Registry using custom helper</h3>";
        var_dump($loggerRC);

        echo "<h3>Logger, from apc cache using custom helper</h3>";
        var_dump($loggerCC);

        echo "<h3>Logger, from Zend_Registry, direct.</h3>";
        var_dump($loggerZ);

        echo "<h3>Logger, from apc Cache, Direct.</h3>";
        var_dump($loggerC);
        exit;
    }

Helper_SCacheOrRegistry.php

class Helper_SCacheOrRegistry {

    private $_source;
    private static $_instance;
    private $_functionsArray = array('Cache' => array(
            'get' => '_getFromCache',
            'set' => '_saveInCache',
            'del' => '_deleteFromCache',
            'exists' => '_existsInCache'),
        'Registry' => array(
            'get' => '_getFromRegistry',
            'set' => '_saveInRegistry',
            'del' => '_deleteFromRegistry',
            'exists' => '_existsInRegistry',
        )
    );

    public static function getInstance() {
        if (!isset(self::$_instance)) {
            $c = __CLASS__;
            self::$_instance = new $c();
        }

        return self::$_instance;
    }


    private  function _getSource($forceRegistry = null) {
        if(true === $forceRegistry)
            return Zend_Registry::getInstance();

        if (Zend_Registry::getInstance()->offsetExists('apcCache'))
            return Zend_Registry::get('apcCache');
        else
            return Zend_Registry::getInstance();

    }

    private  function _isSourceCache() {
        return (!$this->_source instanceof Zend_Registry);
    }

    public function createCacheId($id) {
        return md5(',e@Q!u$#~\|3Pa^e1%oh&s0*<h(7)o-+h/t.' . $id);
    }

    public function set($key, $value, $forceRegistry = null) {
        $this->_fire('set', $this->createCacheId($key), $value, $forceRegistry);
    }

    public function get($key, $forceRegistry = null) {
        return $this->_fire('get', $this->createCacheId($key), null, $forceRegistry);
    }

    public function del($key, $forceRegistry = null) {
        return $this->_fire('del', $this->createCacheId($key), null, $forceRegistry);
    }

    public function exists($key, $forceRegistry = null) {
        return $this->_fire('exists', $this->createCacheId($key), null, $forceRegistry);
    }

    private  function _fire($method, $key, $value = null, $forceRegistry = null) {


        $this->_source = $this->_getSource($forceRegistry);
        $call = ($this->_isSourceCache()) ?
                $this->_functionsArray['Cache'][$method] : $this->_functionsArray['Registry'][$method];

        return (isset($value)) ? $this->$call($key, $value) : $this->$call($key);
    }

    private  function _getFromCache($key) {
        return $this->_existsInCache($key);
    }

    private  function _saveInCache($key, $value) {
        if ($this->_existsInCache($key))
            return false;

        $this->_source->save($value, $key);
        return true;
    }

    private  function _deleteFromCache($key) {
        if (!$this->_existsInCache($key))
            return false;

        $this->_source->remove($key);
        return true;
    }

    private  function _existsInCache($key) {
        return $this->_source->load($key);
    }

    private  function _getFromRegistry($key) {
        if ($this->_existsInRegistry($key))
            return unserialize($this->_source->get($key));

        return false;
    }

    private  function _saveInRegistry($key, $value) {
        if ($this->_existsInRegistry($key))
            return false;

        $this->_source->set($key, serialize($value));
        return true;
    }

    private  function _deleteFromRegistry($key) {
        if (!$this->_existsInCache($key))
            return false;

        $this->_source->offsetUnset($key);
        return true;
    }

    private  function _existsInRegistry($key) {
        return $this->_source->isRegistered($key);
    }

}

输出:

记录器,局部变量

object(Zend_Log)[84]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[93]
          protected '_stream' => resource(77, stream)
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[94]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[95]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

记录器,使用自定义帮助程序从注册表

object(Zend_Log)[96]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[97]
          protected '_stream' => int 0
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[98]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[99]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

< strong>记录器,使用自定义帮助程序从 apc 缓存

object(Zend_Log)[100]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[101]
          protected '_stream' => int 0
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[102]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[103]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

记录器,来自 Zend_Registry,直接。

object(Zend_Log)[84]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[93]
          protected '_stream' => resource(77, stream)
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[94]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[95]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

记录器,来自 apc 缓存,直接。

object(Zend_Log)[104]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[105]
          protected '_stream' => int 0
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[106]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[107]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

I am trying to store an instance of Zend_Log (with Zend_Log_Writer_Stream) to Zend_Cache(preferably) or Zend_Registry(fallback) but with the custom helper as an abstraction layer instead of direct access.

Problem

  • Except when using Zend_Registry directly, everytime Zend_Log_Writer_Stream's _stream property disappears.

I have attached my code below along with the output it generates.

I am not following these links because I have another writer Zend_Log_Writer_Database that writes to a separate database than application so i need to initialize that. For now i have commented it out.

Bootstrap.php - clipped

    protected function _initLog() {
        // instantiate CacheOrRegistry variable.
        $this->_cor = Helper_SCacheOrRegistry::getInstance();

        // make sure its not already cached and config for this resource exists.
        if ($this->_cor->exists('logger') || !($config = $this->_config->resources->log))
            return;


        $logger = new Zend_Log();
        $config = $config->toArray();

        /*

    if (isset($config['db']) && is_array($config['db'])) {
        $dbParams = $config['db'];
        $writerDb = new Zend_Log_Writer_Db(
                        $this->_cor->get('logDb'),
                        $dbParams['writerParams']['table'],
                        $dbParams['writerParams']['columnMapping']);

        if (isset($dbParams['filterName'])) {

            switch ($dbParams['filterName']) {
                case 'Priority':
                    $writerDb->addFilter(new Zend_Log_Filter_Priority($dbParams['filterParams']['priority']));
                    break;
            }
        }

        $logger->addWriter($writerDb);
    }
    */

        if( 'development' === APPLICATION_ENV) {
        $fileParams = $this->_options['resources']['log']['file'];
        if(!isset($fileParams) || !(is_array($fileParams)))
            return;

        $writerFile = new Zend_Log_Writer_Stream($fileParams['writerParams']['path'],$fileParams['writerParams']['mode']);
        $writerFile->setFormatter(new Zend_Log_Formatter_Simple($fileParams['writerParams']['format']));

        if (isset($fileParams['filterName'])) {
            switch ($fileParams['filterName']) {
                case 'Priority':
                    $writerFile->addFilter(new Zend_Log_Filter_Priority($fileParams['filterParams']['priority']));
                    break;
            }
        }

        $logger->addWriter($writerFile);
        }



        $logger->setEventItem('user_agent', $_SERVER['HTTP_USER_AGENT']);
        $logger->setEventItem('get_vars', serialize($_GET));
        $logger->setEventItem('post_vars', serialize($_POST));
        $logger->setEventItem('ip', $_SERVER['REMOTE_ADDR']);
        $logger->setEventItem('username', $this->_username);



        // This has issue of missing _stream, Using Custom Helper with Registry use force.
        $this->_cor->set('logger', $logger, true);
        $loggerRC = $this->_cor->get('logger', true);

        // This also has issue of missing _stream, Using Custom Helper with apc Cache
        $this->_cor->set('logger', $logger);
        $loggerCC = $this->_cor->get('logger');

        // This works perfectly.
        Zend_Registry::set($this->_cor->createCacheId('loggerR'), $logger);
        $loggerZ = Zend_Registry::get($this->_cor->createCacheId('loggerR'));

        // This also seems to have issue of missing _stream, Using apc Cache directly
        $cache = Zend_Registry::get('apcCache');
        $cache->save($logger, $this->_cor->createCacheId('loggerC'));
        $loggerC = $cache->load($this->_cor->createCacheId('loggerC'));


        echo "<h3>Logger, local variable</h3>";
        var_dump($logger);

        echo "<h3>Logger, from Registry using custom helper</h3>";
        var_dump($loggerRC);

        echo "<h3>Logger, from apc cache using custom helper</h3>";
        var_dump($loggerCC);

        echo "<h3>Logger, from Zend_Registry, direct.</h3>";
        var_dump($loggerZ);

        echo "<h3>Logger, from apc Cache, Direct.</h3>";
        var_dump($loggerC);
        exit;
    }

Helper_SCacheOrRegistry.php

class Helper_SCacheOrRegistry {

    private $_source;
    private static $_instance;
    private $_functionsArray = array('Cache' => array(
            'get' => '_getFromCache',
            'set' => '_saveInCache',
            'del' => '_deleteFromCache',
            'exists' => '_existsInCache'),
        'Registry' => array(
            'get' => '_getFromRegistry',
            'set' => '_saveInRegistry',
            'del' => '_deleteFromRegistry',
            'exists' => '_existsInRegistry',
        )
    );

    public static function getInstance() {
        if (!isset(self::$_instance)) {
            $c = __CLASS__;
            self::$_instance = new $c();
        }

        return self::$_instance;
    }


    private  function _getSource($forceRegistry = null) {
        if(true === $forceRegistry)
            return Zend_Registry::getInstance();

        if (Zend_Registry::getInstance()->offsetExists('apcCache'))
            return Zend_Registry::get('apcCache');
        else
            return Zend_Registry::getInstance();

    }

    private  function _isSourceCache() {
        return (!$this->_source instanceof Zend_Registry);
    }

    public function createCacheId($id) {
        return md5(',e@Q!u$#~\|3Pa^e1%oh&s0*<h(7)o-+h/t.' . $id);
    }

    public function set($key, $value, $forceRegistry = null) {
        $this->_fire('set', $this->createCacheId($key), $value, $forceRegistry);
    }

    public function get($key, $forceRegistry = null) {
        return $this->_fire('get', $this->createCacheId($key), null, $forceRegistry);
    }

    public function del($key, $forceRegistry = null) {
        return $this->_fire('del', $this->createCacheId($key), null, $forceRegistry);
    }

    public function exists($key, $forceRegistry = null) {
        return $this->_fire('exists', $this->createCacheId($key), null, $forceRegistry);
    }

    private  function _fire($method, $key, $value = null, $forceRegistry = null) {


        $this->_source = $this->_getSource($forceRegistry);
        $call = ($this->_isSourceCache()) ?
                $this->_functionsArray['Cache'][$method] : $this->_functionsArray['Registry'][$method];

        return (isset($value)) ? $this->$call($key, $value) : $this->$call($key);
    }

    private  function _getFromCache($key) {
        return $this->_existsInCache($key);
    }

    private  function _saveInCache($key, $value) {
        if ($this->_existsInCache($key))
            return false;

        $this->_source->save($value, $key);
        return true;
    }

    private  function _deleteFromCache($key) {
        if (!$this->_existsInCache($key))
            return false;

        $this->_source->remove($key);
        return true;
    }

    private  function _existsInCache($key) {
        return $this->_source->load($key);
    }

    private  function _getFromRegistry($key) {
        if ($this->_existsInRegistry($key))
            return unserialize($this->_source->get($key));

        return false;
    }

    private  function _saveInRegistry($key, $value) {
        if ($this->_existsInRegistry($key))
            return false;

        $this->_source->set($key, serialize($value));
        return true;
    }

    private  function _deleteFromRegistry($key) {
        if (!$this->_existsInCache($key))
            return false;

        $this->_source->offsetUnset($key);
        return true;
    }

    private  function _existsInRegistry($key) {
        return $this->_source->isRegistered($key);
    }

}

Output:

Logger, local variable

object(Zend_Log)[84]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[93]
          protected '_stream' => resource(77, stream)
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[94]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[95]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

Logger, from Registry using custom helper

object(Zend_Log)[96]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[97]
          protected '_stream' => int 0
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[98]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[99]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

Logger, from apc cache using custom helper

object(Zend_Log)[100]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[101]
          protected '_stream' => int 0
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[102]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[103]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

Logger, from Zend_Registry, direct.

object(Zend_Log)[84]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[93]
          protected '_stream' => resource(77, stream)
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[94]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[95]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

Logger, from apc Cache, Direct.

object(Zend_Log)[104]
  protected '_priorities' => 
    array
      0 => string 'EMERG' (length=5)
      1 => string 'ALERT' (length=5)
      2 => string 'CRIT' (length=4)
      3 => string 'ERR' (length=3)
      4 => string 'WARN' (length=4)
      5 => string 'NOTICE' (length=6)
      6 => string 'INFO' (length=4)
      7 => string 'DEBUG' (length=5)
  protected '_writers' => 
    array
      0 => 
        object(Zend_Log_Writer_Stream)[105]
          protected '_stream' => int 0
          protected '_filters' => 
            array
              0 => 
                object(Zend_Log_Filter_Priority)[106]
                  protected '_priority' => int 7
                  protected '_operator' => string '<=' (length=2)
          protected '_formatter' => 
            object(Zend_Log_Formatter_Simple)[107]
              protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
        [ %priorityName% : %message% ]
        [ POST: %post_vars% ] 
        [ GET: %get_vars% ] 
' (length=161)
  protected '_filters' => 
    array
      empty
  protected '_extras' => 
    array
      'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
      'get_vars' => string 'a:0:{}' (length=6)
      'post_vars' => string 'a:0:{}' (length=6)
      'ip' => string '127.0.0.1' (length=9)
      'username' => string 'guest' (length=5)
  protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
  protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
  protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
  protected '_origErrorHandler' => null
  protected '_registeredErrorHandler' => boolean false
  protected '_errorHandlerMap' => boolean false
  protected '_timestampFormat' => string 'c' (length=1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸 2024-12-05 06:17:13
  • Zend_Log 在存储时不应该被序列化。
  • Zend_Cache 不是一个选项,因为它需要序列化对象,因为它只存储字符串。
  • Zend_Registry 无法通过帮助程序类工作,因为由于代码而发生了一些序列化。删除它解决了问题。

简而言之:

  • 使用 Zend_Registry 存储对象
  • 在 Zend_Registry 中存储时不要序列化
  • Zend_Log shouldn't be serialized when stored.
  • Zend_Cache isn't an option because it required objects to be serialized as it stores only strings.
  • Zend_Registry wasn't working through helper class as there was some serialization going on due to the code. Removing that fixed the issue.

So in short:

  • Use Zend_Registry to store objects
  • Do not serialize when storing in Zend_Registry
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文