-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogManager.php
More file actions
39 lines (31 loc) · 1.09 KB
/
LogManager.php
File metadata and controls
39 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Manager;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
final class LogManager
{
public const SUCCESS = 0;
public const FAILURE = 1;
public function __construct(private readonly LoggerInterface $logger)
{
}
public function logException(\Exception $exception, string $level = LogLevel::CRITICAL): int
{
$exceptionTrace = $exception->getTrace();
try {
$this->logger->log($level, sprintf('%s - %s', static::class, $exceptionTrace[0]['function']), [
'exception' => $exception->getMessage(),
'trace' => $exceptionTrace,
]);
return self::SUCCESS;
} catch (\Exception $e) {
$this->logger->critical(sprintf('Log using App\Manager\LogUtilsTrait::log with level "%s" failed', $level), [
'exception' => $e->getMessage(),
'trace' => $e->getTrace(),
'originalException' => $exception->getMessage(),
'originalTrace' => $exceptionTrace,
]);
return self::FAILURE;
}
}
}