scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 114  →  ?path2? @ 115
/vendor/monolog/monolog/src/Monolog/Processor/GitProcessor.php
@@ -0,0 +1,64 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
use Monolog\Logger;
 
/**
* Injects Git branch and Git commit SHA in all records
*
* @author Nick Otter
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class GitProcessor
{
private $level;
private static $cache;
 
public function __construct($level = Logger::DEBUG)
{
$this->level = Logger::toMonologLevel($level);
}
 
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
// return if the level is not high enough
if ($record['level'] < $this->level) {
return $record;
}
 
$record['extra']['git'] = self::getGitInfo();
 
return $record;
}
 
private static function getGitInfo()
{
if (self::$cache) {
return self::$cache;
}
 
$branches = `git branch -v --no-abbrev`;
if (preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) {
return self::$cache = array(
'branch' => $matches[1],
'commit' => $matches[2],
);
}
 
return self::$cache = array();
}
}
/vendor/monolog/monolog/src/Monolog/Processor/IntrospectionProcessor.php
@@ -0,0 +1,112 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
use Monolog\Logger;
 
/**
* Injects line/file:class/function where the log message came from
*
* Warning: This only works if the handler processes the logs directly.
* If you put the processor on a handler that is behind a FingersCrossedHandler
* for example, the processor will only be called once the trigger level is reached,
* and all the log records will have the same file/line/.. data from the call that
* triggered the FingersCrossedHandler.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class IntrospectionProcessor
{
private $level;
 
private $skipClassesPartials;
 
private $skipStackFramesCount;
 
private $skipFunctions = array(
'call_user_func',
'call_user_func_array',
);
 
public function __construct($level = Logger::DEBUG, array $skipClassesPartials = array(), $skipStackFramesCount = 0)
{
$this->level = Logger::toMonologLevel($level);
$this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials);
$this->skipStackFramesCount = $skipStackFramesCount;
}
 
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
// return if the level is not high enough
if ($record['level'] < $this->level) {
return $record;
}
 
/*
* http://php.net/manual/en/function.debug-backtrace.php
* As of 5.3.6, DEBUG_BACKTRACE_IGNORE_ARGS option was added.
* Any version less than 5.3.6 must use the DEBUG_BACKTRACE_IGNORE_ARGS constant value '2'.
*/
$trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
 
// skip first since it's always the current method
array_shift($trace);
// the call_user_func call is also skipped
array_shift($trace);
 
$i = 0;
 
while ($this->isTraceClassOrSkippedFunction($trace, $i)) {
if (isset($trace[$i]['class'])) {
foreach ($this->skipClassesPartials as $part) {
if (strpos($trace[$i]['class'], $part) !== false) {
$i++;
continue 2;
}
}
} elseif (in_array($trace[$i]['function'], $this->skipFunctions)) {
$i++;
continue;
}
 
break;
}
 
$i += $this->skipStackFramesCount;
 
// we should have the call source now
$record['extra'] = array_merge(
$record['extra'],
array(
'file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null,
'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null,
'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
)
);
 
return $record;
}
 
private function isTraceClassOrSkippedFunction(array $trace, $index)
{
if (!isset($trace[$index])) {
return false;
}
 
return isset($trace[$index]['class']) || in_array($trace[$index]['function'], $this->skipFunctions);
}
}
/vendor/monolog/monolog/src/Monolog/Processor/MemoryPeakUsageProcessor.php
@@ -0,0 +1,35 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Injects memory_get_peak_usage in all records
*
* @see Monolog\Processor\MemoryProcessor::__construct() for options
* @author Rob Jensen
*/
class MemoryPeakUsageProcessor extends MemoryProcessor
{
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
$bytes = memory_get_peak_usage($this->realUsage);
$formatted = $this->formatBytes($bytes);
 
$record['extra']['memory_peak_usage'] = $formatted;
 
return $record;
}
}
/vendor/monolog/monolog/src/Monolog/Processor/MemoryProcessor.php
@@ -0,0 +1,63 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Some methods that are common for all memory processors
*
* @author Rob Jensen
*/
abstract class MemoryProcessor
{
/**
* @var bool If true, get the real size of memory allocated from system. Else, only the memory used by emalloc() is reported.
*/
protected $realUsage;
 
/**
* @var bool If true, then format memory size to human readable string (MB, KB, B depending on size)
*/
protected $useFormatting;
 
/**
* @param bool $realUsage Set this to true to get the real size of memory allocated from system.
* @param bool $useFormatting If true, then format memory size to human readable string (MB, KB, B depending on size)
*/
public function __construct($realUsage = true, $useFormatting = true)
{
$this->realUsage = (boolean) $realUsage;
$this->useFormatting = (boolean) $useFormatting;
}
 
/**
* Formats bytes into a human readable string if $this->useFormatting is true, otherwise return $bytes as is
*
* @param int $bytes
* @return string|int Formatted string if $this->useFormatting is true, otherwise return $bytes as is
*/
protected function formatBytes($bytes)
{
$bytes = (int) $bytes;
 
if (!$this->useFormatting) {
return $bytes;
}
 
if ($bytes > 1024 * 1024) {
return round($bytes / 1024 / 1024, 2).' MB';
} elseif ($bytes > 1024) {
return round($bytes / 1024, 2).' KB';
}
 
return $bytes . ' B';
}
}
/vendor/monolog/monolog/src/Monolog/Processor/MemoryUsageProcessor.php
@@ -0,0 +1,35 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Injects memory_get_usage in all records
*
* @see Monolog\Processor\MemoryProcessor::__construct() for options
* @author Rob Jensen
*/
class MemoryUsageProcessor extends MemoryProcessor
{
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
$bytes = memory_get_usage($this->realUsage);
$formatted = $this->formatBytes($bytes);
 
$record['extra']['memory_usage'] = $formatted;
 
return $record;
}
}
/vendor/monolog/monolog/src/Monolog/Processor/MercurialProcessor.php
@@ -0,0 +1,63 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jonathan A. Schweder <jonathanschweder@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
use Monolog\Logger;
 
/**
* Injects Hg branch and Hg revision number in all records
*
* @author Jonathan A. Schweder <jonathanschweder@gmail.com>
*/
class MercurialProcessor
{
private $level;
private static $cache;
 
public function __construct($level = Logger::DEBUG)
{
$this->level = Logger::toMonologLevel($level);
}
 
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
// return if the level is not high enough
if ($record['level'] < $this->level) {
return $record;
}
 
$record['extra']['hg'] = self::getMercurialInfo();
 
return $record;
}
 
private static function getMercurialInfo()
{
if (self::$cache) {
return self::$cache;
}
 
$result = explode(' ', trim(`hg id -nb`));
if (count($result) >= 3) {
return self::$cache = array(
'branch' => $result[1],
'revision' => $result[2],
);
}
 
return self::$cache = array();
}
}
/vendor/monolog/monolog/src/Monolog/Processor/ProcessIdProcessor.php
@@ -0,0 +1,31 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Adds value of getmypid into records
*
* @author Andreas Hörnicke
*/
class ProcessIdProcessor
{
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
$record['extra']['process_id'] = getmypid();
 
return $record;
}
}
/vendor/monolog/monolog/src/Monolog/Processor/PsrLogMessageProcessor.php
@@ -0,0 +1,48 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Processes a record's message according to PSR-3 rules
*
* It replaces {foo} with the value from $context['foo']
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class PsrLogMessageProcessor
{
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
if (false === strpos($record['message'], '{')) {
return $record;
}
 
$replacements = array();
foreach ($record['context'] as $key => $val) {
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) {
$replacements['{'.$key.'}'] = $val;
} elseif (is_object($val)) {
$replacements['{'.$key.'}'] = '[object '.get_class($val).']';
} else {
$replacements['{'.$key.'}'] = '['.gettype($val).']';
}
}
 
$record['message'] = strtr($record['message'], $replacements);
 
return $record;
}
}
/vendor/monolog/monolog/src/Monolog/Processor/TagProcessor.php
@@ -0,0 +1,44 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Adds a tags array into record
*
* @author Martijn Riemers
*/
class TagProcessor
{
private $tags;
 
public function __construct(array $tags = array())
{
$this->setTags($tags);
}
 
public function addTags(array $tags = array())
{
$this->tags = array_merge($this->tags, $tags);
}
 
public function setTags(array $tags = array())
{
$this->tags = $tags;
}
 
public function __invoke(array $record)
{
$record['extra']['tags'] = $this->tags;
 
return $record;
}
}
/vendor/monolog/monolog/src/Monolog/Processor/UidProcessor.php
@@ -0,0 +1,46 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Adds a unique identifier into records
*
* @author Simon Mönch <sm@webfactory.de>
*/
class UidProcessor
{
private $uid;
 
public function __construct($length = 7)
{
if (!is_int($length) || $length > 32 || $length < 1) {
throw new \InvalidArgumentException('The uid length must be an integer between 1 and 32');
}
 
$this->uid = substr(hash('md5', uniqid('', true)), 0, $length);
}
 
public function __invoke(array $record)
{
$record['extra']['uid'] = $this->uid;
 
return $record;
}
 
/**
* @return string
*/
public function getUid()
{
return $this->uid;
}
}
/vendor/monolog/monolog/src/Monolog/Processor/WebProcessor.php
@@ -0,0 +1,113 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
/**
* Injects url/method and remote IP of the current web request in all records
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class WebProcessor
{
/**
* @var array|\ArrayAccess
*/
protected $serverData;
 
/**
* Default fields
*
* Array is structured as [key in record.extra => key in $serverData]
*
* @var array
*/
protected $extraFields = array(
'url' => 'REQUEST_URI',
'ip' => 'REMOTE_ADDR',
'http_method' => 'REQUEST_METHOD',
'server' => 'SERVER_NAME',
'referrer' => 'HTTP_REFERER',
);
 
/**
* @param array|\ArrayAccess $serverData Array or object w/ ArrayAccess that provides access to the $_SERVER data
* @param array|null $extraFields Field names and the related key inside $serverData to be added. If not provided it defaults to: url, ip, http_method, server, referrer
*/
public function __construct($serverData = null, array $extraFields = null)
{
if (null === $serverData) {
$this->serverData = &$_SERVER;
} elseif (is_array($serverData) || $serverData instanceof \ArrayAccess) {
$this->serverData = $serverData;
} else {
throw new \UnexpectedValueException('$serverData must be an array or object implementing ArrayAccess.');
}
 
if (null !== $extraFields) {
if (isset($extraFields[0])) {
foreach (array_keys($this->extraFields) as $fieldName) {
if (!in_array($fieldName, $extraFields)) {
unset($this->extraFields[$fieldName]);
}
}
} else {
$this->extraFields = $extraFields;
}
}
}
 
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
// skip processing if for some reason request data
// is not present (CLI or wonky SAPIs)
if (!isset($this->serverData['REQUEST_URI'])) {
return $record;
}
 
$record['extra'] = $this->appendExtraFields($record['extra']);
 
return $record;
}
 
/**
* @param string $extraName
* @param string $serverName
* @return $this
*/
public function addExtraField($extraName, $serverName)
{
$this->extraFields[$extraName] = $serverName;
 
return $this;
}
 
/**
* @param array $extra
* @return array
*/
private function appendExtraFields(array $extra)
{
foreach ($this->extraFields as $extraName => $serverName) {
$extra[$extraName] = isset($this->serverData[$serverName]) ? $this->serverData[$serverName] : null;
}
 
if (isset($this->serverData['UNIQUE_ID'])) {
$extra['unique_id'] = $this->serverData['UNIQUE_ID'];
}
 
return $extra;
}
}