Skip to content

Commit

Permalink
Add Logger::makeId method
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Feb 13, 2022
1 parent 421cb00 commit 8b0e23a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
*/
namespace Framework\Log;

use Exception;
use Framework\Log\Debug\LogCollector;
use InvalidArgumentException;
use JetBrains\PhpStorm\Pure;

/**
Expand Down Expand Up @@ -92,9 +90,6 @@ protected function getConfig() : array
* @param string $message
* @param array<string> $context
*
* @throws Exception if random_bytes cannot gather sufficient entropy
* @throws InvalidArgumentException if log level is invalid
*
* @return bool
*/
public function log(LogLevel $level, string $message, array $context = []) : bool
Expand All @@ -108,7 +103,7 @@ public function log(LogLevel $level, string $message, array $context = []) : boo
return true;
}
$time = \time();
$id = \bin2hex(\random_bytes(6));
$id = $this->makeId();
$message = $this->replaceContext($message, $context);
$log = new Log($level, $message, $time, $id);
$written = $this->write($log);
Expand All @@ -132,6 +127,11 @@ public function log(LogLevel $level, string $message, array $context = []) : boo
return $written;
}

protected function makeId() : string
{
return \bin2hex(\random_bytes(6));
}

/**
* Get the last accepted log in the current instance.
*
Expand Down

0 comments on commit 8b0e23a

Please sign in to comment.