Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| LogSaver | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
| info | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| error | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| warning | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| debug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| log | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Services\Log; |
| 4 | |
| 5 | use App\LogLevelEnum; |
| 6 | use App\Models\Log; |
| 7 | use App\Models\PlatformChannel; |
| 8 | |
| 9 | class LogSaver |
| 10 | { |
| 11 | /** |
| 12 | * @param array<string, mixed> $context |
| 13 | */ |
| 14 | public static function info(string $message, ?PlatformChannel $channel = null, array $context = []): void |
| 15 | { |
| 16 | self::log(LogLevelEnum::INFO, $message, $channel, $context); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @param array<string, mixed> $context |
| 21 | */ |
| 22 | public static function error(string $message, ?PlatformChannel $channel = null, array $context = []): void |
| 23 | { |
| 24 | self::log(LogLevelEnum::ERROR, $message, $channel, $context); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @param array<string, mixed> $context |
| 29 | */ |
| 30 | public static function warning(string $message, ?PlatformChannel $channel = null, array $context = []): void |
| 31 | { |
| 32 | self::log(LogLevelEnum::WARNING, $message, $channel, $context); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @param array<string, mixed> $context |
| 37 | */ |
| 38 | public static function debug(string $message, ?PlatformChannel $channel = null, array $context = []): void |
| 39 | { |
| 40 | self::log(LogLevelEnum::DEBUG, $message, $channel, $context); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @param array<string, mixed> $context |
| 45 | */ |
| 46 | private static function log(LogLevelEnum $level, string $message, ?PlatformChannel $channel = null, array $context = []): void |
| 47 | { |
| 48 | $logContext = $context; |
| 49 | |
| 50 | if ($channel) { |
| 51 | $logContext = array_merge($logContext, [ |
| 52 | 'channel_id' => $channel->id, |
| 53 | 'channel_name' => $channel->name, |
| 54 | 'platform' => $channel->platformInstance->platform->value, |
| 55 | 'instance_url' => $channel->platformInstance->url, |
| 56 | ]); |
| 57 | } |
| 58 | |
| 59 | Log::create([ |
| 60 | 'level' => $level, |
| 61 | 'message' => $message, |
| 62 | 'context' => $logContext, |
| 63 | ]); |
| 64 | } |
| 65 | } |