Newer
Older
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace App\Service\Exception\Formatter;
use App\Service\Exception\Formatter;
use Throwable;
class Log extends Formatter
{
public function formatMessage(): string
{
return $this->generateMessage($this->inspector->getException());
}
public function formatTrace(): string
{
static $template = ' #%d %s->%s(%s) in %s on line %d';
$frames = $this->inspector->getFrames();
$response = '';
$line = 1;
foreach ($frames as $frame) {
$response .= str_replace('{none}->', '', sprintf(
$template,
$line,
$frame->getClass() ?: '{none}',
$frame->getFunction(),
$this->generateArgs($frame->getArgs()),
$this->replacePath($frame->getFile()),
$frame->getLine()
));
$line++;
}
return substr($response, 1); // remove the first space
}
protected function generateMessage(Throwable $exception)
{
$message = sprintf(
'%s%s: %s in %s on line %d',
get_class($exception),
$exception->getCode() ? '(' . $exception->getCode() . ')' : '',
$exception->getMessage(),
$this->replacePath($exception->getFile()),
$exception->getLine()
);
if ($exception->getPrevious()) {
$message .= ' [Caused by ' . $this->generateMessage($exception->getPrevious()) . ']';
}
return $message;
}
}