diff --git a/examples/firelogger.php b/examples/firelogger.php deleted file mode 100644 index a6d885f98..000000000 --- a/examples/firelogger.php +++ /dev/null @@ -1,45 +0,0 @@ - 'val1', 'key2' => true]]; - -// will show in FireLogger -Debugger::fireLog('Hello World'); -Debugger::fireLog($arr); - - -function first($arg1, $arg2) -{ - second(true, false); -} - - -function second($arg1, $arg2) -{ - third([1, 2, 3]); -} - - -function third($arg1) -{ - throw new Exception('The my exception', 123); -} - - -try { - first(10, 'any string'); -} catch (Throwable $e) { - Debugger::fireLog($e); -} - -?> - - -

Tracy: FireLogger demo

- -

How to enable FireLogger?

diff --git a/readme.md b/readme.md index 6e4d6a2eb..fadd34fb5 100644 --- a/readme.md +++ b/readme.md @@ -343,35 +343,6 @@ echo Debugger::timer(); // elapsed time in seconds ``` -FireLogger ----------- - -You cannot always send debugging information to the browser window. This applies to AJAX requests or generating XML files to output. In such cases, you can send the messages by a separate channel into FireLogger. Error, Notice and Warning levels are sent to FireLogger window automatically. It is also possible to log suppressed exceptions in running application when attention to them is important. - -How to do it? - -- install extension [FireLogger for Chrome](https://chrome.google.com/webstore/detail/firelogger-for-chrome/hmagilfopmdjkeomnjpchokglfdfjfeh) -- turn on Chrome DevTools (using Ctrl-Shift-I key) and open Console - -Navigate to the [demo page](https://examples.nette.org/tracy/) and you will see messages sent from PHP. - -Because Tracy\Debugger communicates with FireLogger via HTTP headers, you must call the logging function before the PHP script sends anything to output. It is also possible to enable output buffering and delay the output. - -```php -use Tracy\Debugger; - -Debugger::fireLog('Hello World'); // send string into FireLogger console - -Debugger::fireLog($_SERVER); // or even arrays and objects - -Debugger::fireLog(new Exception('Test Exception')); // or exceptions -``` - -The result looks like this: - -![FireLogger](https://nette.github.io/tracy/images/tracy-firelogger.png) - - Custom Logger ------------- diff --git a/src/Tracy/Debugger/Debugger.php b/src/Tracy/Debugger/Debugger.php index 53eb0b60c..cb0730445 100644 --- a/src/Tracy/Debugger/Debugger.php +++ b/src/Tracy/Debugger/Debugger.php @@ -33,9 +33,6 @@ class Debugger /** @var bool whether to display debug bar in development mode */ public static $showBar = true; - /** @var bool whether to send data to FireLogger in development mode */ - public static $showFireLogger = true; - /** @var int size of reserved memory */ public static $reservedMemorySize = 500000; @@ -96,7 +93,7 @@ class Debugger /** @var string|array email(s) to which send error notifications */ public static $email; - /** for Debugger::log() and Debugger::fireLog() */ + /** for Debugger::log() */ public const DEBUG = ILogger::DEBUG, INFO = ILogger::INFO, @@ -145,9 +142,6 @@ class Debugger /** @var ILogger */ private static $logger; - /** @var ILogger */ - private static $fireLogger; - /** @var array{DevelopmentStrategy, ProductionStrategy} */ private static $strategy; @@ -236,7 +230,6 @@ public static function enable($mode = null, ?string $logDirectory = null, $email 'Dumper/Exposer', 'Dumper/Renderer', 'Dumper/Value', - 'Logger/FireLogger', 'Logger/Logger', 'Session/SessionStorage', 'Session/FileSession', @@ -435,16 +428,6 @@ public static function getLogger(): ILogger } - public static function getFireLogger(): ILogger - { - if (!self::$fireLogger) { - self::$fireLogger = new FireLogger; - } - - return self::$fireLogger; - } - - /** @return ProductionStrategy|DevelopmentStrategy @internal */ public static function getStrategy() { @@ -575,18 +558,6 @@ public static function log($message, string $level = ILogger::INFO) } - /** - * Sends message to FireLogger console. - * @param mixed $message - */ - public static function fireLog($message): bool - { - return !self::$productionMode && self::$showFireLogger - ? self::getFireLogger()->log($message) - : false; - } - - /** @internal */ public static function addSourceMapper(callable $mapper): void { diff --git a/src/Tracy/Debugger/DevelopmentStrategy.php b/src/Tracy/Debugger/DevelopmentStrategy.php index be87a6add..9c0837c4a 100644 --- a/src/Tracy/Debugger/DevelopmentStrategy.php +++ b/src/Tracy/Debugger/DevelopmentStrategy.php @@ -49,7 +49,6 @@ public function handleException(\Throwable $exception, bool $firstTime): void $this->blueScreen->render($exception); } else { - Debugger::fireLog($exception); $this->renderExceptionCli($exception); } } @@ -102,11 +101,8 @@ public function handleError( $message = 'PHP ' . Helpers::errorTypeToString($severity) . ': ' . Helpers::improveError($message); $count = &$this->bar->getPanel('Tracy:errors')->data["$file|$line|$message"]; - if (!$count++) { // not repeated error - Debugger::fireLog(new ErrorException($message, 0, $severity, $file, $line)); - if (!Helpers::isHtmlMode() && !Helpers::isAjax()) { - echo "\n$message in $file on line $line\n"; - } + if (!$count++ && !Helpers::isHtmlMode() && !Helpers::isAjax()) { + echo "\n$message in $file on line $line\n"; } if (function_exists('ini_set')) { diff --git a/src/Tracy/Logger/FireLogger.php b/src/Tracy/Logger/FireLogger.php deleted file mode 100644 index fd606d10a..000000000 --- a/src/Tracy/Logger/FireLogger.php +++ /dev/null @@ -1,187 +0,0 @@ - []]; - - - /** - * Sends message to FireLogger console. - * @param mixed $message - */ - public function log($message, $level = self::DEBUG): bool - { - if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) { - return false; - } - - $item = [ - 'name' => 'PHP', - 'level' => $level, - 'order' => count($this->payload['logs']), - 'time' => str_pad(number_format((microtime(true) - Debugger::$time) * 1000, 1, '.', ' '), 8, '0', STR_PAD_LEFT) . ' ms', - 'template' => '', - 'message' => '', - 'style' => 'background:#767ab6', - ]; - - $args = func_get_args(); - if (isset($args[0]) && is_string($args[0])) { - $item['template'] = array_shift($args); - } - - if (isset($args[0]) && $args[0] instanceof \Throwable) { - $e = array_shift($args); - $trace = $e->getTrace(); - if ( - isset($trace[0]['class']) - && $trace[0]['class'] === Debugger::class - && ($trace[0]['function'] === 'shutdownHandler' || $trace[0]['function'] === 'errorHandler') - ) { - unset($trace[0]); - } - - $file = str_replace(dirname($e->getFile(), 3), "\xE2\x80\xA6", $e->getFile()); - $item['template'] = ($e instanceof \ErrorException ? '' : Helpers::getClass($e) . ': ') - . $e->getMessage() . ($e->getCode() ? ' #' . $e->getCode() : '') . ' in ' . $file . ':' . $e->getLine(); - $item['pathname'] = $e->getFile(); - $item['lineno'] = $e->getLine(); - - } else { - $trace = debug_backtrace(); - if ( - isset($trace[1]['class']) - && $trace[1]['class'] === Debugger::class - && ($trace[1]['function'] === 'fireLog') - ) { - unset($trace[0]); - } - - foreach ($trace as $frame) { - if (isset($frame['file']) && is_file($frame['file'])) { - $item['pathname'] = $frame['file']; - $item['lineno'] = $frame['line']; - break; - } - } - } - - $item['exc_info'] = ['', '', []]; - $item['exc_frames'] = []; - - foreach ($trace as $frame) { - $frame += ['file' => null, 'line' => null, 'class' => null, 'type' => null, 'function' => null, 'object' => null, 'args' => null]; - $item['exc_info'][2][] = [$frame['file'], $frame['line'], "$frame[class]$frame[type]$frame[function]", $frame['object']]; - $item['exc_frames'][] = $frame['args']; - } - - if ( - isset($args[0]) - && in_array($args[0], [self::DEBUG, self::INFO, self::WARNING, self::ERROR, self::CRITICAL], true) - ) { - $item['level'] = array_shift($args); - } - - $item['args'] = $args; - - $this->payload['logs'][] = $this->jsonDump($item, -1); - foreach (str_split(base64_encode(json_encode($this->payload, JSON_INVALID_UTF8_SUBSTITUTE)), 4990) as $k => $v) { - header("FireLogger-de11e-$k: $v"); - } - - return true; - } - - - /** - * Dump implementation for JSON. - * @param mixed $var - * @return array|int|float|bool|string|null - */ - private function jsonDump(&$var, int $level = 0) - { - if (is_bool($var) || $var === null || is_int($var) || is_float($var)) { - return $var; - - } elseif (is_string($var)) { - $var = Helpers::encodeString($var, $this->maxLength); - return htmlspecialchars_decode(strip_tags($var)); - - } elseif (is_array($var)) { - static $marker; - if ($marker === null) { - $marker = uniqid("\x00", true); - } - - if (isset($var[$marker])) { - return "\xE2\x80\xA6RECURSION\xE2\x80\xA6"; - - } elseif ($level < $this->maxDepth || !$this->maxDepth) { - $var[$marker] = true; - $res = []; - foreach ($var as $k => &$v) { - if ($k !== $marker) { - $res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1); - } - } - - unset($var[$marker]); - return $res; - - } else { - return " \xE2\x80\xA6 "; - } - } elseif (is_object($var)) { - $arr = get_mangled_object_vars($var); - static $list = []; - if (in_array($var, $list, true)) { - return "\xE2\x80\xA6RECURSION\xE2\x80\xA6"; - - } elseif ($level < $this->maxDepth || !$this->maxDepth) { - $list[] = $var; - $res = ["\x00" => '(object) ' . Helpers::getClass($var)]; - foreach ($arr as $k => &$v) { - if (isset($k[0]) && $k[0] === "\x00") { - $k = substr($k, strrpos($k, "\x00") + 1); - } - - $res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1); - } - - array_pop($list); - return $res; - - } else { - return " \xE2\x80\xA6 "; - } - } elseif (is_resource($var)) { - return 'resource ' . get_resource_type($var); - - } else { - return 'unknown type'; - } - } -} diff --git a/src/tracy.php b/src/tracy.php index 73259adff..46b60189c 100644 --- a/src/tracy.php +++ b/src/tracy.php @@ -18,7 +18,6 @@ require __DIR__ . '/Tracy/Dumper/Exposer.php'; require __DIR__ . '/Tracy/Dumper/Renderer.php'; require __DIR__ . '/Tracy/Logger/ILogger.php'; -require __DIR__ . '/Tracy/Logger/FireLogger.php'; require __DIR__ . '/Tracy/Logger/Logger.php'; require __DIR__ . '/Tracy/Debugger/Debugger.php'; require __DIR__ . '/Tracy/Debugger/DeferredContent.php'; diff --git a/tests/Tracy/Debugger.fireLog().basic.phpt b/tests/Tracy/Debugger.fireLog().basic.phpt deleted file mode 100644 index b802b6c65..000000000 --- a/tests/Tracy/Debugger.fireLog().basic.phpt +++ /dev/null @@ -1,35 +0,0 @@ - 'val1', 'key2' => true], (object) ['key1' => 'val1', 'key2' => true]]; - -// will show in FireLogger -Debugger::fireLog('Hello World'); // Tracy\Debugger::DEBUG -Debugger::fireLog('Info message', Debugger::INFO); -Debugger::fireLog('Warn message', Debugger::WARNING); -Debugger::fireLog('Error message', Debugger::ERROR); -Debugger::fireLog($arr); - -preg_match('#^FireLogger-de11e-0:(.+)#m', implode("\n", headers_list()), $matches); -Assert::true(isset($matches[1])); diff --git a/tests/Tracy/Debugger.fireLog().exception.phpt b/tests/Tracy/Debugger.fireLog().exception.phpt deleted file mode 100644 index e9c1773e1..000000000 --- a/tests/Tracy/Debugger.fireLog().exception.phpt +++ /dev/null @@ -1,52 +0,0 @@ -