ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RollbarHandler.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
14use RollbarNotifier;
15use Exception;
17
35{
42
43 protected $levelMap = array(
44 Logger::DEBUG => 'debug',
45 Logger::INFO => 'info',
46 Logger::NOTICE => 'info',
47 Logger::WARNING => 'warning',
48 Logger::ERROR => 'error',
49 Logger::CRITICAL => 'critical',
50 Logger::ALERT => 'critical',
51 Logger::EMERGENCY => 'critical',
52 );
53
59 private $hasRecords = false;
60
61 protected $initialized = false;
62
68 public function __construct(RollbarNotifier $rollbarNotifier, $level = Logger::ERROR, $bubble = true)
69 {
70 $this->rollbarNotifier = $rollbarNotifier;
71
72 parent::__construct($level, $bubble);
73 }
74
78 protected function write(array $record)
79 {
80 if (!$this->initialized) {
81 // __destructor() doesn't get called on Fatal errors
82 register_shutdown_function(array($this, 'close'));
83 $this->initialized = true;
84 }
85
86 $context = $record['context'];
87 $payload = array();
88 if (isset($context['payload'])) {
89 $payload = $context['payload'];
90 unset($context['payload']);
91 }
92 $context = array_merge($context, $record['extra'], array(
93 'level' => $this->levelMap[$record['level']],
94 'monolog_level' => $record['level_name'],
95 'channel' => $record['channel'],
96 'datetime' => $record['datetime']->format('U'),
97 ));
98
99 if (isset($context['exception']) && $context['exception'] instanceof Exception) {
100 $payload['level'] = $context['level'];
101 $exception = $context['exception'];
102 unset($context['exception']);
103
104 $this->rollbarNotifier->report_exception($exception, $context, $payload);
105 } else {
106 $this->rollbarNotifier->report_message(
107 $record['message'],
108 $context['level'],
109 $context,
110 $payload
111 );
112 }
113
114 $this->hasRecords = true;
115 }
116
117 public function flush()
118 {
119 if ($this->hasRecords) {
120 $this->rollbarNotifier->flush();
121 $this->hasRecords = false;
122 }
123 }
124
128 public function close()
129 {
130 $this->flush();
131 }
132
136 public function reset()
137 {
138 $this->flush();
139
140 parent::reset();
141 }
142
143
144}
An exception for terminatinating execution or to throw for unit testing.
Base Handler class providing the Handler structure.
Sends errors to Rollbar.
close()
{Closes the handler.This will be called automatically when the object is destroyed}
write(array $record)
{Writes the record down to the log of the implementing handler.void}
__construct(RollbarNotifier $rollbarNotifier, $level=Logger::ERROR, $bubble=true)
Monolog log channel.
Definition: Logger.php:29
const EMERGENCY
Urgent alert.
Definition: Logger.php:78
const ERROR
Runtime errors.
Definition: Logger.php:58
const CRITICAL
Critical conditions.
Definition: Logger.php:65
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53
const INFO
Interesting events.
Definition: Logger.php:40
const DEBUG
Detailed debug information.
Definition: Logger.php:33
const NOTICE
Uncommon events.
Definition: Logger.php:45
const ALERT
Action must be taken immediately.
Definition: Logger.php:73
$context
Definition: webdav.php:25