PHPackages                             patchwork/error-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. patchwork/error-logger

Abandoned → [symfony/error-handler](/?search=symfony%2Ferror-handler)Library[Logging &amp; Monitoring](/categories/logging)

patchwork/error-logger
======================

Advanced PHP error handling and high accuracy JSON logging

4453PHP

Since Feb 4Pushed 11y ago2 watchersCompare

[ Source](https://github.com/nicolas-grekas/Patchwork-Error-Logger)[ Packagist](https://packagist.org/packages/patchwork/error-logger)[ RSS](/packages/patchwork-error-logger/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Patchwork Error Logger: Advanced PHP error handling and high accuracy JSON logging
==================================================================================

[](#patchwork-error-logger-advanced-php-error-handling-and-high-accuracy-json-logging)

Here are five PHP classes under Apache 2 and GPLv2 licenses, focused on particular aspects of errors handling in PHP. Together, they offer unprecedented accuracy for logging what's going on with the internal state of your applications.

For interoperability and readability, errors and variables' states are logged to JSON.

Error handling
--------------

[](#error-handling)

### Patchwork\\PHP\\ErrorHandler

[](#patchworkphperrorhandler)

is a flexible error and exception handler.

Its default behavior is to log errors to the same file where fatal errors are written. That way, the same debug stream contains both uncatchable fatal errors and catchable ones in an easy to parse format.

Each error type is handled according to four bit fields:

- *scream*: controls which errors are never @-silenced - silenced fatal errors that can be detected at shutdown time are logged when the bit field allows so,
- *thrownErrors*: controls which errors are turned to exceptions (defaults to *E\_RECOVERABLE\_ERROR | E\_USER\_ERROR*),
- *scopedErrors*: controls which errors are logged along with their local context,
- *tracedErrors*: controls which errors are logged along with their trace (but only once for repeated errors).

Since errors, even silenced ones, always have a performance cost, repeated errors are all logged, so that the developper can see them and weight them as more important to fix than others of the same type.

High accuracy logging
---------------------

[](#high-accuracy-logging)

Did you try to dump a variable inside an output buffering handler? Any error handling or variable logging code out there using either *ob\_start()*, *print\_r()* or *var\_dump()* fails in this situation. Neither *serialize()* is usable, because some objects throw an exception when serialized. If your current dumper uses *json\_encode()* internally (or *var\_export()* since PHP 5.3.3) then you may be safe. But even then, you won't be able to log intra-references in your arrays/objects, nor details for resources and so on.

Because errors always happen in unexpected situations, a robust logger must work whatever the running context is, for any variable type.

In order to allow a higher level of accuracy, variables are logged following the [JSON convention to dump any PHP variable with high accuracy](https://github.com/nicolas-grekas/Patchwork-Doc/blob/master/Dumping-PHP-Data-en.md).

To achieve this, several classes are involved:

### Patchwork\\PHP\\Logger

[](#patchworkphplogger)

logs any message to an output stream.

Error messages are handled specifically in order to make them more friendly, especially for traces and exceptions.

Logged messages just have to have a type and some associated data. They are sent to a *JsonDumper* object who writes to your debug stream (but that can be any other destination).

### Patchwork\\PHP\\JsonDumper

[](#patchworkphpjsondumper)

implements the [JSON convention to dump any PHP variable with high accuracy](https://github.com/nicolas-grekas/Patchwork-Doc/blob/master/Dumping-PHP-Data-en.md).

It extends the *Dumper* class.

### Patchwork\\PHP\\Dumper

[](#patchworkphpdumper)

Handles a callback mechanism for getting detailed information about dumped objects and resources, alongside with managing depth and length limits.

It extends the *Walker* class.

### Patchwork\\PHP\\Walker

[](#patchworkphpwalker)

implements a mechanism to generically traverse any PHP variable.

It takes internal references into account, recursive or non-recursive, without preempting any special use of the discovered data. It exposes only one public method *-&gt;walk()*, which triggers the traversal. It also has a public property *-&gt;checkInternalRefs* set to true by default, to disable the check for internal references if the mechanism is considered too expensive. Checking recursive references and object/resource can not be disabled but is much lighter.

Usage
-----

[](#usage)

Including the `bootup.logger.php` file is the easiest way to start with these features. By defaults, errors are written to *php://stderr*, but the file is here to be tuned by you.

This code is extracted from the [Patchwork](http://pa.tchwork.com/) framework where it serves as the foundation for the debugging system. It is released here standalone in the hope that it can be used in a different context successfully!

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/243674?v=4)[Nicolas Grekas](/maintainers/nicolas-grekas)[@nicolas-grekas](https://github.com/nicolas-grekas)

---

Top Contributors

[![nicolas-grekas](https://avatars.githubusercontent.com/u/243674?v=4)](https://github.com/nicolas-grekas "nicolas-grekas (147 commits)")

### Embed Badge

![Health badge](/badges/patchwork-error-logger/health.svg)

```
[![Health](https://phpackages.com/badges/patchwork-error-logger/health.svg)](https://phpackages.com/packages/patchwork-error-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B11.2k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1941.5M269](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2328.5M330](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
