Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
exceptionhandlerformatter.php
1<?php
2
3namespace Bitrix\Main\Diag;
4
6
8{
9 const MAX_CHARS = 30;
10
11 const SHOW_PARAMETERS = 1;
12 const DELIMITER = '----------';
13
20 public static function format($exception, $htmlMode = false, $level = 0)
21 {
22 $formatter = new LogFormatter((bool)($level & static::SHOW_PARAMETERS), static::MAX_CHARS);
23
24 $result = $formatter->format("{exception}{trace}{delimiter}\n", [
25 'exception' => $exception,
26 'trace' => static::getTrace($exception),
27 ]);
28
29 if ($htmlMode)
30 {
31 $result = '<pre>'.Main\Text\HtmlFilter::encode($result).'</pre>';
32 }
33
34 return $result;
35 }
36
41 protected static function getTrace($exception)
42 {
43 $backtrace = $exception->getTrace();
44
45 $skip = "Bitrix\\Main\\Diag\\ExceptionHandler";
46
47 $result = [];
48 foreach ($backtrace as $item)
49 {
50 if (!isset($item['class']) || ($item['class'] != $skip))
51 {
52 $result[] = $item;
53 }
54 }
55
56 return $result;
57 }
58
62 protected static function getMessage($exception)
63 {
64 return $exception->getMessage().' ('.$exception->getCode().')';
65 }
66
70 public static function severityToString($severity)
71 {
72 return LogFormatter::severityToString($severity);
73 }
74
78 protected static function getArguments($args, $level)
79 {
80 $formatter = new LogFormatter((bool)($level & static::SHOW_PARAMETERS), static::MAX_CHARS);
81
82 return $formatter->formatArguments($args);
83 }
84
88 protected static function convertArgumentToString($arg, $level)
89 {
90 $formatter = new LogFormatter((bool)($level & static::SHOW_PARAMETERS), static::MAX_CHARS);
91
92 return $formatter->formatArgument($arg);
93 }
94
98 protected static function getFileLink($file, $line)
99 {
100 if (!empty($file))
101 {
102 return $file . ':' . $line;
103 }
104 return '';
105 }
106}
static format($exception, $htmlMode=false, $level=0)
static severityToString($severity)