Skip to content
Permalink
Browse files

Logger: added priority to exception file name

  • Loading branch information...
dg committed Jul 15, 2019
1 parent 47fe5fe commit 6ff7adcac3fca952eda4e7893bd60e3dd355c690
Showing with 8 additions and 8 deletions.
  1. +3 −3 src/Tracy/Logger/Logger.php
  2. +1 −1 tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt
  3. +4 −4 tests/Tracy/Logger.log().phpt
@@ -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
}
@@ -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'));
@@ -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'));
});

0 comments on commit 6ff7adc

Please sign in to comment.
You can’t perform that action at this time.