You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

  1. <?php
  2. namespace App\Utilities\Logger;
  3. use Throwable;
  4. use Carbon\Carbon;
  5. use Ramsey\Uuid\Uuid;
  6. use Illuminate\Support\Arr;
  7. use Illuminate\Support\Facades\Auth;
  8. use Illuminate\Support\Facades\DB;
  9. class LogServiceRecordProcessor
  10. {
  11. public function __invoke($record)
  12. {
  13. try {
  14. $exception = json_decode($record['message'], true);
  15. return array_merge($record, [
  16. 'correlation_id' => Uuid::uuid4()->toString(),
  17. 'breadcrumbs' => DB::getQueryLog(),
  18. 'request' => app('request'),
  19. 'message' => Arr::get($exception, 'getMessage', $record['message']),
  20. 'from' => env('CONTAINER_NAME'),
  21. 'trace' => Arr::get($exception, 'getTraceAsString'),
  22. 'name' => Arr::get($exception, 'getName'),
  23. 'code' => Arr::get($exception, 'getCode'),
  24. 'file' => Arr::get($exception, 'getFile'),
  25. 'line' => Arr::get($exception, 'getLine'),
  26. 'user_id' => Auth::hasResolvedGuards() ? Auth::id() : null,
  27. 'created_at' => Carbon::now(),
  28. ]);
  29. } catch (Throwable $exception) {
  30. return $record;
  31. }
  32. }
  33. }