Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2014-12-15 01:24:52 +0300
committerMatthieu Napoli <matthieu@mnapoli.fr>2014-12-15 01:24:52 +0300
commit49713cebc9102853265324e697513802932c5e2a (patch)
treea2f2bc4590ec64b9ef55969cd7c2c7b21ecf9d8f /core
parent5c2669513e8561ce2f62aa08c37ef806e43001d7 (diff)
#6622 Logger refactoring: restored the "screen" backend to log to HTML notifications
The "screen" backend (WebNotificationHandler) now logs to HTML notification boxes using the `Notification` api. I've re-set the default log level to WARN, and logged PHP notices/warnings to "warning" so that on a default install they are shown in the page in a yellow/warning notification box. For the record, the default log level had previously been changed from WARN to ERROR because screen logging was previously messing the HTML/JSON output (which was breaking archiving). With the logger refactoring this is no longer a problem.
Diffstat (limited to 'core')
-rw-r--r--core/Error.php2
-rw-r--r--core/Log/Handler/WebNotificationHandler.php45
2 files changed, 46 insertions, 1 deletions
diff --git a/core/Error.php b/core/Error.php
index 0dd346244f..6b69e68848 100644
--- a/core/Error.php
+++ b/core/Error.php
@@ -94,7 +94,7 @@ class Error
case E_DEPRECATED:
case E_USER_DEPRECATED:
default:
- Log::info(self::createLogMessage($errno, $errstr, $errfile, $errline));
+ Log::warning(self::createLogMessage($errno, $errstr, $errfile, $errline));
break;
}
}
diff --git a/core/Log/Handler/WebNotificationHandler.php b/core/Log/Handler/WebNotificationHandler.php
new file mode 100644
index 0000000000..af9afbe68e
--- /dev/null
+++ b/core/Log/Handler/WebNotificationHandler.php
@@ -0,0 +1,45 @@
+<?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\Log\Handler;
+
+use Monolog\Handler\AbstractProcessingHandler;
+use Monolog\Logger;
+use Piwik\Common;
+use Piwik\Notification;
+use Piwik\Notification\Manager;
+
+/**
+ * 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 = htmlentities($record['formatted']);
+
+ $notification = new Notification($message);
+ $notification->context = $context;
+ Manager::notify(Common::getRandomString(), $notification);
+ }
+}