bearsunday /
BEAR.Resource
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace BEAR\Resource; |
||
| 6 | |||
| 7 | use Override; |
||
| 8 | use Psr\Log\LoggerInterface as PsrLoggerInterface; |
||
| 9 | use Psr\Log\LogLevel; |
||
| 10 | |||
| 11 | use function in_array; |
||
| 12 | use function sprintf; |
||
| 13 | |||
| 14 | final readonly class DevLogger implements LoggerInterface |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 15 | { |
||
| 16 | public function __construct( |
||
| 17 | private PsrLoggerInterface $logger, |
||
| 18 | ) { |
||
| 19 | } |
||
| 20 | |||
| 21 | #[Override] |
||
| 22 | public function __invoke(ResourceObject $ro): void |
||
| 23 | { |
||
| 24 | $unsafeMethod = ['post', 'put', 'patch', 'delete']; |
||
| 25 | $level = in_array($ro->uri->method, $unsafeMethod, true) ? LogLevel::INFO : LogLevel::DEBUG; |
||
| 26 | $this->logger->log($level, sprintf('request: %s %s', $ro->uri->method, (string) $ro->uri)); |
||
| 27 | $this->logger->log($level, sprintf('response: %s %s', $ro->code, (string) $ro)); |
||
| 28 | } |
||
| 29 | } |
||
| 30 |