update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\Monolog\Processor;
|
||||
|
||||
use Piwik\Plugin;
|
||||
|
||||
/**
|
||||
* Records the name of the class that logged.
|
||||
*/
|
||||
class ClassNameProcessor
|
||||
{
|
||||
private $skippedClasses = array(
|
||||
__CLASS__,
|
||||
'Piwik\Log',
|
||||
'Piwik\Piwik',
|
||||
'Piwik\CronArchive',
|
||||
'Monolog\Logger',
|
||||
);
|
||||
|
||||
public function __invoke(array $record)
|
||||
{
|
||||
$record['extra']['class'] = $this->getLoggingClassName();
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the plugin/class that triggered the log.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getLoggingClassName()
|
||||
{
|
||||
$backtrace = $this->getBacktrace();
|
||||
|
||||
$name = Plugin::getPluginNameFromBacktrace($backtrace);
|
||||
|
||||
// if we can't determine the plugin, use the name of the calling class
|
||||
if ($name == false) {
|
||||
$name = $this->getClassNameThatIsLogging($backtrace);
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
private function getClassNameThatIsLogging($backtrace)
|
||||
{
|
||||
foreach ($backtrace as $line) {
|
||||
if (isset($line['class'])) {
|
||||
return $line['class'];
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function getBacktrace()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.3.6', '>=')) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
|
||||
} else {
|
||||
$backtrace = debug_backtrace();
|
||||
}
|
||||
|
||||
$skippedClasses = $this->skippedClasses;
|
||||
$backtrace = array_filter($backtrace, function ($item) use ($skippedClasses) {
|
||||
if (isset($item['class'])) {
|
||||
return !in_array($item['class'], $skippedClasses);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return $backtrace;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\Monolog\Processor;
|
||||
|
||||
use Piwik\ErrorHandler;
|
||||
use Piwik\Log;
|
||||
|
||||
/**
|
||||
* Process a log record containing an exception to generate a textual message.
|
||||
*/
|
||||
class ExceptionToTextProcessor
|
||||
{
|
||||
public function __invoke(array $record)
|
||||
{
|
||||
if (! $this->contextContainsException($record)) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
/** @var \Exception $exception */
|
||||
$exception = $record['context']['exception'];
|
||||
|
||||
$record['message'] = sprintf(
|
||||
"%s(%d): %s\n%s",
|
||||
$exception->getFile(),
|
||||
$exception->getLine(),
|
||||
$this->getMessage($exception),
|
||||
$this->getStackTrace($exception)
|
||||
);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
private function contextContainsException($record)
|
||||
{
|
||||
return isset($record['context']['exception'])
|
||||
&& $record['context']['exception'] instanceof \Exception;
|
||||
}
|
||||
|
||||
private function getMessage(\Exception $exception)
|
||||
{
|
||||
if ($exception instanceof \ErrorException) {
|
||||
return ErrorHandler::getErrNoString($exception->getSeverity()) . ' - ' . $exception->getMessage();
|
||||
}
|
||||
|
||||
return $exception->getMessage();
|
||||
}
|
||||
|
||||
private function getStackTrace(\Exception $exception)
|
||||
{
|
||||
return Log::$debugBacktraceForTests ?: $exception->getTraceAsString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\Monolog\Processor;
|
||||
|
||||
use Piwik\Common;
|
||||
|
||||
/**
|
||||
* Adds a unique "request id" to the log message to follow log entries for each HTTP request.
|
||||
*/
|
||||
class RequestIdProcessor
|
||||
{
|
||||
private $currentRequestKey;
|
||||
|
||||
public function __invoke(array $record)
|
||||
{
|
||||
if (Common::isPhpCliMode()) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
if (empty($this->currentRequestKey)) {
|
||||
$this->currentRequestKey = substr(Common::generateUniqId(), 0, 5);
|
||||
}
|
||||
|
||||
$record['extra']['request_id'] = $this->currentRequestKey;
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
42
www/analytics/plugins/Monolog/Processor/SprintfProcessor.php
Normal file
42
www/analytics/plugins/Monolog/Processor/SprintfProcessor.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\Monolog\Processor;
|
||||
|
||||
/**
|
||||
* Processes a log message using `sprintf()`.
|
||||
*/
|
||||
class SprintfProcessor
|
||||
{
|
||||
public function __invoke(array $record)
|
||||
{
|
||||
$message = $record['message'];
|
||||
$parameters = $record['context'];
|
||||
|
||||
if (is_string($message) && !empty($parameters) && strpos($message, '%') !== false) {
|
||||
$parameters = $this->ensureParametersAreStrings($parameters);
|
||||
|
||||
$record['message'] = vsprintf($message, $parameters);
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
private function ensureParametersAreStrings(array $parameters)
|
||||
{
|
||||
foreach ($parameters as &$param) {
|
||||
if (is_array($param)) {
|
||||
$param = json_encode($param);
|
||||
} elseif (is_object($param)) {
|
||||
$param = get_class($param);
|
||||
}
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
}
|
||||
24
www/analytics/plugins/Monolog/Processor/TokenProcessor.php
Normal file
24
www/analytics/plugins/Monolog/Processor/TokenProcessor.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\Monolog\Processor;
|
||||
|
||||
/**
|
||||
* Removes any token_auth that might appear in the logs.
|
||||
*
|
||||
* Ideally the token_auth should never be logged, but...
|
||||
*/
|
||||
class TokenProcessor
|
||||
{
|
||||
public function __invoke(array $record)
|
||||
{
|
||||
$record['message'] = preg_replace('/token_auth=[0-9a-h]+/', 'token_auth=removed', $record['message']);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue