adachsoft / debugger
Check your logs in the console.
Installs: 363
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/adachsoft/debugger
Requires
- php: ^8.3
- adachsoft/console-io: ^0.1.0
Requires (Dev)
- phpunit/phpunit: 12.4
This package is auto-updated.
Last update: 2025-12-25 09:16:40 UTC
README
A small, framework-agnostic PHP debugger/logger that can dump variables, print backtraces and measure execution time.
It can be used directly by instantiating AdachSoft\Debugger\Debugger with your preferred LogInterface and ParserInterface, or via the global facade D / helper function d().
Requirements
- PHP ^8.3
Installation
composer require adachsoft/debugger
Quick start (explicit instance)
use AdachSoft\Debugger\Debugger; use AdachSoft\Debugger\Log\LogPrint; use AdachSoft\Debugger\ParserVarDump; $debugger = new Debugger(new LogPrint(), new ParserVarDump()); $debugger->varDump(['hello' => 'world']); $debugger->backTrace();
Quick start (factory)
The factory provides ready-to-use presets:
use AdachSoft\Debugger\DebuggerFactory; $debugger = DebuggerFactory::create(); $debugger->varDump('hello');
Available presets:
DebuggerFactory::create()DebuggerFactory::createColored()DebuggerFactory::createTypeWithoutValue()
Global facade (D) and helper function (d)
This package ships a global class D (in the global namespace) and a global helper function d().
They are autoloaded through Composer autoload.files, so they work after including vendor/autoload.php.
require_once __DIR__ . '/vendor/autoload.php'; d(['a' => 1, 'b' => [true, null]]); D::useTypeOnly(); d(['a' => 1, 'b' => [true, null]]); D::useStandard(); D::dump('standard mode', ['x' => 123]);
Timing
D::start(); usleep(100_000); $elapsed = D::stop('sleep'); D::dump('elapsed', $elapsed);
Backtrace
D::trace();
Error handler
use AdachSoft\Debugger\Debugger; Debugger::showAllErrors(); $debugger = D::getInstance(); $debugger->setErrorHandler(); // Any PHP warning/notice/error will be formatted and sent to the configured logger.
Logging targets
The debugger delegates output to a LogInterface implementation.
Built-in loggers (see src/Log):
AdachSoft\Debugger\Log\LogPrint(console output)AdachSoft\Debugger\Log\LogToFile(append to a file)AdachSoft\Debugger\Log\LogToServer(send to a TCP server)
Example:
use AdachSoft\Debugger\Debugger; use AdachSoft\Debugger\Log\LogToFile; use AdachSoft\Debugger\ParserVarDump; $debugger = new Debugger( new LogToFile(fileName: __DIR__ . '/debug.log'), new ParserVarDump(), ); $debugger->varDump('saved to file');
License
MIT