From 834db9c9d2d758edee3f35c6c7d223207fa24fa7 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 16 Jul 2019 00:44:35 +0200 Subject: [PATCH] Logger: added priority to exception file name --- src/Tracy/Logger/Logger.php | 6 +++--- tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt | 2 +- tests/Tracy/Logger.log().phpt | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Tracy/Logger/Logger.php b/src/Tracy/Logger/Logger.php index 4dea99014..7d06d9d7f 100644 --- a/src/Tracy/Logger/Logger.php +++ b/src/Tracy/Logger/Logger.php @@ -61,7 +61,7 @@ public function log($message, $level = self::INFO) } $exceptionFile = $message instanceof \Throwable - ? $this->getExceptionFile($message) + ? $this->getExceptionFile($message, $level) : null; $line = static::formatLogLine($message, $exceptionFile); $file = $this->directory . '/' . strtolower($level ?: self::INFO) . '.log'; @@ -119,7 +119,7 @@ public static function formatLogLine($message, string $exceptionFile = null): st } - public function getExceptionFile(\Throwable $exception): string + public function getExceptionFile(\Throwable $exception, string $level = self::EXCEPTION): string { while ($exception) { $data[] = [ @@ -135,7 +135,7 @@ public function getExceptionFile(\Throwable $exception): string return $dir . $file; } } - return $dir . 'exception--' . @date('Y-m-d--H-i') . "--$hash.html"; // @ timezone may not be set + return $dir . $level . '--' . @date('Y-m-d--H-i') . "--$hash.html"; // @ timezone may not be set } diff --git a/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt b/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt index a505a6c72..560c4b968 100644 --- a/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt +++ b/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt @@ -19,5 +19,5 @@ Debugger::$logSeverity = E_NOTICE; $variable = $missingVariable; -Assert::count(1, glob(TEMP_DIR . '/exception*.html')); +Assert::count(1, glob(TEMP_DIR . '/error*.html')); Assert::count(1, glob(TEMP_DIR . '/error.log')); diff --git a/tests/Tracy/Logger.log().phpt b/tests/Tracy/Logger.log().phpt index c8eee25ec..7dfa867b1 100644 --- a/tests/Tracy/Logger.log().phpt +++ b/tests/Tracy/Logger.log().phpt @@ -32,23 +32,23 @@ test(function () { test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_ERROR, __FILE__, __LINE__), 'c'); - Assert::match('[%a%] Fatal Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/c.log')); + Assert::match('[%a%] Fatal Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ c-%a%.html', file_get_contents($logger->directory . '/c.log')); }); test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_WARNING, __FILE__, __LINE__), 'd'); - Assert::match('[%a%] Warning: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/d.log')); + Assert::match('[%a%] Warning: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ d-%a%.html', file_get_contents($logger->directory . '/d.log')); }); test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_COMPILE_ERROR, __FILE__, __LINE__), 'e'); - Assert::match('[%a%] Compile Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/e.log')); + Assert::match('[%a%] Compile Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ e-%a%.html', file_get_contents($logger->directory . '/e.log')); }); test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_NOTICE, __FILE__, __LINE__), 'f'); - Assert::match('[%a%] Notice: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/f.log')); + Assert::match('[%a%] Notice: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ f-%a%.html', file_get_contents($logger->directory . '/f.log')); });