adt / error-logger
Requires
- php: >=7.4
- tracy/tracy: >=2.6.0
Requires (Dev)
- phpunit/phpunit: ^9.6 | ^10.5 | ^11.5 | ^12.0
Suggests
- adt/tracy-git: Useful for displaying information about currently deployed application version.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-17 13:34:58 UTC
README
Sends more info about the error than Tracy\Logger. Moreover, it can send multiple errors not only the first.
Installation
composer require adt/error-logger
Place this to your bootstrap.php after calling $configurator->enableDebugger():
$logger = \ADT\ErrorLogger::install( $email = 'errors@example.com', $maxEmailsPerDay = 100, $maxEmailsPerRequest = 10, $includeExceptionFile = true, $errorMessageSanitizeRegex = '~\d|(/[^\s]*)|(\w+://)~', // removes all numbers, absolut paths and protocols $emailSnooze = '1 day' ); if (!\Tracy\Debugger::$productionMode) { // Do not send emails $logger->mailer = null; }
Log rotation
Tracy never rotates its logs. Before each write ErrorLogger renames every *.log of the log directory bigger than
$maxLogSize (10 MB) to <name>.log-<YYYY-MM-DD-HHMMSS>, keeps $maxRotatedLogs (10) of them per log and deletes
exception snapshots (exception--*) older than $maxExceptionFileAge (90 days). Logs written by PHP itself into the
same directory are rotated too. No cron needed, it runs under the user of the application.
$logger->maxLogSize = 50 * 1024 * 1024;
Markdown exception report
Recent Tracy writes next to every exception--*.html a Markdown twin exception--*.md, which ErrorLogger attaches
to the e-mail. Tracy prints the request headers in it raw and dumps call arguments without passing their names, so the
scrubber of the BlueScreen (keyed by name) does not apply there. ErrorLogger therefore writes the .md itself before Tracy does
(and rewrites an older one before attaching it); with a Tracy without it nothing changes:
- request headers, query parameters, call arguments and dumped keys whose name matches
$sensitiveKeys, the BlueScreenscrubberorkeysToHideare replaced by*****, - call arguments without a name (variadic, closures) are always replaced, frames, files and lines stay.
The HTML report is left to the BlueScreen scrubber. The exception message itself is never scrubbed.
$logger->sensitiveKeys = '~pass|secret|token|iban~i';
Tests: composer install && vendor/bin/phpunit (runs a request through the PHP built-in web server).