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,95 @@
|
|||
<?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\Formatter;
|
||||
|
||||
use Monolog\Formatter\FormatterInterface;
|
||||
|
||||
/**
|
||||
* Formats a log message into a line of text using our custom Piwik log format.
|
||||
*/
|
||||
class LineMessageFormatter implements FormatterInterface
|
||||
{
|
||||
/**
|
||||
* The log message format string that turns a tag name, date-time and message into
|
||||
* one string to log.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $logMessageFormat;
|
||||
|
||||
private $allowInlineLineBreaks;
|
||||
|
||||
/**
|
||||
* @param string $logMessageFormat
|
||||
* @param bool $allowInlineLineBreaks If disabled, a log message will be created for each line
|
||||
*/
|
||||
public function __construct($logMessageFormat, $allowInlineLineBreaks = true)
|
||||
{
|
||||
$this->logMessageFormat = $logMessageFormat;
|
||||
$this->allowInlineLineBreaks = $allowInlineLineBreaks;
|
||||
}
|
||||
|
||||
public function format(array $record)
|
||||
{
|
||||
$class = isset($record['extra']['class']) ? $record['extra']['class'] : '';
|
||||
$date = $record['datetime']->format('Y-m-d H:i:s');
|
||||
|
||||
$message = trim($record['message']);
|
||||
|
||||
if ($this->allowInlineLineBreaks) {
|
||||
$message = str_replace("\n", "\n ", $message); // intend lines
|
||||
$messages = array($message);
|
||||
} else {
|
||||
$messages = explode("\n", $message);
|
||||
}
|
||||
|
||||
$total = '';
|
||||
|
||||
foreach ($messages as $message) {
|
||||
$message = $this->prefixMessageWithRequestId($record, $message);
|
||||
$total .= $this->formatMessage($class, $message, $date, $record);
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
private function formatMessage($class, $message, $date, $record)
|
||||
{
|
||||
$message = str_replace(
|
||||
array('%tag%', '%message%', '%datetime%', '%level%'),
|
||||
array($class, $message, $date, $record['level_name']),
|
||||
$this->logMessageFormat
|
||||
);
|
||||
|
||||
$message .= "\n";
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function formatBatch(array $records)
|
||||
{
|
||||
foreach ($records as $key => $record) {
|
||||
$records[$key] = $this->format($record);
|
||||
}
|
||||
|
||||
return $records;
|
||||
}
|
||||
|
||||
private function prefixMessageWithRequestId(array $record, $message)
|
||||
{
|
||||
$requestId = isset($record['extra']['request_id']) ? $record['extra']['request_id'] : '';
|
||||
|
||||
$message = trim($message);
|
||||
|
||||
if ($requestId) {
|
||||
$message = '[' . $requestId . '] ' . $message;
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
39
www/analytics/plugins/Monolog/Handler/DatabaseHandler.php
Normal file
39
www/analytics/plugins/Monolog/Handler/DatabaseHandler.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?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\Handler;
|
||||
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Piwik\Common;
|
||||
use Piwik\Db;
|
||||
|
||||
/**
|
||||
* Writes log to database.
|
||||
*/
|
||||
class DatabaseHandler extends AbstractProcessingHandler
|
||||
{
|
||||
protected function write(array $record)
|
||||
{
|
||||
$sql = sprintf(
|
||||
'INSERT INTO %s (tag, timestamp, level, message) VALUES (?, ?, ?, ?)',
|
||||
Common::prefixTable('logger_message')
|
||||
);
|
||||
|
||||
$queryLog = Db::isQueryLogEnabled();
|
||||
Db::enableQueryLog(false);
|
||||
|
||||
Db::query($sql, array(
|
||||
$record['extra']['class'],
|
||||
$record['datetime']->format('Y-m-d H:i:s'),
|
||||
$record['level_name'],
|
||||
trim($record['formatted'])
|
||||
));
|
||||
|
||||
Db::enableQueryLog($queryLog);
|
||||
}
|
||||
}
|
||||
24
www/analytics/plugins/Monolog/Handler/EchoHandler.php
Normal file
24
www/analytics/plugins/Monolog/Handler/EchoHandler.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\Handler;
|
||||
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
|
||||
/**
|
||||
* Simply echos all messages.
|
||||
*/
|
||||
class EchoHandler extends AbstractProcessingHandler
|
||||
{
|
||||
protected function write(array $record)
|
||||
{
|
||||
$message = $record['level_name'] . ': ' . $record['message'];
|
||||
|
||||
echo $message . "\n";
|
||||
}
|
||||
}
|
||||
31
www/analytics/plugins/Monolog/Handler/FileHandler.php
Normal file
31
www/analytics/plugins/Monolog/Handler/FileHandler.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?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\Handler;
|
||||
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Piwik\Filechecks;
|
||||
|
||||
/**
|
||||
* Writes log to file.
|
||||
*
|
||||
* Extends StreamHandler to be able to have a custom exception message.
|
||||
*/
|
||||
class FileHandler extends StreamHandler
|
||||
{
|
||||
protected function write(array $record)
|
||||
{
|
||||
try {
|
||||
parent::write($record);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
throw new \Exception(
|
||||
Filechecks::getErrorMessageMissingPermissions($this->url)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?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\Handler;
|
||||
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Logger;
|
||||
use Piwik\Common;
|
||||
use Piwik\Notification;
|
||||
use Piwik\Notification\Manager;
|
||||
use Zend_Session_Exception;
|
||||
|
||||
/**
|
||||
* Writes log messages into HTML notification box.
|
||||
*/
|
||||
class WebNotificationHandler extends AbstractProcessingHandler
|
||||
{
|
||||
protected function write(array $record)
|
||||
{
|
||||
switch ($record['level']) {
|
||||
case Logger::EMERGENCY:
|
||||
case Logger::ALERT:
|
||||
case Logger::CRITICAL:
|
||||
case Logger::ERROR:
|
||||
$context = Notification::CONTEXT_ERROR;
|
||||
break;
|
||||
case Logger::WARNING:
|
||||
$context = Notification::CONTEXT_WARNING;
|
||||
break;
|
||||
default:
|
||||
$context = Notification::CONTEXT_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
$message = $record['level_name'] . ': ' . htmlentities($record['message']);
|
||||
|
||||
$notification = new Notification($message);
|
||||
$notification->context = $context;
|
||||
$notification->flags = 0;
|
||||
try {
|
||||
Manager::notify(Common::getRandomString(), $notification);
|
||||
} catch (Zend_Session_Exception $e) {
|
||||
// Can happen if this handler is enabled in CLI
|
||||
// Silently ignore the error.
|
||||
}
|
||||
}
|
||||
}
|
||||
15
www/analytics/plugins/Monolog/Monolog.php
Normal file
15
www/analytics/plugins/Monolog/Monolog.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?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;
|
||||
|
||||
use Piwik\Plugin;
|
||||
|
||||
class Monolog extends Plugin
|
||||
{
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
29
www/analytics/plugins/Monolog/config/cli.php
Normal file
29
www/analytics/plugins/Monolog/config/cli.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Monolog\Logger;
|
||||
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
|
||||
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
return array(
|
||||
|
||||
// Log
|
||||
'log.handlers' => array(
|
||||
DI\get('Symfony\Bridge\Monolog\Handler\ConsoleHandler'),
|
||||
),
|
||||
'Symfony\Bridge\Monolog\Handler\ConsoleHandler' => function (ContainerInterface $c) {
|
||||
// Override the default verbosity map to make it more verbose by default
|
||||
$verbosityMap = array(
|
||||
OutputInterface::VERBOSITY_NORMAL => Logger::INFO,
|
||||
OutputInterface::VERBOSITY_VERBOSE => Logger::DEBUG,
|
||||
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::DEBUG,
|
||||
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
|
||||
);
|
||||
$handler = new ConsoleHandler(null, true, $verbosityMap);
|
||||
$handler->setFormatter(new ConsoleFormatter($c->get('log.console.format'), null, true, true));
|
||||
return $handler;
|
||||
},
|
||||
'log.console.format' => '%start_tag%%level_name% [%datetime%]%end_tag% %message%' . PHP_EOL,
|
||||
|
||||
);
|
||||
108
www/analytics/plugins/Monolog/config/config.php
Normal file
108
www/analytics/plugins/Monolog/config/config.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Monolog\Logger;
|
||||
use Piwik\Log;
|
||||
|
||||
return array(
|
||||
|
||||
'Monolog\Logger' => DI\object('Monolog\Logger')
|
||||
->constructor('piwik', DI\get('log.handlers'), DI\get('log.processors')),
|
||||
|
||||
'Psr\Log\LoggerInterface' => DI\get('Monolog\Logger'),
|
||||
|
||||
'log.handler.classes' => array(
|
||||
'file' => 'Piwik\Plugins\Monolog\Handler\FileHandler',
|
||||
'screen' => 'Piwik\Plugins\Monolog\Handler\WebNotificationHandler',
|
||||
'database' => 'Piwik\Plugins\Monolog\Handler\DatabaseHandler',
|
||||
),
|
||||
'log.handlers' => DI\factory(function (ContainerInterface $c) {
|
||||
if ($c->has('ini.log.log_writers')) {
|
||||
$writerNames = $c->get('ini.log.log_writers');
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
|
||||
$classes = $c->get('log.handler.classes');
|
||||
|
||||
$writerNames = array_map('trim', $writerNames);
|
||||
$writers = array();
|
||||
foreach ($writerNames as $writerName) {
|
||||
if (isset($classes[$writerName])) {
|
||||
$writers[$writerName] = $c->get($classes[$writerName]);
|
||||
}
|
||||
}
|
||||
return array_values($writers);
|
||||
}),
|
||||
|
||||
'log.processors' => array(
|
||||
DI\get('Piwik\Plugins\Monolog\Processor\SprintfProcessor'),
|
||||
DI\get('Piwik\Plugins\Monolog\Processor\ClassNameProcessor'),
|
||||
DI\get('Piwik\Plugins\Monolog\Processor\RequestIdProcessor'),
|
||||
DI\get('Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor'),
|
||||
DI\get('Monolog\Processor\PsrLogMessageProcessor'),
|
||||
DI\get('Piwik\Plugins\Monolog\Processor\TokenProcessor'),
|
||||
),
|
||||
|
||||
'Piwik\Plugins\Monolog\Handler\FileHandler' => DI\object()
|
||||
->constructor(DI\get('log.file.filename'), DI\get('log.level'))
|
||||
->method('setFormatter', DI\get('log.lineMessageFormatter.file')),
|
||||
|
||||
'log.lineMessageFormatter.file' => DI\object('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter')
|
||||
->constructorParameter('allowInlineLineBreaks', false),
|
||||
|
||||
'Piwik\Plugins\Monolog\Handler\DatabaseHandler' => DI\object()
|
||||
->constructor(DI\get('log.level'))
|
||||
->method('setFormatter', DI\get('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter')),
|
||||
|
||||
'Piwik\Plugins\Monolog\Handler\WebNotificationHandler' => DI\object()
|
||||
->constructor(DI\get('log.level'))
|
||||
->method('setFormatter', DI\get('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter')),
|
||||
|
||||
'log.level' => DI\factory(function (ContainerInterface $c) {
|
||||
if ($c->has('ini.log.log_level')) {
|
||||
$level = strtoupper($c->get('ini.log.log_level'));
|
||||
if (!empty($level) && defined('Piwik\Log::'.strtoupper($level))) {
|
||||
return Log::getMonologLevel(constant('Piwik\Log::'.strtoupper($level)));
|
||||
}
|
||||
}
|
||||
return Logger::WARNING;
|
||||
}),
|
||||
|
||||
'log.file.filename' => DI\factory(function (ContainerInterface $c) {
|
||||
$logPath = $c->get('ini.log.logger_file_path');
|
||||
|
||||
// Absolute path
|
||||
if (strpos($logPath, '/') === 0) {
|
||||
return $logPath;
|
||||
}
|
||||
|
||||
// Remove 'tmp/' at the beginning
|
||||
if (strpos($logPath, 'tmp/') === 0) {
|
||||
$logPath = substr($logPath, strlen('tmp'));
|
||||
}
|
||||
|
||||
if (empty($logPath)) {
|
||||
// Default log file
|
||||
$logPath = '/logs/piwik.log';
|
||||
}
|
||||
|
||||
$logPath = $c->get('path.tmp') . $logPath;
|
||||
if (is_dir($logPath)) {
|
||||
$logPath .= '/piwik.log';
|
||||
}
|
||||
|
||||
return $logPath;
|
||||
}),
|
||||
|
||||
'Piwik\Plugins\Monolog\Formatter\LineMessageFormatter' => DI\object()
|
||||
->constructor(DI\get('log.format')),
|
||||
|
||||
'log.format' => DI\factory(function (ContainerInterface $c) {
|
||||
if ($c->has('ini.log.string_message_format')) {
|
||||
return $c->get('ini.log.string_message_format');
|
||||
}
|
||||
return '%level% %tag%[%datetime%] %message%';
|
||||
}),
|
||||
|
||||
);
|
||||
37
www/analytics/plugins/Monolog/config/tracker.php
Normal file
37
www/analytics/plugins/Monolog/config/tracker.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
function isTrackerDebugEnabled(ContainerInterface $c)
|
||||
{
|
||||
$trackerDebug = $c->get("ini.Tracker.debug");
|
||||
return ($trackerDebug == 1 || !empty($GLOBALS['PIWIK_TRACKER_DEBUG']));
|
||||
}
|
||||
|
||||
return array(
|
||||
|
||||
'Psr\Log\LoggerInterface' => function (ContainerInterface $c) {
|
||||
if (isTrackerDebugEnabled($c)) {
|
||||
return $c->get('Monolog\Logger');
|
||||
} else {
|
||||
return new \Psr\Log\NullLogger();
|
||||
}
|
||||
},
|
||||
|
||||
'log.handler.classes' => DI\decorate(function ($previous) {
|
||||
if (isset($previous['screen'])) {
|
||||
$previous['screen'] = 'Piwik\Plugins\Monolog\Handler\EchoHandler';
|
||||
}
|
||||
|
||||
return $previous;
|
||||
}),
|
||||
|
||||
'log.level' => DI\decorate(function ($previous, ContainerInterface $c) {
|
||||
if (isTrackerDebugEnabled($c)) {
|
||||
return \Monolog\Logger::DEBUG;
|
||||
}
|
||||
|
||||
return $previous;
|
||||
})
|
||||
|
||||
);
|
||||
3
www/analytics/plugins/Monolog/plugin.json
Normal file
3
www/analytics/plugins/Monolog/plugin.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"description": "Adds logging capabilities to Piwik."
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue