Packages

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • DebugBar
  • DebugBlueScreen
  • Debugger
  • DebugHelpers
  • FireLogger
  • Logger

Interfaces

  • IBarPanel
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Diagnostics
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * FireLogger console logger.
 17:  *
 18:  * @see http://firelogger.binaryage.com
 19:  * @author     David Grudl
 20:  * @package Nette\Diagnostics
 21:  */
 22: class FireLogger extends Object
 23: {
 24:     const DEBUG = 'debug',
 25:         INFO = 'info',
 26:         WARNING = 'warning',
 27:         ERROR = 'error',
 28:         CRITICAL = 'critical';
 29: 
 30:     private static $payload = array('logs' => array());
 31: 
 32: 
 33: 
 34:     /**
 35:      * Sends message to FireLogger console.
 36:      * @param  mixed
 37:      * @return bool    was successful?
 38:      */
 39:     public static function log($message, $priority = self::DEBUG)
 40:     {
 41:         if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) {
 42:             return FALSE;
 43:         }
 44: 
 45:         $item = array(
 46:             'name' => 'PHP',
 47:             'level' => $priority,
 48:             'order' => count(self::$payload['logs']),
 49:             'time' => str_pad(number_format((microtime(TRUE) - Debugger::$time) * 1000, 1, '.', ' '), 8, '0', STR_PAD_LEFT) . ' ms',
 50:             'template' => '',
 51:             'message' => '',
 52:             'style' => 'background:#767ab6',
 53:         );
 54: 
 55:         $args = func_get_args();
 56:         if (isset($args[0]) && is_string($args[0])) {
 57:             $item['template'] = array_shift($args);
 58:         }
 59: 
 60:         if (isset($args[0]) && $args[0] instanceof Exception) {
 61:             $e = array_shift($args);
 62:             $trace = $e->getTrace();
 63:             if (isset($trace[0]['class']) && $trace[0]['class'] === 'Debugger'
 64:                 && ($trace[0]['function'] === '_shutdownHandler' || $trace[0]['function'] === '_errorHandler')
 65:             ) {
 66:                 unset($trace[0]);
 67:             }
 68: 
 69:             $file = str_replace(dirname(dirname(dirname($e->getFile()))), "\xE2\x80\xA6", $e->getFile());
 70:             $item['template'] = ($e instanceof ErrorException ? '' : get_class($e) . ': ')
 71:                 . $e->getMessage() . ($e->getCode() ? ' #' . $e->getCode() : '') . ' in ' . $file . ':' . $e->getLine();
 72:             $item['pathname'] = $e->getFile();
 73:             $item['lineno'] = $e->getLine();
 74: 
 75:         } else {
 76:             $trace = debug_backtrace();
 77:             if (isset($trace[1]['class']) && $trace[1]['class'] === 'Debugger'
 78:                 && ($trace[1]['function'] === 'fireLog')
 79:             ) {
 80:                 unset($trace[0]);
 81:             }
 82: 
 83:             foreach ($trace as $frame) {
 84:                 if (isset($frame['file']) && is_file($frame['file'])) {
 85:                     $item['pathname'] = $frame['file'];
 86:                     $item['lineno'] = $frame['line'];
 87:                     break;
 88:                 }
 89:             }
 90:         }
 91: 
 92:         $item['exc_info'] = array('', '', array());
 93:         $item['exc_frames'] = array();
 94: 
 95:         foreach ($trace as $frame) {
 96:             $frame += array('file' => NULL, 'line' => NULL, 'class' => NULL, 'type' => NULL, 'function' => NULL, 'object' => NULL, 'args' => NULL);
 97:             $item['exc_info'][2][] = array($frame['file'], $frame['line'], "$frame[class]$frame[type]$frame[function]", $frame['object']);
 98:             $item['exc_frames'][] = $frame['args'];
 99:         }
100: 
101:         if (isset($args[0]) && in_array($args[0], array(self::DEBUG, self::INFO, self::WARNING, self::ERROR, self::CRITICAL), TRUE)) {
102:             $item['level'] = array_shift($args);
103:         }
104: 
105:         $item['args'] = $args;
106: 
107:         self::$payload['logs'][] = self::jsonDump($item, -1);
108:         foreach (str_split(base64_encode(@json_encode(self::$payload)), 4990) as $k => $v) { // intentionally @
109:             header("FireLogger-de11e-$k:$v");
110:         }
111:         return TRUE;
112:     }
113: 
114: 
115: 
116:     /**
117:      * Dump implementation for JSON.
118:      * @param  mixed  variable to dump
119:      * @param  int    current recursion level
120:      * @return string
121:      */
122:     private static function jsonDump(&$var, $level = 0)
123:     {
124:         if (is_bool($var) || is_null($var) || is_int($var) || is_float($var)) {
125:             return $var;
126: 
127:         } elseif (is_string($var)) {
128:             if (Debugger::$maxLen && strlen($var) > Debugger::$maxLen) {
129:                 $var = substr($var, 0, Debugger::$maxLen) . " \xE2\x80\xA6 ";
130:             }
131:             return Strings::fixEncoding($var);
132: 
133:         } elseif (is_array($var)) {
134:             static $marker;
135:             if ($marker === NULL) {
136:                 $marker = uniqid("\x00", TRUE);
137:             }
138:             if (isset($var[$marker])) {
139:                 return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
140: 
141:             } elseif ($level < Debugger::$maxDepth || !Debugger::$maxDepth) {
142:                 $var[$marker] = TRUE;
143:                 $res = array();
144:                 foreach ($var as $k => &$v) {
145:                     if ($k !== $marker) {
146:                         $res[self::jsonDump($k)] = self::jsonDump($v, $level + 1);
147:                     }
148:                 }
149:                 unset($var[$marker]);
150:                 return $res;
151: 
152:             } else {
153:                 return " \xE2\x80\xA6 ";
154:             }
155: 
156:         } elseif (is_object($var)) {
157:             $arr = (array) $var;
158:             static $list = array();
159:             if (in_array($var, $list, TRUE)) {
160:                 return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
161: 
162:             } elseif ($level < Debugger::$maxDepth || !Debugger::$maxDepth) {
163:                 $list[] = $var;
164:                 $res = array("\x00" => '(object) ' . get_class($var));
165:                 foreach ($arr as $k => &$v) {
166:                     if ($k[0] === "\x00") {
167:                         $k = substr($k, strrpos($k, "\x00") + 1);
168:                     }
169:                     $res[self::jsonDump($k)] = self::jsonDump($v, $level + 1);
170:                 }
171:                 array_pop($list);
172:                 return $res;
173: 
174:             } else {
175:                 return " \xE2\x80\xA6 ";
176:             }
177: 
178:         } elseif (is_resource($var)) {
179:             return "resource " . get_resource_type($var);
180: 
181:         } else {
182:             return "unknown type";
183:         }
184:     }
185: 
186: }
187: 
Nette Framework 2.0.7 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.8.0