25 use Monolog\Formatter\LineFormatter as MonologLineFormatter;
54 $format =
null, $dateFormat =
null, $allowInlineLineBreaks =
false,
55 $ignoreEmptyContextAndExtra =
false, $includeStacktraces =
false
58 $format, $dateFormat, $allowInlineLineBreaks,
59 $ignoreEmptyContextAndExtra
61 $this->includeStacktraces( $includeStacktraces );
67 public function format( array $record ) {
69 unset( $record[
'context'][
'private'] );
73 $prettyException =
'';
74 if ( isset( $record[
'context'][
'exception'] ) &&
75 strpos( $this->
format,
'%exception%' ) !==
false
77 $e = $record[
'context'][
'exception'];
78 unset( $record[
'context'][
'exception'] );
80 if ( $e instanceof Throwable || $e instanceof Exception ) {
82 } elseif ( is_array( $e ) ) {
85 $prettyException = $this->stringify( $e );
89 $output = parent::format( $record );
91 if ( strpos(
$output,
'%exception%' ) !==
false ) {
115 'class' => get_class( $e ),
116 'message' => $e->getMessage(),
117 'code' => $e->getCode(),
118 'file' => $e->getFile(),
119 'line' => $e->getLine(),
123 $prev = $e->getPrevious();
139 'class' =>
'Unknown',
142 'message' =>
'unknown',
145 $e = array_merge( $defaults, $e );
147 $which = is_a( $e[
'class'], Error::class,
true ) ?
'Error' :
'Exception';
148 $str =
"\n[$which {$e['class']}] (" .
149 "{$e['file']}:{$e['line']}) {$e['message']}";
151 if ( $this->includeStacktraces && $e[
'trace'] ) {
156 if ( isset( $e[
'previous'] ) ) {
157 $prev = $e[
'previous'];
159 $prev = array_merge( $defaults, $prev );
160 $which = is_a( $prev[
'class'], Error::class,
true ) ?
'Error' :
'Exception';
161 $str .=
"\nCaused by: [$which {$prev['class']}] (" .
162 "{$prev['file']}:{$prev['line']}) {$prev['message']}";
164 if ( $this->includeStacktraces && $prev[
'trace'] ) {
171 $prev = $prev[
'previous'] ??
null;