friendship ended with social-app. php is my new best friend
at main 935 B view raw
1<?php declare(strict_types = 1); 2 3namespace Contributte\Logging\Slack\Formatter; 4 5use Throwable; 6 7final class ExceptionStackTraceFormatter implements IFormatter 8{ 9 10 public function format(SlackContext $context, Throwable $exception, string $priority): SlackContext 11 { 12 // Skip empty trace 13 if (count($exception->getTrace()) < 1) { 14 return $context; 15 } 16 17 $context = clone $context; 18 $attachment = $context->createAttachment(); 19 $attachment->setText(sprintf('*Stack trace* (_%s_)', get_class($exception))); 20 $attachment->setMarkdown(); 21 22 foreach ($exception->getTrace() as $id => $trace) { 23 $func = $attachment->createField(); 24 $func->setTitle(sprintf(':fireworks: Trace #%s', $id + 1)); 25 $file = $attachment->createField(); 26 $file->setTitle(':open_file_folder: File'); 27 $file->setValue('```Function: ' . $trace['function'] . "\nFile: " . $trace['file'] . ':' . $trace['line'] . '```'); 28 } 29 30 return $context; 31 } 32 33}