Format debug trace

@param array $trace
@return array
428477
public static function debugBacktraceString($trace = null) {
		$result = [];
		if (!\Debug::$debug) return $result;
		$i = 1;
		// if trace is not provided
		if (empty($trace)) {
			$trace = debug_backtrace();
			unset($trace[0]);
		}
		foreach($trace as $v) {
			$stack = '#' . $i . ' ' . (isset($v['file']) ? $v['file'] : 'Unknown');
			if (isset($v['line'])) {
				$stack.= '(' . $v['line'] . ')';
			}
			// do not show error handler
			if (!(isset($v['class']) && $v['class'] == 'error' && $v['function'] == 'error_handler')) {
				$stack.= ': ';
				if(isset($v['class'])) {
					$stack.= $v['class'] . $v['type'];
				}
				$params = [];
				if (isset($v['args'])) {
					foreach ($v['args'] as $v2) {
						if (gettype($v2) == 'string') {
							$params[] = str_replace(["\n", "\r", "\t"], ' ', $v2);
						} else if (is_array($v2)) {
							$temp = var_export_condensed($v2, ['skip_objects' => true]);
							$params[] = substr($temp, 0, 100) . '...';
						} else {
							$params[] = var_export_condensed($v2, ['skip_objects' => true]);
						}
					}
				}
				$stack.= $v['function'] . '(' . implode(', ', $params) . ');';
			}
			$i++;
			$result[] = $stack;
		}
		return $result;
	}
1196383
protected function getTrace($e)
    {
        $traces = $e->getTrace();

        // Get trace from xdebug if enabled, failure exceptions only trace to the shutdown handler by default
        if (!$e instanceof \ErrorException) {
            return $traces;
        }

        if (!Misc::isLevelFatal($e->getSeverity())) {
            return $traces;
        }

        if (!extension_loaded('xdebug') || !xdebug_is_enabled()) {
            return [];
        }

        // Use xdebug to get the full stack trace and remove the shutdown handler stack trace
        $stack = array_reverse(xdebug_get_function_stack());
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
        $traces = array_diff_key($stack, $trace);

        return $traces;
    }
898724
private function renderTrace($trace)
    {
        foreach ($trace as $i => $entry) {
            $s = '';
            if (!empty($entry['file'])) {
                $s .= $this->stripFile($entry['file']);
                if (!empty($entry['line'])) {
                    $s .= ' (line ' . $entry['line'] . ')';
                }
            }
            if (!empty($entry['function'])) {
                $class = !empty($entry['class']) ? $entry['class'] . $entry['type'] : '';
                $args  = !empty($entry['args']) ? $this->dumpArgs($entry['args']) : '' ;
                $s .= ':<br/>&nbsp;&nbsp;&nbsp;' . $class . $entry['function'] . '(' . $args . ')';
            }
            $trace[$i] = '<li>' . $s . '</li>';
        }

        return '<code><ul>' . implode('<br/>', $trace) . '</ul></code>';
    }
1340161
static function dump($var, $trace = true)
    {
        $d = Debug::getInstance();

        if ($d->level < 1) {
            return;
        }

        if ($d->terminal) {
            $c = $d->console;

            if (!is_array($var)) {
                $c->writeln(print_r($var, 1), 'blue');
            } else {
                $lines = explode("\n", print_r($var, 1));
                foreach ($lines as $line) {
                    preg_match_all('|(.*)\[(.*)\] \=\>(.*)|', $line, $m);
                    
                    if (!isset($m[0][0])) {
                        $c->writeln($line);
                    } else {
                        $c->write($m[1][0] . '[', 'blue');
                        $c->write($m[2][0], 'light_red');
                        $c->write('] =>', 'blue');
                        $c->writeln($m[3][0], 'blue');
                    }
                }
            }

        } else {
            $txt = preg_replace('/\[(.*)\]/u', '[<span style="color:#d00">$1</span>]', print_r($var, 1));
            echo '<pre style="color:blue">' . $txt . "</pre>";
        }

        if ($trace)
            $d->_trace();
    }
1142896
private function filterTrace($trace)
    {
        $ignore = 'app/Services/Database.php';
        $j = strlen($ignore);
        foreach ($trace as $i => $entry) {
            if (isset($entry['file'])) {
                $s = $this->stripFile($entry['file']);
                if (substr($s, 0, $j) == $ignore) {
                    unset($trace[$i]);
                }
            }
        }

        return $trace;
    }
390603
protected static function _cleanTrace( array &$trace, $skipLines = null, $basePath = null )
    {
        $_trace = array();
        $_basePath = $basePath ?: \Kisma::get( 'app.base_path' );

        //	Skip some lines
        if ( !empty( $skipLines ) && count( $trace ) > $skipLines )
        {
            $trace = array_slice( $trace, $skipLines );
        }

        foreach ( $trace as $_index => $_code )
        {
            $_traceItem = array();

            Scalar::sins( $trace[$_index], 'file', 'Unspecified' );
            Scalar::sins( $trace[$_index], 'line', 0 );
            Scalar::sins( $trace[$_index], 'function', 'Unspecified' );

            $_traceItem['file_name'] = trim(
                str_replace(
                    array(
                        $_basePath,
                        "\t",
                        "\r",
                        "\n",
                        PHP_EOL,
                        'phar://',
                    ),
                    array(
                        null,
                        '    ',
                        null,
                        null,
                        null,
                        null,
                    ),
                    $trace[$_index]['file']
                )
            );

            $_args = null;

            if ( isset( $_code['args'] ) && !empty( $_code['args'] ) )
            {
                foreach ( $_code['args'] as $_arg )
                {
                    if ( is_object( $_arg ) )
                    {
                        $_args .= get_class( $_arg ) . ', ';
                    }
                    else if ( is_array( $_arg ) )
                    {
                        $_args .= '[array], ';
                    }
                    else if ( is_bool( $_arg ) )
                    {
                        if ( $_arg )
                        {
                            $_args .= 'true, ';
                        }
                        else
                        {
                            $_args .= 'false, ';
                        }
                    }
                    else if ( is_numeric( $_arg ) )
                    {
                        $_args .= $_arg . ', ';
                    }
                    else if ( is_scalar( $_arg ) )
                    {
                        $_args .= '"' . $_arg . '", ';
                    }
                    else
                    {
                        $_args .= '"' . gettype( $_arg ) . '", ';
                    }
                }
            }

            $_traceItem['line'] = $trace[$_index]['line'];

            if ( isset( $_code['type'] ) )
            {
                $_traceItem['function'] = ( isset( $_code['class'] ) ? $_code['class'] : null ) . $_code['type'] . $_code['function'];
            }
            else
            {
                $_traceItem['function'] = $_code['function'];
            }

            $_traceItem['function'] .= '(' . ( $_args ? ' ' . trim( $_args, ', ' ) . ' ' : null ) . ')';
            $_traceItem['index'] = $_index;
            $_trace[] = $_traceItem;
        }

        return $_trace;
    }
835169
public function getStackTraceFrames(array $trace): array
    {
        return \Raven_Stacktrace::get_stack_info(
            $trace,
            $this->client->trace,
            [],
            $this->client->message_limit,
            $this->client->getPrefixes(),
            $this->client->getAppPath(),
            $this->client->getExcludedAppPaths(),
            $this->serializer,
            $this->reprSerializer
        );
    }
866362
private function formatLogChannel(array $record)
    {
        if (!isset($record['channel'])) {
            return '';
        }

        if ($this->isDeprecationLog($record)) {
            return '** DEPRECATION **';
        }

        if ($this->isEventNotificationLog($record)) {
            return 'NOTIFIED EVENTS';
        }

        $channel = $record['channel'];
        $channelIcons = array(
            '_event_stop' => '[!] ',
            'security' => '(!) ',
        );
        $channelIcon = array_key_exists($channel, $channelIcons) ? $channelIcons[$channel] : '';

        return sprintf('%s%s', $channelIcon, strtoupper($channel));
    }
511406
public function format(array $record)
    {
        $formattedRecord = $this->formatter->format($record);

        if (is_array($formattedRecord)) {
            list($channel, $message, $backtrace, $loglevel) = $formattedRecord;

            return [
                $channel,
                $this->formatterPrefix . $message,
                $backtrace,
                $loglevel,
            ];
        }

        return $this->formatterPrefix . $formattedRecord;
    }
976750
public function location($trace) {
        $root = substr($_SERVER['DOCUMENT_ROOT'], 0 , strlen(static::$defaults['docroot']) * -1);
        $file = implode('/', array_diff(explode('/', $trace[0]['file']), explode('/', $root)));
        $ret = array(
            'file' => $file,
            'line' => $trace[0]['line']
        );
        if (isset($trace[1]['function'])) $ret['function'] = $trace[1]['function'];
        if (isset($trace[1]['class'])) $ret['class'] = $trace[1]['class'];
        return $ret;
    }
1288783
public function format(array $record)
    {
        $output = $this->addTitle($record['level_name'], $record['level']);
        $output .= '<table cellspacing="1" width="100%" class="monolog-output">';

        if (isset($record['context']['bug'])) {
            $bug = $record['context']['bug'];
            if ($bug instanceof Bug) {
                $output .= $this->addRow('Bug ID', $bug->getId());
                $output .= $this->addRow('Bug Title', $bug->getTitle());
                $output .= $this->addRow('Task Title', $bug->getTask()->getTitle());
                $output .= $this->addRow('Bug Message', $record['message']);
            }
            if (isset($record['context']['path'])) {
                $path = $record['context']['path'];
                if ($path instanceof Path) {
                    $embeddedTable = '<table cellspacing="1" width="100%">';
                    foreach ($path as $index => $step) {
                        $embeddedTable .= $this->addRow('Step', $this->convertToString($index + 1));
                        $embeddedTable .= $this->addRow('Transition', $this->convertToString($step[0]));
                        $embeddedTable .= $this->addRow('Data', $this->convertToString($step[1]));
                        $embeddedTable .= $this->addRow('Places', $this->convertToString(implode('|', $step[2])));

                        $transitionName = $step[0];
                        $subject = $record['context']['subject'];
                        if ($transitionName && $subject instanceof AbstractSubject) {
                            $url = $subject->getScreenshotUrl($bug->getId(), $index);
                            if ($url) {
                                $embeddedTable .= $this->addRow('Screenshot', $this->addImage($url), false);
                            }
                        }
                    }
                    $embeddedTable .= '</table>';
                    $output .= $this->addRow('Steps', $embeddedTable, false);
                }
            }
        }

        return $output.'</table>';
    }
474818
def _format_trace(trace):
    
    lines = []
    for fname, lineno, func, src, _ in trace:
        if src:
            for line in src:
                lines.append('    '+line.strip()+'\n')
        lines.append('  %s:%4d in %s\n' % (fname, lineno, func))
    return ''.join(lines)
492436
protected function format_backtrace($btrace)
    {
        if (empty($btrace) || count($btrace) == 0) {
            return "backtrace empty";
        }
        
        $trace = "";
        
        foreach ($btrace as $nr => &$btrace_entry) {
            if ($nr == 0) {
                $trace .= $btrace_entry["args"][2] . "\r\n" . "line: " . $btrace_entry["args"][3] . "\r\n" . $btrace_entry["args"][1];
                
                $cstack = $this->extract_call_stack($btrace);
                if (!empty($cstack)) {
                    $trace .= "\r\n\r\nCall stack:\r\n\r\n" . $cstack;
                }
                
                continue;
            }
        }
        
        return $trace;
    }
717577
private function formatStacktraceForExceptions($exceptions)
    {
        if (!is_array($exceptions)) {
            $exceptions = [$exceptions];
        }

        $this->root = $this->findApplicationRoot();

        $trace = '';
        foreach ($exceptions as $ex) {
            if ($ex instanceof Throwable) {
                $trace .= $this->formatExceptionStacktrace($ex);
            }
        }

        return $trace;
    }
346297
private static function debug_print($file, $level, $format, $data)
    {
        array_shift($data);
        foreach ($data as $k => $v) {
            if (is_string($v)) {
                $data[$k] = str_replace("\n", ' ', $v);
            } elseif ($v instanceof \Exception) {
                $data[$k] = $v->__toString();
            } elseif (!is_numeric($v)) {
                $data[$k] = str_replace("\n", " ", json_encode($v));
            }
        }

        $mtime = microtime(true);
        $time = 1000 * ($mtime - intval($mtime));

        $trace = debug_backtrace();
        $location = $trace[2]['function'];
        for ($n = 2; $n < sizeof($trace); $n++) {
            if (isset($trace[$n]['class'])) {
                $location = $trace[$n]['class'];
                break;
            }
        }

        $id = isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : getmypid();

        $msg = sizeof($data) ? vsprintf($format, $data) : $format;
        error_log(sprintf("[%s.%03d %s %s %s] %s\n", date('d.m.Y H:m:s'), $time, $id, $level, $location, $msg), 3, $file);
    }
938445
public function debug() {
		return array(
			'id'         => $this->id(),
			'name'       => strtolower(substr(get_class($this), strlen('elfinderdriver'))),
			'mimeDetect' => $this->mimeDetect,
			'imgLib'     => $this->imgLib
		);
	}
521315
public function getTraceCall($trace)
    {
        $call = '';
        if(isset($trace['class'], $trace['type']))
        {
            // 匿名类必须用NULL分割一下
            list($class) = explode("\0", $trace['class']);
            $call .= $class . $trace['type'];
        }
        if(isset($trace['function']))
        {
            $call .= $trace['function'] . '(' . $this->getTraceArgs($trace) . ')';
        }
        return $call;
    }