Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Log Class Reference

Public Member Functions

 __construct (Zend_Log_Writer_Abstract $writer=null)
 
 __call ($method, $params)
 
 addPriority ($name, $priority)
 
 addFilter ($filter)
 
 addWriter ($writer)
 
 setEventItem ($name, $value)
 
 registerErrorHandler ()
 
 errorHandler ($errno, $errstr, $errfile, $errline, $errcontext)
 
 setTimestampFormat ($format)
 
 getTimestampFormat ()
 

Static Public Member Functions

static factory ($config=array())
 

Data Fields

const EMERG = 0
 
const ALERT = 1
 
const CRIT = 2
 
const ERR = 3
 
const WARN = 4
 
const NOTICE = 5
 
const INFO = 6
 
const DEBUG = 7
 

Protected Member Functions

 _constructWriterFromConfig ($config)
 
 _constructFilterFromConfig ($config)
 
 _constructFormatterFromConfig ($config)
 
 _constructFromConfig ($type, $config, $namespace)
 
 getClassName ($config, $type, $defaultNamespace)
 
 _packEvent ($message, $priority)
 

Protected Attributes

 $_priorities = array()
 
 $_writers = array()
 
 $_filters = array()
 
 $_extras = array()
 
 $_defaultWriterNamespace = 'Zend_Log_Writer'
 
 $_defaultFilterNamespace = 'Zend_Log_Filter'
 
 $_defaultFormatterNamespace = 'Zend_Log_Formatter'
 
 $_origErrorHandler = null
 
 $_registeredErrorHandler = false
 
 $_errorHandlerMap = false
 
 $_timestampFormat = 'c'
 

Detailed Description

Definition at line 40 of file Log.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Zend_Log_Writer_Abstract  $writer = null)

Class constructor. Create a new logger

Parameters
Zend_Log_Writer_Abstract | null$writerdefault writer

Definition at line 119 of file Log.php.

120  {
121  $r = new ReflectionClass($this);
122  $this->_priorities = array_flip($r->getConstants());
123 
124  if ($writer !== null) {
125  $this->addWriter($writer);
126  }
127  }
addWriter($writer)
Definition: Log.php:529

Member Function Documentation

◆ __call()

__call (   $method,
  $params 
)

Undefined method handler allows a shortcut: $log->priorityName('message') instead of $log->log('message', Zend_Log::PRIORITY_NAME)

Parameters
string$methodpriority name
string$paramsmessage to log
Returns
void
Exceptions
Zend_Log_Exception
See also
Zend_Log_Exception
Zend_Log_Exception

Definition at line 381 of file Log.php.

382  {
383  $priority = strtoupper($method);
384  if (($priority = array_search($priority, $this->_priorities)) !== false) {
385  switch (count($params)) {
386  case 0:
388  #require_once 'Zend/Log/Exception.php';
389  throw new Zend_Log_Exception('Missing log message');
390  case 1:
391  $message = array_shift($params);
392  $extras = null;
393  break;
394  default:
395  $message = array_shift($params);
396  $extras = array_shift($params);
397  break;
398  }
399  $this->log($message, $priority, $extras);
400  } else {
402  #require_once 'Zend/Log/Exception.php';
403  throw new Zend_Log_Exception('Bad log priority');
404  }
405  }
$message
$method
Definition: info.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _constructFilterFromConfig()

_constructFilterFromConfig (   $config)
protected

Construct filter object from configuration array or Zend_Config object

Parameters
array | Zend_Config$configZend_Config or Array
Returns
Zend_Log_Filter_Interface
Exceptions
Zend_Log_Exception
See also
Zend_Log_Exception

Definition at line 223 of file Log.php.

224  {
225  $filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace);
226 
227  if (!$filter instanceof Zend_Log_Filter_Interface) {
228  $filterName = is_object($filter)
229  ? get_class($filter)
230  : 'The specified filter';
232  #require_once 'Zend/Log/Exception.php';
233  throw new Zend_Log_Exception("{$filterName} does not implement Zend_Log_Filter_Interface");
234  }
235 
236  return $filter;
237  }
$config
Definition: fraud_order.php:17
_constructFromConfig($type, $config, $namespace)
Definition: Log.php:271

◆ _constructFormatterFromConfig()

_constructFormatterFromConfig (   $config)
protected

Construct formatter object from configuration array or Zend_Config object

Parameters
array | Zend_Config$configZend_Config or Array
Returns
Zend_Log_Formatter_Interface
Exceptions
Zend_Log_Exception
See also
Zend_Log_Exception

Definition at line 246 of file Log.php.

247  {
248  $formatter = $this->_constructFromConfig('formatter', $config, $this->_defaultFormatterNamespace);
249 
250  if (!$formatter instanceof Zend_Log_Formatter_Interface) {
251  $formatterName = is_object($formatter)
252  ? get_class($formatter)
253  : 'The specified formatter';
255  #require_once 'Zend/Log/Exception.php';
256  throw new Zend_Log_Exception($formatterName . ' does not implement Zend_Log_Formatter_Interface');
257  }
258 
259  return $formatter;
260  }
$config
Definition: fraud_order.php:17
_constructFromConfig($type, $config, $namespace)
Definition: Log.php:271

◆ _constructFromConfig()

_constructFromConfig (   $type,
  $config,
  $namespace 
)
protected

Construct a filter or writer from config

Parameters
string$type'writer' of 'filter'
mixed$configZend_Config or Array
string$namespace
Returns
object
Exceptions
Zend_Log_Exception

Definition at line 271 of file Log.php.

272  {
273  if ($config instanceof Zend_Config) {
274  $config = $config->toArray();
275  }
276 
277  if (!is_array($config) || empty($config)) {
278  #require_once 'Zend/Log/Exception.php';
279  throw new Zend_Log_Exception(
280  'Configuration must be an array or instance of Zend_Config'
281  );
282  }
283 
284  $params = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array();
285  $className = $this->getClassName($config, $type, $namespace);
286  if (!class_exists($className)) {
287  #require_once 'Zend/Loader.php';
289  }
290 
291  $reflection = new ReflectionClass($className);
292  if (!$reflection->implementsInterface('Zend_Log_FactoryInterface')) {
293  #require_once 'Zend/Log/Exception.php';
294  throw new Zend_Log_Exception(
295  $className . ' does not implement Zend_Log_FactoryInterface and can not be constructed from config.'
296  );
297  }
298 
299  return call_user_func(array($className, 'factory'), $params);
300  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
$config
Definition: fraud_order.php:17
$type
Definition: item.phtml:13
getClassName($config, $type, $defaultNamespace)
Definition: Log.php:311
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ _constructWriterFromConfig()

_constructWriterFromConfig (   $config)
protected

Construct a writer object based on a configuration array

Parameters
array$configconfig array with writer spec
Returns
Zend_Log_Writer_Abstract
Exceptions
Zend_Log_Exception
See also
Zend_Log_Exception

Definition at line 190 of file Log.php.

191  {
192  $writer = $this->_constructFromConfig('writer', $config, $this->_defaultWriterNamespace);
193 
194  if (!$writer instanceof Zend_Log_Writer_Abstract) {
195  $writerName = is_object($writer)
196  ? get_class($writer)
197  : 'The specified writer';
199  #require_once 'Zend/Log/Exception.php';
200  throw new Zend_Log_Exception("{$writerName} does not extend Zend_Log_Writer_Abstract!");
201  }
202 
203  if (isset($config['filterName'])) {
204  $filter = $this->_constructFilterFromConfig($config);
205  $writer->addFilter($filter);
206  }
207 
208  if (isset($config['formatterName'])) {
209  $formatter = $this->_constructFormatterFromConfig($config);
210  $writer->setFormatter($formatter);
211  }
212 
213  return $writer;
214  }
$config
Definition: fraud_order.php:17
_constructFormatterFromConfig($config)
Definition: Log.php:246
_constructFilterFromConfig($config)
Definition: Log.php:223
_constructFromConfig($type, $config, $namespace)
Definition: Log.php:271

◆ _packEvent()

_packEvent (   $message,
  $priority 
)
protected

Packs message and priority into Event array

Parameters
string$messageMessage to log
integer$priorityPriority of message
Returns
array Event array

Definition at line 345 of file Log.php.

346  {
347  return array_merge(array(
348  'timestamp' => date($this->_timestampFormat),
349  'message' => $message,
350  'priority' => $priority,
351  'priorityName' => $this->_priorities[$priority]
352  ),
353  $this->_extras
354  );
355  }
$message

◆ addFilter()

addFilter (   $filter)

Add a filter that will be applied before all log writers. Before a message will be received by any of the writers, it must be accepted by all filters added with this method.

Parameters
int | Zend_Config | array | Zend_Log_Filter_Interface$filter
Returns
$this
Exceptions
Zend_Log_Exception
See also
Zend_Log_Filter_Priority
Zend_Log_Exception

Definition at line 501 of file Log.php.

502  {
503  if (is_int($filter)) {
505  #require_once 'Zend/Log/Filter/Priority.php';
506  $filter = new Zend_Log_Filter_Priority($filter);
507 
508  } elseif ($filter instanceof Zend_Config || is_array($filter)) {
509  $filter = $this->_constructFilterFromConfig($filter);
510 
511  } elseif(! $filter instanceof Zend_Log_Filter_Interface) {
513  #require_once 'Zend/Log/Exception.php';
514  throw new Zend_Log_Exception('Invalid filter provided');
515  }
516 
517  $this->_filters[] = $filter;
518  return $this;
519  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_constructFilterFromConfig($config)
Definition: Log.php:223

◆ addPriority()

addPriority (   $name,
  $priority 
)

Add a custom priority

Parameters
string$nameName of priority
integer$priorityNumeric priority
Returns
$this
Exceptions
Zend_Log_Exception
See also
Zend_Log_Exception

Definition at line 476 of file Log.php.

477  {
478  // Priority names must be uppercase for predictability.
479  $name = strtoupper($name);
480 
481  if (isset($this->_priorities[$priority])
482  || false !== array_search($name, $this->_priorities)) {
484  #require_once 'Zend/Log/Exception.php';
485  throw new Zend_Log_Exception('Existing priorities cannot be overwritten');
486  }
487 
488  $this->_priorities[$priority] = $name;
489  return $this;
490  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addWriter()

addWriter (   $writer)

Add a writer. A writer is responsible for taking a log message and writing it out to storage.

Parameters
mixed$writerZend_Log_Writer_Abstract or Config array
Returns
Zend_Log
Exceptions
Zend_Log_Exception
See also
Zend_Log_Exception

Definition at line 529 of file Log.php.

530  {
531  if (is_array($writer) || $writer instanceof Zend_Config) {
532  $writer = $this->_constructWriterFromConfig($writer);
533  }
534 
535  if (!$writer instanceof Zend_Log_Writer_Abstract) {
537  #require_once 'Zend/Log/Exception.php';
538  throw new Zend_Log_Exception(
539  'Writer must be an instance of Zend_Log_Writer_Abstract'
540  . ' or you should pass a configuration array'
541  );
542  }
543 
544  $this->_writers[] = $writer;
545  return $this;
546  }
_constructWriterFromConfig($config)
Definition: Log.php:190

◆ errorHandler()

errorHandler (   $errno,
  $errstr,
  $errfile,
  $errline,
  $errcontext 
)

Error Handler will convert error into log message, and then call the original error handler

Custom error handler int $errno string $errstr string $errfile int $errline array $errcontext boolean

Definition at line 622 of file Log.php.

623  {
624  $errorLevel = error_reporting();
625 
626  if ($errorLevel & $errno) {
627  if (isset($this->_errorHandlerMap[$errno])) {
628  $priority = $this->_errorHandlerMap[$errno];
629  } else {
630  $priority = Zend_Log::INFO;
631  }
632  $this->log($errstr, $priority, array('errno'=>$errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext));
633  }
634 
635  if ($this->_origErrorHandler !== null) {
636  return call_user_func($this->_origErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext);
637  }
638  return false;
639  }
const INFO
Definition: Log.php:48

◆ factory()

static factory (   $config = array())
static

Factory to construct the logger and one or more writers based on the configuration array

Parameters
array|Zend_ConfigArray or instance of Zend_Config
Returns
Zend_Log
Exceptions
Zend_Log_Exception
See also
Zend_Log_Exception
Zend_Log_Exception

Definition at line 137 of file Log.php.

138  {
139  if ($config instanceof Zend_Config) {
140  $config = $config->toArray();
141  }
142 
143  if (!is_array($config) || empty($config)) {
145  #require_once 'Zend/Log/Exception.php';
146  throw new Zend_Log_Exception('Configuration must be an array or instance of Zend_Config');
147  }
148 
149  if (array_key_exists('className', $config)) {
150  $class = $config['className'];
151  unset($config['className']);
152  } else {
153  $class = __CLASS__;
154  }
155 
156  $log = new $class;
157 
158  if (!$log instanceof Zend_Log) {
160  #require_once 'Zend/Log/Exception.php';
161  throw new Zend_Log_Exception('Passed className does not belong to a descendant of Zend_Log');
162  }
163 
164  if (array_key_exists('timestampFormat', $config)) {
165  if (null != $config['timestampFormat'] && '' != $config['timestampFormat']) {
166  $log->setTimestampFormat($config['timestampFormat']);
167  }
168  unset($config['timestampFormat']);
169  }
170 
171  if (!is_array(current($config))) {
172  $log->addWriter(current($config));
173  } else {
174  foreach($config as $writer) {
175  $log->addWriter($writer);
176  }
177  }
178 
179  return $log;
180  }
$config
Definition: fraud_order.php:17
$_option $_optionId $class
Definition: date.phtml:13

◆ getClassName()

getClassName (   $config,
  $type,
  $defaultNamespace 
)
protected

Get the writer or filter full classname

Parameters
array$config
string$typefilter|writer
string$defaultNamespace
Returns
string full classname
Exceptions
Zend_Log_Exception

Definition at line 311 of file Log.php.

312  {
313  if (!isset($config[$type . 'Name'])) {
314  #require_once 'Zend/Log/Exception.php';
315  throw new Zend_Log_Exception("Specify {$type}Name in the configuration array");
316  }
317 
318  $className = $config[$type . 'Name'];
319  $namespace = $defaultNamespace;
320 
321  if (isset($config[$type . 'Namespace'])) {
322  $namespace = $config[$type . 'Namespace'];
323  }
324 
325  // PHP >= 5.3.0 namespace given?
326  if (substr($namespace, -1) == '\\') {
327  return $namespace . $className;
328  }
329 
330  // empty namespace given?
331  if (strlen($namespace) === 0) {
332  return $className;
333  }
334 
335  return $namespace . '_' . $className;
336  }
$config
Definition: fraud_order.php:17
$type
Definition: item.phtml:13
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ getTimestampFormat()

getTimestampFormat ( )

Get timestamp format used for log entries.

Returns
string

Definition at line 658 of file Log.php.

659  {
661  }
$_timestampFormat
Definition: Log.php:112

◆ registerErrorHandler()

registerErrorHandler ( )

Register Logging system as an error handler to log php errors Note: it still calls the original error handler if set_error_handler is able to return it.

Errors will be mapped as: E_NOTICE, E_USER_NOTICE => NOTICE E_WARNING, E_CORE_WARNING, E_USER_WARNING => WARN E_ERROR, E_USER_ERROR, E_CORE_ERROR, E_RECOVERABLE_ERROR => ERR E_DEPRECATED, E_STRICT, E_USER_DEPRECATED => DEBUG (unknown/other) => INFO

Custom error handler Zend_Log

Definition at line 576 of file Log.php.

577  {
578  // Only register once. Avoids loop issues if it gets registered twice.
579  if ($this->_registeredErrorHandler) {
580  return $this;
581  }
582 
583  $this->_origErrorHandler = set_error_handler(array($this, 'errorHandler'));
584 
585  // Contruct a default map of phpErrors to Zend_Log priorities.
586  // Some of the errors are uncatchable, but are included for completeness
587  $this->_errorHandlerMap = array(
588  E_NOTICE => Zend_Log::NOTICE,
589  E_USER_NOTICE => Zend_Log::NOTICE,
590  E_WARNING => Zend_Log::WARN,
591  E_CORE_WARNING => Zend_Log::WARN,
592  E_USER_WARNING => Zend_Log::WARN,
593  E_ERROR => Zend_Log::ERR,
594  E_USER_ERROR => Zend_Log::ERR,
595  E_CORE_ERROR => Zend_Log::ERR,
596  E_RECOVERABLE_ERROR => Zend_Log::ERR,
597  E_STRICT => Zend_Log::DEBUG,
598  );
599  // PHP 5.3.0+
600  if (defined('E_DEPRECATED')) {
601  $this->_errorHandlerMap['E_DEPRECATED'] = Zend_Log::DEBUG;
602  }
603  if (defined('E_USER_DEPRECATED')) {
604  $this->_errorHandlerMap['E_USER_DEPRECATED'] = Zend_Log::DEBUG;
605  }
606 
607  $this->_registeredErrorHandler = true;
608  return $this;
609  }
const WARN
Definition: Log.php:46
const DEBUG
Definition: Log.php:49
const ERR
Definition: Log.php:45
const NOTICE
Definition: Log.php:47

◆ setEventItem()

setEventItem (   $name,
  $value 
)

Set an extra item to pass to the log writers.

Parameters
string$nameName of the field
string$valueValue of the field
Returns
Zend_Log

Definition at line 555 of file Log.php.

556  {
557  $this->_extras = array_merge($this->_extras, array($name => $value));
558  return $this;
559  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setTimestampFormat()

setTimestampFormat (   $format)

Set timestamp format for log entries.

Parameters
string$format
Returns
Zend_Log

Definition at line 647 of file Log.php.

648  {
649  $this->_timestampFormat = $format;
650  return $this;
651  }
$format
Definition: list.phtml:12

Field Documentation

◆ $_defaultFilterNamespace

$_defaultFilterNamespace = 'Zend_Log_Filter'
protected

Definition at line 82 of file Log.php.

◆ $_defaultFormatterNamespace

$_defaultFormatterNamespace = 'Zend_Log_Formatter'
protected

Definition at line 88 of file Log.php.

◆ $_defaultWriterNamespace

$_defaultWriterNamespace = 'Zend_Log_Writer'
protected

Definition at line 76 of file Log.php.

◆ $_errorHandlerMap

$_errorHandlerMap = false
protected

Definition at line 106 of file Log.php.

◆ $_extras

$_extras = array()
protected

Definition at line 70 of file Log.php.

◆ $_filters

$_filters = array()
protected

Definition at line 65 of file Log.php.

◆ $_origErrorHandler

$_origErrorHandler = null
protected

Definition at line 94 of file Log.php.

◆ $_priorities

$_priorities = array()
protected

Definition at line 55 of file Log.php.

◆ $_registeredErrorHandler

$_registeredErrorHandler = false
protected

Definition at line 100 of file Log.php.

◆ $_timestampFormat

$_timestampFormat = 'c'
protected

Definition at line 112 of file Log.php.

◆ $_writers

$_writers = array()
protected

Definition at line 60 of file Log.php.

◆ ALERT

const ALERT = 1

Definition at line 43 of file Log.php.

◆ CRIT

const CRIT = 2

Definition at line 44 of file Log.php.

◆ DEBUG

const DEBUG = 7

Definition at line 49 of file Log.php.

◆ EMERG

const EMERG = 0

Definition at line 42 of file Log.php.

◆ ERR

const ERR = 3

Definition at line 45 of file Log.php.

◆ INFO

const INFO = 6

Definition at line 48 of file Log.php.

◆ NOTICE

const NOTICE = 5

Definition at line 47 of file Log.php.

◆ WARN

const WARN = 4

Definition at line 46 of file Log.php.


The documentation for this class was generated from the following file: