64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
namespace CloudObjects\SDK\TestHelpers;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class InMemoryLogger implements LoggerInterface {
|
|
|
|
private $logs = [];
|
|
|
|
public function getLogs() : array {
|
|
return $this->logs;
|
|
}
|
|
|
|
public function getLastLogMessage() : string {
|
|
if (empty($this->logs)) {
|
|
return '';
|
|
}
|
|
|
|
return end($this->logs)['message'];
|
|
}
|
|
|
|
public function emergency(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'emergency', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function alert(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'alert', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function critical(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'critical', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function error(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'error', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function warning(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'warning', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function notice(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'notice', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function info(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'info', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function debug(string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => 'debug', 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
public function log($level, string|\Stringable $message, array $context = []): void {
|
|
$this->logs[] = [ 'level' => $level, 'message' => (string)$message, 'context' => $context ];
|
|
}
|
|
|
|
}
|