Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Logger: added priority to exception file name
  • Loading branch information
dg committed Aug 19, 2019
1 parent 47fe5fe commit 6ff7adc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Tracy/Logger/Logger.php
Expand Up @@ -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';
Expand Down Expand Up @@ -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[] = [
Expand All @@ -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
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt
Expand Up @@ -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'));
8 changes: 4 additions & 4 deletions tests/Tracy/Logger.log().phpt
Expand Up @@ -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.