Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions lib/private/Log/PsrLoggerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Stringable;
use Throwable;
use function array_key_exists;
use function array_merge;
Expand All @@ -27,14 +28,14 @@ public function __construct(

public static function logLevelToInt(string $level): int {
return match ($level) {
LogLevel::ALERT => ILogger::ERROR,
LogLevel::CRITICAL => ILogger::ERROR,
LogLevel::DEBUG => ILogger::DEBUG,
LogLevel::EMERGENCY => ILogger::FATAL,
LogLevel::ERROR => ILogger::ERROR,
LogLevel::INFO => ILogger::INFO,
LogLevel::NOTICE => ILogger::INFO,
LogLevel::ALERT,
LogLevel::ERROR,
LogLevel::CRITICAL => ILogger::ERROR,
LogLevel::WARNING => ILogger::WARN,
LogLevel::INFO,
LogLevel::NOTICE => ILogger::INFO,
LogLevel::DEBUG => ILogger::DEBUG,
default => throw new InvalidArgumentException('Unsupported custom log level'),
};
}
Expand All @@ -50,10 +51,9 @@ private function containsThrowable(array $context): bool {
/**
* System is unusable.
*
* @param $message
* @param mixed[] $context
*/
public function emergency($message, array $context = []): void {
public function emergency(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::EMERGENCY, (string)$message, $context);
}

Expand All @@ -63,10 +63,9 @@ public function emergency($message, array $context = []): void {
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param $message
* @param mixed[] $context
*/
public function alert($message, array $context = []): void {
public function alert(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::ALERT, (string)$message, $context);
}

Expand All @@ -75,21 +74,19 @@ public function alert($message, array $context = []): void {
*
* Example: Application component unavailable, unexpected exception.
*
* @param $message
* @param mixed[] $context
*/
public function critical($message, array $context = []): void {
public function critical(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::CRITICAL, (string)$message, $context);
}

/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param $message
* @param mixed[] $context
*/
public function error($message, array $context = []): void {
public function error(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::ERROR, (string)$message, $context);
}

Expand All @@ -99,20 +96,18 @@ public function error($message, array $context = []): void {
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param $message
* @param mixed[] $context
*/
public function warning($message, array $context = []): void {
public function warning(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::WARNING, (string)$message, $context);
}

/**
* Normal but significant events.
*
* @param $message
* @param mixed[] $context
*/
public function notice($message, array $context = []): void {
public function notice(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::NOTICE, (string)$message, $context);
}

Expand All @@ -121,28 +116,25 @@ public function notice($message, array $context = []): void {
*
* Example: User logs in, SQL logs.
*
* @param $message
* @param mixed[] $context
*/
public function info($message, array $context = []): void {
public function info(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::INFO, (string)$message, $context);
}

/**
* Detailed debug information.
*
* @param $message
* @param mixed[] $context
*/
public function debug($message, array $context = []): void {
public function debug(string|Stringable $message, array $context = []): void {
$this->log(LogLevel::DEBUG, (string)$message, $context);
}

/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param $message
* @param mixed[] $context
*
* @throws InvalidArgumentException
Expand Down
Loading