ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
firebug.php
Go to the documentation of this file.
1<?php
21class Log_firebug extends Log
22{
28 var $_buffering = false;
29
35 var $_buffer = array();
36
42 var $_lineFormat = '%2$s [%3$s] %4$s';
43
54 var $_timeFormat = '%b %d %H:%M:%S';
55
61 var $_methods = array(
62 PEAR_LOG_EMERG => 'error',
63 PEAR_LOG_ALERT => 'error',
64 PEAR_LOG_CRIT => 'error',
65 PEAR_LOG_ERR => 'error',
66 PEAR_LOG_WARNING => 'warn',
67 PEAR_LOG_NOTICE => 'info',
68 PEAR_LOG_INFO => 'info',
69 PEAR_LOG_DEBUG => 'debug'
70 );
71
81 function Log_firebug($name = '', $ident = 'PHP', $conf = array(),
82 $level = PEAR_LOG_DEBUG)
83 {
84 $this->_id = md5(microtime());
85 $this->_ident = $ident;
86 $this->_mask = Log::UPTO($level);
87 if (isset($conf['buffering'])) {
88 $this->_buffering = $conf['buffering'];
89 }
90
91 if ($this->_buffering) {
92 register_shutdown_function(array(&$this, '_Log_firebug'));
93 }
94
95 if (!empty($conf['lineFormat'])) {
96 $this->_lineFormat = str_replace(array_keys($this->_formatMap),
97 array_values($this->_formatMap),
98 $conf['lineFormat']);
99 }
100
101 if (!empty($conf['timeFormat'])) {
102 $this->_timeFormat = $conf['timeFormat'];
103 }
104 }
105
111 function open()
112 {
113 $this->_opened = true;
114 return true;
115 }
116
120 function _Log_firebug()
121 {
122 $this->close();
123 }
124
130 function close()
131 {
132 $this->flush();
133 $this->_opened = false;
134 return true;
135 }
136
142 function flush() {
143 if (count($this->_buffer)) {
144 print '<script type="text/javascript">';
145 print "\nif (('console' in window) && ('firebug' in console)) {\n";
146 foreach ($this->_buffer as $line) {
147 print " $line\n";
148 }
149 print "}\n";
150 print "</script>\n";
151 };
152 $this->_buffer = array();
153 }
154
167 function log($message, $priority = null)
168 {
169 /* If a priority hasn't been specified, use the default value. */
170 if ($priority === null) {
171 $priority = $this->_priority;
172 }
173
174 /* Abort early if the priority is above the maximum logging level. */
175 if (!$this->_isMasked($priority)) {
176 return false;
177 }
178
179 /* Extract the string representation of the message. */
180 $message = $this->_extractMessage($message);
181 $method = $this->_methods[$priority];
182
183 /* normalize line breaks */
184 $message = str_replace("\r\n", "\n", $message);
185
186 /* escape line breaks */
187 $message = str_replace("\n", "\\n\\\n", $message);
188
189 /* escape quotes */
190 $message = str_replace('"', '\\"', $message);
191
192 /* Build the string containing the complete log line. */
193 $line = $this->_format($this->_lineFormat,
194 strftime($this->_timeFormat),
195 $priority,
196 $message);
197
198 if ($this->_buffering) {
199 $this->_buffer[] = sprintf('console.%s("%s");', $method, $line);
200 } else {
201 print '<script type="text/javascript">';
202 print "\nif (('console' in window) && ('firebug' in console)) {\n";
203 /* Build and output the complete log line. */
204 printf(' console.%s("%s");', $method, $line);
205 print "\n}\n";
206 print "</script>\n";
207 }
208 /* Notify observers about this log message. */
209 $this->_announce(array('priority' => $priority, 'message' => $message));
210
211 return true;
212 }
213
214}
const PEAR_LOG_ALERT
Definition: Log.php:11
const PEAR_LOG_EMERG
Definition: Log.php:10
const PEAR_LOG_ERR
Definition: Log.php:13
const PEAR_LOG_CRIT
Definition: Log.php:12
const PEAR_LOG_DEBUG
Definition: Log.php:17
const PEAR_LOG_INFO
Definition: Log.php:16
const PEAR_LOG_WARNING
Definition: Log.php:14
const PEAR_LOG_NOTICE
Definition: Log.php:15
close()
Closes the firebug handler.
Definition: firebug.php:130
_Log_firebug()
Destructor.
Definition: firebug.php:120
Log_firebug($name='', $ident='PHP', $conf=array(), $level=PEAR_LOG_DEBUG)
Constructs a new Log_firebug object.
Definition: firebug.php:81
log($message, $priority=null)
Writes $message to Firebug console.
Definition: firebug.php:167
open()
Opens the firebug handler.
Definition: firebug.php:111
flush()
Flushes all pending ("buffered") data.
Definition: firebug.php:142
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642
$_priority
Definition: Log.php:69
_isMasked($priority)
Check if the given priority is included in the current level mask.
Definition: Log.php:726
_announce($event)
Informs each registered observer instance that a new message has been logged.
Definition: Log.php:811
_extractMessage($message)
Returns the string representation of the message data.
Definition: Log.php:417
_format($format, $timestamp, $priority, $message)
Produces a formatted log line based on a format string and a set of variables representing the curren...
Definition: Log.php:530
if(! $in) print
The Log:: class implements both an abstraction for various logging mechanisms and the Subject end of ...