Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/Monolog
File: Logger.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Monolog package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Jordi Boggiano <j.boggiano@seld.be>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Monolog log channel
[12] Fix | Delete
*
[13] Fix | Delete
* It contains a stack of Handlers and a stack of Processors,
[14] Fix | Delete
* and uses them to store records that are added to it.
[15] Fix | Delete
*
[16] Fix | Delete
* @author Jordi Boggiano <j.boggiano@seld.be>
[17] Fix | Delete
*/
[18] Fix | Delete
class Monolog_Logger implements Monolog_Psr_LoggerInterface
[19] Fix | Delete
{
[20] Fix | Delete
/**
[21] Fix | Delete
* Detailed debug information
[22] Fix | Delete
*/
[23] Fix | Delete
const DEBUG = 100;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Interesting events
[27] Fix | Delete
*
[28] Fix | Delete
* Examples: User logs in, SQL logs.
[29] Fix | Delete
*/
[30] Fix | Delete
const INFO = 200;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Uncommon events
[34] Fix | Delete
*/
[35] Fix | Delete
const NOTICE = 250;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Exceptional occurrences that are not errors
[39] Fix | Delete
*
[40] Fix | Delete
* Examples: Use of deprecated APIs, poor use of an API,
[41] Fix | Delete
* undesirable things that are not necessarily wrong.
[42] Fix | Delete
*/
[43] Fix | Delete
const WARNING = 300;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Runtime errors
[47] Fix | Delete
*/
[48] Fix | Delete
const ERROR = 400;
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Critical conditions
[52] Fix | Delete
*
[53] Fix | Delete
* Example: Application component unavailable, unexpected exception.
[54] Fix | Delete
*/
[55] Fix | Delete
const CRITICAL = 500;
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Action must be taken immediately
[59] Fix | Delete
*
[60] Fix | Delete
* Example: Entire website down, database unavailable, etc.
[61] Fix | Delete
* This should trigger the SMS alerts and wake you up.
[62] Fix | Delete
*/
[63] Fix | Delete
const ALERT = 550;
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* Urgent alert.
[67] Fix | Delete
*/
[68] Fix | Delete
const EMERGENCY = 600;
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* Monolog API version
[72] Fix | Delete
*
[73] Fix | Delete
* This is only bumped when API breaks are done and should
[74] Fix | Delete
* follow the major version of the library
[75] Fix | Delete
*
[76] Fix | Delete
* @var int
[77] Fix | Delete
*/
[78] Fix | Delete
const API = 1;
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Logging levels from syslog protocol defined in RFC 5424
[82] Fix | Delete
*
[83] Fix | Delete
* @var array $levels Logging levels
[84] Fix | Delete
*/
[85] Fix | Delete
protected static $levels = array(
[86] Fix | Delete
100 => 'DEBUG',
[87] Fix | Delete
200 => 'INFO',
[88] Fix | Delete
250 => 'NOTICE',
[89] Fix | Delete
300 => 'WARNING',
[90] Fix | Delete
400 => 'ERROR',
[91] Fix | Delete
500 => 'CRITICAL',
[92] Fix | Delete
550 => 'ALERT',
[93] Fix | Delete
600 => 'EMERGENCY',
[94] Fix | Delete
);
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* @var DateTimeZone
[98] Fix | Delete
*/
[99] Fix | Delete
protected static $timezone;
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* @var string
[103] Fix | Delete
*/
[104] Fix | Delete
protected $name;
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* The handler stack
[108] Fix | Delete
*
[109] Fix | Delete
* @var Monolog_Handler_HandlerInterface[]
[110] Fix | Delete
*/
[111] Fix | Delete
protected $handlers;
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Processors that will process all log records
[115] Fix | Delete
*
[116] Fix | Delete
* To process records of a single handler instead, add the processor on that specific handler
[117] Fix | Delete
*
[118] Fix | Delete
* @var callable[]
[119] Fix | Delete
*/
[120] Fix | Delete
protected $processors;
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* @param string $name The logging channel
[124] Fix | Delete
* @param Monolog_Handler_HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc.
[125] Fix | Delete
* @param callable[] $processors Optional array of processors
[126] Fix | Delete
*/
[127] Fix | Delete
public function __construct($name, array $handlers = array(), array $processors = array())
[128] Fix | Delete
{
[129] Fix | Delete
$this->name = $name;
[130] Fix | Delete
$this->handlers = $handlers;
[131] Fix | Delete
$this->processors = $processors;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* @return string
[136] Fix | Delete
*/
[137] Fix | Delete
public function getName()
[138] Fix | Delete
{
[139] Fix | Delete
return $this->name;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Pushes a handler on to the stack.
[144] Fix | Delete
*
[145] Fix | Delete
* @param Monolog_Handler_HandlerInterface $handler
[146] Fix | Delete
*/
[147] Fix | Delete
public function pushHandler(Monolog_Handler_HandlerInterface $handler)
[148] Fix | Delete
{
[149] Fix | Delete
array_unshift($this->handlers, $handler);
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Pops a handler from the stack
[154] Fix | Delete
*
[155] Fix | Delete
* @return Monolog_Handler_HandlerInterface
[156] Fix | Delete
*/
[157] Fix | Delete
public function popHandler()
[158] Fix | Delete
{
[159] Fix | Delete
if (!$this->handlers) {
[160] Fix | Delete
throw new LogicException('You tried to pop from an empty handler stack.');
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
return array_shift($this->handlers);
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Adds a processor on to the stack.
[168] Fix | Delete
*
[169] Fix | Delete
* @param callable $callback
[170] Fix | Delete
*/
[171] Fix | Delete
public function pushProcessor($callback)
[172] Fix | Delete
{
[173] Fix | Delete
if (!is_callable($callback)) {
[174] Fix | Delete
throw new InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
[175] Fix | Delete
}
[176] Fix | Delete
array_unshift($this->processors, $callback);
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Removes the processor on top of the stack and returns it.
[181] Fix | Delete
*
[182] Fix | Delete
* @return callable
[183] Fix | Delete
*/
[184] Fix | Delete
public function popProcessor()
[185] Fix | Delete
{
[186] Fix | Delete
if (!$this->processors) {
[187] Fix | Delete
throw new LogicException('You tried to pop from an empty processor stack.');
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
return array_shift($this->processors);
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
/**
[194] Fix | Delete
* Adds a log record.
[195] Fix | Delete
*
[196] Fix | Delete
* @param integer $level The logging level
[197] Fix | Delete
* @param string $message The log message
[198] Fix | Delete
* @param array $context The log context
[199] Fix | Delete
*
[200] Fix | Delete
* @return Boolean Whether the record has been processed
[201] Fix | Delete
*/
[202] Fix | Delete
public function addRecord($level, $message, array $context = array())
[203] Fix | Delete
{
[204] Fix | Delete
if (!$this->handlers) {
[205] Fix | Delete
$this->pushHandler(new Monolog_Handler_StreamHandler('php://stderr', self::DEBUG));
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
$record = array(
[209] Fix | Delete
'message' => (string) $message,
[210] Fix | Delete
'context' => $context,
[211] Fix | Delete
'level' => $level,
[212] Fix | Delete
'level_name' => self::getLevelName($level),
[213] Fix | Delete
'channel' => $this->name,
[214] Fix | Delete
'datetime' => $this->getCurrentTimestamp(),
[215] Fix | Delete
'extra' => array(),
[216] Fix | Delete
);
[217] Fix | Delete
// check if any handler will handle this message
[218] Fix | Delete
$handlerKey = null;
[219] Fix | Delete
foreach ($this->handlers as $key => $handler) {
[220] Fix | Delete
if ($handler->isHandling($record)) {
[221] Fix | Delete
$handlerKey = $key;
[222] Fix | Delete
break;
[223] Fix | Delete
}
[224] Fix | Delete
}
[225] Fix | Delete
// none found
[226] Fix | Delete
if (null === $handlerKey) {
[227] Fix | Delete
return false;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
// found at least one, process message and dispatch it
[231] Fix | Delete
foreach ($this->processors as $processor) {
[232] Fix | Delete
$record = call_user_func($processor, $record);
[233] Fix | Delete
}
[234] Fix | Delete
while (isset($this->handlers[$handlerKey]) &&
[235] Fix | Delete
false === $this->handlers[$handlerKey]->handle($record)) {
[236] Fix | Delete
$handlerKey++;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
return true;
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
private function getCurrentTimestamp()
[243] Fix | Delete
{
[244] Fix | Delete
if (!self::$timezone) {
[245] Fix | Delete
self::$timezone = new DateTimeZone(date_default_timezone_get() ? date_default_timezone_get() : 'UTC');
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
if (is_callable(array('DateTime', 'createFromFormat'))) {
[249] Fix | Delete
/** @handled static */
[250] Fix | Delete
return DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), self::$timezone)->setTimezone(self::$timezone);
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
return new DateTime('now', self::$timezone);
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Adds a log record at the DEBUG level.
[258] Fix | Delete
*
[259] Fix | Delete
* @param string $message The log message
[260] Fix | Delete
* @param array $context The log context
[261] Fix | Delete
*
[262] Fix | Delete
* @return Boolean Whether the record has been processed
[263] Fix | Delete
*/
[264] Fix | Delete
public function addDebug($message, array $context = array())
[265] Fix | Delete
{
[266] Fix | Delete
return $this->addRecord(self::DEBUG, $message, $context);
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Adds a log record at the INFO level.
[271] Fix | Delete
*
[272] Fix | Delete
* @param string $message The log message
[273] Fix | Delete
* @param array $context The log context
[274] Fix | Delete
*
[275] Fix | Delete
* @return Boolean Whether the record has been processed
[276] Fix | Delete
*/
[277] Fix | Delete
public function addInfo($message, array $context = array())
[278] Fix | Delete
{
[279] Fix | Delete
return $this->addRecord(self::INFO, $message, $context);
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Adds a log record at the NOTICE level.
[284] Fix | Delete
*
[285] Fix | Delete
* @param string $message The log message
[286] Fix | Delete
* @param array $context The log context
[287] Fix | Delete
*
[288] Fix | Delete
* @return Boolean Whether the record has been processed
[289] Fix | Delete
*/
[290] Fix | Delete
public function addNotice($message, array $context = array())
[291] Fix | Delete
{
[292] Fix | Delete
return $this->addRecord(self::NOTICE, $message, $context);
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* Adds a log record at the WARNING level.
[297] Fix | Delete
*
[298] Fix | Delete
* @param string $message The log message
[299] Fix | Delete
* @param array $context The log context
[300] Fix | Delete
*
[301] Fix | Delete
* @return Boolean Whether the record has been processed
[302] Fix | Delete
*/
[303] Fix | Delete
public function addWarning($message, array $context = array())
[304] Fix | Delete
{
[305] Fix | Delete
return $this->addRecord(self::WARNING, $message, $context);
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
/**
[309] Fix | Delete
* Adds a log record at the ERROR level.
[310] Fix | Delete
*
[311] Fix | Delete
* @param string $message The log message
[312] Fix | Delete
* @param array $context The log context
[313] Fix | Delete
*
[314] Fix | Delete
* @return Boolean Whether the record has been processed
[315] Fix | Delete
*/
[316] Fix | Delete
public function addError($message, array $context = array())
[317] Fix | Delete
{
[318] Fix | Delete
return $this->addRecord(self::ERROR, $message, $context);
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
/**
[322] Fix | Delete
* Adds a log record at the CRITICAL level.
[323] Fix | Delete
*
[324] Fix | Delete
* @param string $message The log message
[325] Fix | Delete
* @param array $context The log context
[326] Fix | Delete
*
[327] Fix | Delete
* @return Boolean Whether the record has been processed
[328] Fix | Delete
*/
[329] Fix | Delete
public function addCritical($message, array $context = array())
[330] Fix | Delete
{
[331] Fix | Delete
return $this->addRecord(self::CRITICAL, $message, $context);
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
/**
[335] Fix | Delete
* Adds a log record at the ALERT level.
[336] Fix | Delete
*
[337] Fix | Delete
* @param string $message The log message
[338] Fix | Delete
* @param array $context The log context
[339] Fix | Delete
*
[340] Fix | Delete
* @return Boolean Whether the record has been processed
[341] Fix | Delete
*/
[342] Fix | Delete
public function addAlert($message, array $context = array())
[343] Fix | Delete
{
[344] Fix | Delete
return $this->addRecord(self::ALERT, $message, $context);
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/**
[348] Fix | Delete
* Adds a log record at the EMERGENCY level.
[349] Fix | Delete
*
[350] Fix | Delete
* @param string $message The log message
[351] Fix | Delete
* @param array $context The log context
[352] Fix | Delete
*
[353] Fix | Delete
* @return Boolean Whether the record has been processed
[354] Fix | Delete
*/
[355] Fix | Delete
public function addEmergency($message, array $context = array())
[356] Fix | Delete
{
[357] Fix | Delete
return $this->addRecord(self::EMERGENCY, $message, $context);
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
/**
[361] Fix | Delete
* Gets all supported logging levels.
[362] Fix | Delete
*
[363] Fix | Delete
* @return array Assoc array with human-readable level names => level codes.
[364] Fix | Delete
*/
[365] Fix | Delete
public static function getLevels()
[366] Fix | Delete
{
[367] Fix | Delete
return array_flip(self::$levels);
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
/**
[371] Fix | Delete
* Gets the name of the logging level.
[372] Fix | Delete
*
[373] Fix | Delete
* @param integer $level
[374] Fix | Delete
*
[375] Fix | Delete
* @return string
[376] Fix | Delete
*/
[377] Fix | Delete
public static function getLevelName($level)
[378] Fix | Delete
{
[379] Fix | Delete
if (!isset(self::$levels[$level])) {
[380] Fix | Delete
throw new InvalidArgumentException('Level "'.$level.'" is not defined, use one of: '.implode(', ', array_keys(self::$levels)));
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
return self::$levels[$level];
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
/**
[387] Fix | Delete
* Checks whether the Logger has a handler that listens on the given level
[388] Fix | Delete
*
[389] Fix | Delete
* @param integer $level
[390] Fix | Delete
*
[391] Fix | Delete
* @return Boolean
[392] Fix | Delete
*/
[393] Fix | Delete
public function isHandling($level)
[394] Fix | Delete
{
[395] Fix | Delete
$record = array(
[396] Fix | Delete
'level' => $level,
[397] Fix | Delete
);
[398] Fix | Delete
[399] Fix | Delete
foreach ($this->handlers as $handler) {
[400] Fix | Delete
if ($handler->isHandling($record)) {
[401] Fix | Delete
return true;
[402] Fix | Delete
}
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
return false;
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
/**
[409] Fix | Delete
* Adds a log record at an arbitrary level.
[410] Fix | Delete
*
[411] Fix | Delete
* This method allows for compatibility with common interfaces.
[412] Fix | Delete
*
[413] Fix | Delete
* @param mixed $level The log level
[414] Fix | Delete
* @param string $message The log message
[415] Fix | Delete
* @param array $context The log context
[416] Fix | Delete
*
[417] Fix | Delete
* @return Boolean Whether the record has been processed
[418] Fix | Delete
*/
[419] Fix | Delete
public function log($level, $message, array $context = array())
[420] Fix | Delete
{
[421] Fix | Delete
if (is_string($level) && defined(__CLASS__.'::'.strtoupper($level))) {
[422] Fix | Delete
$level = constant(__CLASS__.'::'.strtoupper($level));
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
return $this->addRecord($level, $message, $context);
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
/**
[429] Fix | Delete
* Adds a log record at the DEBUG level.
[430] Fix | Delete
*
[431] Fix | Delete
* This method allows for compatibility with common interfaces.
[432] Fix | Delete
*
[433] Fix | Delete
* @param string $message The log message
[434] Fix | Delete
* @param array $context The log context
[435] Fix | Delete
*
[436] Fix | Delete
* @return Boolean Whether the record has been processed
[437] Fix | Delete
*/
[438] Fix | Delete
public function debug($message, array $context = array())
[439] Fix | Delete
{
[440] Fix | Delete
return $this->addRecord(self::DEBUG, $message, $context);
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Adds a log record at the INFO level.
[445] Fix | Delete
*
[446] Fix | Delete
* This method allows for compatibility with common interfaces.
[447] Fix | Delete
*
[448] Fix | Delete
* @param string $message The log message
[449] Fix | Delete
* @param array $context The log context
[450] Fix | Delete
*
[451] Fix | Delete
* @return Boolean Whether the record has been processed
[452] Fix | Delete
*/
[453] Fix | Delete
public function info($message, array $context = array())
[454] Fix | Delete
{
[455] Fix | Delete
return $this->addRecord(self::INFO, $message, $context);
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
/**
[459] Fix | Delete
* Adds a log record at the INFO level.
[460] Fix | Delete
*
[461] Fix | Delete
* This method allows for compatibility with common interfaces.
[462] Fix | Delete
*
[463] Fix | Delete
* @param string $message The log message
[464] Fix | Delete
* @param array $context The log context
[465] Fix | Delete
*
[466] Fix | Delete
* @return Boolean Whether the record has been processed
[467] Fix | Delete
*/
[468] Fix | Delete
public function notice($message, array $context = array())
[469] Fix | Delete
{
[470] Fix | Delete
return $this->addRecord(self::NOTICE, $message, $context);
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Adds a log record at the WARNING level.
[475] Fix | Delete
*
[476] Fix | Delete
* This method allows for compatibility with common interfaces.
[477] Fix | Delete
*
[478] Fix | Delete
* @param string $message The log message
[479] Fix | Delete
* @param array $context The log context
[480] Fix | Delete
*
[481] Fix | Delete
* @return Boolean Whether the record has been processed
[482] Fix | Delete
*/
[483] Fix | Delete
public function warn($message, array $context = array())
[484] Fix | Delete
{
[485] Fix | Delete
return $this->addRecord(self::WARNING, $message, $context);
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
/**
[489] Fix | Delete
* Adds a log record at the WARNING level.
[490] Fix | Delete
*
[491] Fix | Delete
* This method allows for compatibility with common interfaces.
[492] Fix | Delete
*
[493] Fix | Delete
* @param string $message The log message
[494] Fix | Delete
* @param array $context The log context
[495] Fix | Delete
*
[496] Fix | Delete
* @return Boolean Whether the record has been processed
[497] Fix | Delete
*/
[498] Fix | Delete
public function warning($message, array $context = array())
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function