|
|
|
|
@ -15,6 +15,7 @@ use OCP\Log\IDataLogger;
|
|
|
|
|
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;
|
|
|
|
|
@ -27,14 +28,14 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
|
|
|
|
|
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'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
@ -50,10 +51,9 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -63,10 +63,9 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -75,10 +74,9 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
*
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -86,10 +84,9 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -99,20 +96,18 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -121,20 +116,18 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
*
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -142,7 +135,6 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
|
|
|
|
|
* Logs with an arbitrary level.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $level
|
|
|
|
|
* @param $message
|
|
|
|
|
* @param mixed[] $context
|
|
|
|
|
*
|
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
|
|