Пример #1
0
 /**
  * Factory to construct the logger and one or more writers
  * based on the configuration array
  *
  * @param  array|Zend_Config Array or instance of Zend_Config
  * @return Zend_Log
  * @throws Zend_Log_Exception
  */
 public static function factory($config = array())
 {
     if ($config instanceof Zend_Config) {
         $config = $config->toArray();
     }
     if (!is_array($config) || empty($config)) {
         /** @see Zend_Log_Exception */
         // require_once 'Zend/Log/Exception.php';
         throw new Zend_Log_Exception('Configuration must be an array or instance of Zend_Config');
     }
     $log = new static();
     if (array_key_exists('timestampFormat', $config)) {
         if (null != $config['timestampFormat'] && '' != $config['timestampFormat']) {
             $log->setTimestampFormat($config['timestampFormat']);
         }
         unset($config['timestampFormat']);
     }
     if (!is_array(current($config))) {
         $log->addWriter(current($config));
     } else {
         foreach ($config as $writer) {
             $log->addWriter($writer);
         }
     }
     return $log;
 }
Пример #2
0
 /**
  * Factory to construct the logger and one or more writers
  * based on the configuration array
  *
  * @param  array|Config Array or instance of Config
  * @throws Exception\InvalidArgumentException
  * @return self
  */
 public static function factory($config = array())
 {
     if ($config instanceof Config) {
         $config = $config->toArray();
     }
     if (!is_array($config) || empty($config)) {
         throw new Exception\InvalidArgumentException('Configuration must be an array or instance of Zend\\Config\\Config');
     }
     $log = new static();
     if (array_key_exists('timestampFormat', $config)) {
         if (null != $config['timestampFormat'] && '' != $config['timestampFormat']) {
             $log->setTimestampFormat($config['timestampFormat']);
         }
         unset($config['timestampFormat']);
     }
     if (!is_array(current($config))) {
         $log->addWriter(current($config));
     } else {
         foreach ($config as $writer) {
             $log->addWriter($writer);
         }
     }
     return $log;
 }
Пример #3
0
 /**
  * Shorthand to get a Db Logger
  *
  * @param string $component
  *
  * @return static
  * @throws \Zend_Log_Exception
  */
 public static function getDbLogger($component = null, $logLevel = \Zend_Log::INFO)
 {
     $runtimeCacheKey = 'pimcore_db_logger_' . $component;
     $logger = \Pimcore\Cache\Runtime::load($runtimeCacheKey);
     if (!$logger) {
         $logger = new static();
         $logger->setComponent($component);
         $logger->addWriter(new \Pimcore\Log\Writer\Db($logLevel));
         \Pimcore\Cache\Runtime::save($logger, $runtimeCacheKey);
     }
     return $logger;
 }