mortenscheel/tracer
A PHP library for advanced stack trace handling and debugging.
13,486
| Install | |
|---|---|
composer require mortenscheel/tracer |
|
| Latest Version: | 0.2.0 |
| PHP: | ^8.2.0 |
| Laravel: | 11 · 12 |
| License: | MIT |
| Last Updated: | Mar 15, 2025 |
| Links: | GitHub · Packagist |
Maintainer: mortenscheel
A PHP library for advanced stack trace handling and debugging.
Installation
composer require mortenscheel/tracer
Features
- Get detailed stack traces with clean filtering options
- Easily ignore vendor frames, specific classes, methods, files, or lines
- StackTrace is a Laravel Collection
- Format stack frames for debugging and display
- Generate editor links (see mortenscheel/editor-links)
- Serializable frames for logging or error reporting
Usage
Basic Usage
use Scheel\Tracer\StackTrace;
// Get a full stack trace
$trace = StackTrace::getTrace();
// Access the first frame
$firstFrame = $trace->first();
// Convert to array for inspection
$frames = $trace->toArray();
Filtering Frames
use Scheel\Tracer\StackTrace;
use Scheel\Tracer\Frame;
// Ignore vendor frames
$trace = StackTrace::getTrace()->ignoreVendor();
// Ignore specific classes
$trace = StackTrace::getTrace()->ignoreClass(SomeClass::class);
// Ignore specific class methods
$trace = StackTrace::getTrace()->ignoreClass(SomeClass::class, 'methodName');
// Ignore specific files
$trace = StackTrace::getTrace()->ignoreFile('/path/to/file.php');
// Ignore specific lines in files
$trace = StackTrace::getTrace()->ignoreFile('/path/to/file.php', 123);
// Custom filtering using the filter method
$trace = StackTrace::getTrace()->filter(function (Frame $frame): bool {
return $frame->class !== 'ClassToIgnore';
});
Working with Frames
use Scheel\Tracer\StackTrace;
$frame = StackTrace::getTrace()->first();
// Get frame location as string
echo $frame->location(); // "/path/to/file.php:123"
// Convert frame to array
$frameData = $frame->toArray();
/*
[
'file' => '/path/to/file.php',
'line' => 123,
'function' => 'methodName',
'class' => 'ClassName',
'type' => '::',
]
*/
// Generate editor links
echo $frame->editorLink(); // "phpstorm://open?file=/path/to/file.php&line=123"
Running Tests
composer test
License
MIT
Author
Morten Scheel
Related Packages
marekmiklusek/laravel-package-skeleton
Laravel package skeleton with Pest, PHPStan, Rector and Pint wired up, and 100%...
7
1
mortenscheel/laravel-query-recorder
A package to record and analyze database queries in Laravel applications.
13,283
1
joshcirre/inertiakit
File-based Inertia routing, simplified server controllers + typed models & props
10
5
benjaminhaeberli/php-skeleton
✨ A modern PHP skeleton that includes CI/CD, PHPStan, Pest & more.
7
2
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 0.2.0 | ^8.2.0 | ^11| | MIT | |
| 0.1.0 | ^8.2.0 | ^11| | MIT |