Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Bar
  • BlueScreen
  • Debugger
  • Dumper
  • FireLogger
  • Helpers
  • Logger
  • OutputDebugger

Interfaces

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