1: <?php
2:
3: /**
4: * @author Lorenz Weber <mail@phryneas.de>
5: * @copyright (c) 2013, Lorenz Weber
6: * @package loggedPDO
7: *
8: * The MIT License (MIT)
9: *
10: * @copyright (c) 2013, Lorenz Weber
11: *
12: * Permission is hereby granted, free of charge, to any person obtaining a copy
13: * of this software and associated documentation files (the "Software"), to deal
14: * in the Software without restriction, including without limitation the rights
15: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16: * copies of the Software, and to permit persons to whom the Software is
17: * furnished to do so, subject to the following conditions:
18: *
19: * The above copyright notice and this permission notice shall be included in
20: * all copies or substantial portions of the Software.
21: *
22: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28: * THE SOFTWARE.
29: */
30: // we're using the PEAR Log package
31:
32:
33: if (stream_resolve_include_path('Log.php'))
34: require_once 'Log.php';
35: else
36: die("Failure including Log.php\nplease install PEAR::Log or check your include_path\n");
37:
38: if (stream_resolve_include_path('Log/firebug.php'))
39: require_once 'Log/firebug.php';
40: else
41: throw new \Exception("Failure including Log/firebug.php\nplease install PEAR::Log or check your include_path\n");
42:
43: /**
44: * @uses Log.php
45: * extends normal Log_firebug: message will be passed & displayed as json encoded object
46: */
47: class Log_firebugJSON extends Log_firebug {
48:
49: function log($message, $priority = null) {
50: /* If a priority hasn't been specified, use the default value. */
51: if ($priority === null) {
52: $priority = $this->_priority;
53: }
54:
55: /* Abort early if the priority is above the maximum logging level. */
56: if (!$this->_isMasked($priority)) {
57: return false;
58: }
59:
60: /* Extract the string representation of the message. */
61: $method = $this->_methods[$priority];
62: /* prepare object to apss to firebug */
63: $object = json_encode($message);
64: /* continue preparing message for _announce */
65: $message_announce = preg_replace("/\r?\n/", "\\n", addslashes($this->_extractMessage($message)));
66:
67: /* Build the string containing the log line prefix. */
68: $prefix = $this->_format($this->_lineFormat, strftime($this->_timeFormat), $priority, '');
69:
70:
71: if ($this->_buffering) {
72: $this->_buffer[] = sprintf('console.%s("%s", %s);', $method, $prefix, $object);
73: } else {
74: print '<script type="text/javascript">';
75: print "\nif ('console' in window) {\n";
76: /* Build and output the complete log line. */
77: printf(' console.%s("%s", %s);', $method, $prefix, $object);
78: print "\n}\n";
79: print "</script>\n";
80: }
81: /* Notify observers about this log message. */
82: $this->_announce(array('priority' => $priority, 'message' => $message_announce));
83:
84: return true;
85: }
86:
87: }
88:
89: ?>
90: