PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,99 @@
<?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'];
$exceptionStr = sprintf(
"%s(%d): %s\n%s",
$exception instanceof \Exception ? $exception->getFile() : $exception['file'],
$exception instanceof \Exception ? $exception->getLine() : $exception['line'],
$this->getMessage($exception),
$this->getStackTrace($exception)
);
if (!isset($record['message'])
|| strpos($record['message'], '{exception}') === false
) {
$record['message'] = $exceptionStr;
} else {
$record['message'] = str_replace('{exception}', $exceptionStr, $record['message']);
}
return $record;
}
private function contextContainsException($record)
{
return isset($record['context']['exception'])
&& ($record['context']['exception'] instanceof \Exception
|| $this->isLooksLikeFatalErrorArray($record['context']['exception']));
}
private function isLooksLikeFatalErrorArray($exception)
{
return is_array($exception) && isset($exception['message']) && isset($exception['file']) && isset($exception['line']);
}
private function getMessage($exception)
{
if ($exception instanceof \ErrorException) {
return ErrorHandler::getErrNoString($exception->getSeverity()) . ' - ' . $exception->getMessage();
}
if (is_array($exception) && isset($exception['message'])) {
return $exception['message'];
}
return $exception->getMessage();
}
private function getStackTrace($exception)
{
if (is_array($exception) && isset($exception['backtrace'])) {
return $exception['backtrace'];
}
return Log::$debugBacktraceForTests ?: self::getWholeBacktrace($exception);
}
public static function getWholeBacktrace(\Exception $exception, $shouldPrintBacktrace = true)
{
$message = "";
$e = $exception;
do {
if ($e !== $exception) {
$message .= ",\ncaused by: ";
}
$message .= $e->getMessage();
if ($shouldPrintBacktrace) {
$message .= "\n" . $e->getTraceAsString();
}
} while ($e = $e->getPrevious());
return $message;
}
}

View File

@ -0,0 +1,35 @@
<?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;
use Piwik\FrontController;
/**
* 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 (empty($this->currentRequestKey)) {
if (Common::isPhpCliMode()) {
$this->currentRequestKey = getmypid();
} else {
$this->currentRequestKey = FrontController::getUniqueRequestId();
}
}
$record['extra']['request_id'] = $this->currentRequestKey;
return $record;
}
}

View 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;
}
}

View 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;
}
}