diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-15 01:24:52 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-15 01:24:52 +0300 |
commit | 49713cebc9102853265324e697513802932c5e2a (patch) | |
tree | a2f2bc4590ec64b9ef55969cd7c2c7b21ecf9d8f /core/Log | |
parent | 5c2669513e8561ce2f62aa08c37ef806e43001d7 (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/Log')
-rw-r--r-- | core/Log/Handler/WebNotificationHandler.php | 45 |
1 files changed, 45 insertions, 0 deletions
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); + } +} |