PHPackages                             middlewares/reporting-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. [HTTP &amp; Networking](/categories/http)
4. /
5. middlewares/reporting-logger

ActiveLibrary[HTTP &amp; Networking](/categories/http)

middlewares/reporting-logger
============================

A middleware to log client-side reportings

v2.1.0(1y ago)66141MITPHPPHP ^7.2 || ^8.0CI passing

Since Jun 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/middlewares/reporting-logger)[ Packagist](https://packagist.org/packages/middlewares/reporting-logger)[ Docs](https://github.com/middlewares/reporting-logger)[ RSS](/packages/middlewares-reporting-logger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (10)Versions (7)Used By (0)

middlewares/reporting-logger
============================

[](#middlewaresreporting-logger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/013e341dc131e81dace93d41a843d08485a403221f5243a494af24efa15c613d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6964646c6577617265732f7265706f7274696e672d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/reporting-logger)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Testing](https://github.com/middlewares/reporting-logger/workflows/testing/badge.svg)](https://github.com/middlewares/reporting-logger/workflows/testing/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/a85edb38b89c9536c51f2872269be19a596b5089b00a0980a069a3d20fa81526/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6964646c6577617265732f7265706f7274696e672d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/reporting-logger)

Middleware to log server-side reportings, like CSP messages or any javascript error. More info about [how collect javascript errors](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror). You may need also the [middlewares/payload](https://github.com/middlewares/payload) (or any other middleware with the same purpose) to parse the json of the body.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)
- A [PSR-3 logger library](https://www.php-fig.org/psr/psr-3/)

Installation
------------

[](#installation)

This package is installable and autoloadable via Composer as [middlewares/reporting-logger](https://packagist.org/packages/middlewares/reporting-logger).

```
composer require middlewares/reporting-logger
```

Example
-------

[](#example)

Register a error handler in your javascript code:

```
window.onerror = function (message, file, lineNo, colNo) {
    const error = { message, file, lineNo, colNo };
    const blob = new Blob([ JSON.stringify(error) ], { type: 'application/json' });

    navigator.sendBeacon('/report', blob);
}
```

```
Dispatcher::run([
    new Middlewares\JsonPayload(),
    new Middlewares\ReportingLogger($logger)
]);
```

Usage
-----

[](#usage)

You need a `Psr\Log\LoggerInterface` instance to handle the logs, for example, [monolog](https://github.com/Seldaek/monolog)

```
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('access');
$logger->pushHandler(new StreamHandler('data/logs.txt'));

Dispatcher::run([
    new Middlewares\ReportingLogger($logger)
]);
```

Optionally, you can provide a `Psr\Http\Message\ResponseFactoryInterface` as the second argument, that will be used to create the responses returned after handle the reporting. If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.

```
$responseFactory = new MyOwnResponseFactory();

$reporting = new Middlewares\ReportingLogger($logger, $responseFactory);
```

### path

[](#path)

The uri path where the logs will be reported. By default is `/report`.

```
// In front-end: send the error to "/log-reporting" path
navigator.sendBeacon('/log-reporting', error);
```

```
// In back-end: configure to collect all reportings send to the same path
$reporting = (new Middlewares\ReportingLogger($logger))->path('/log-reporting')
```

### message

[](#message)

The message used to save the logs. You can use the strings `%{varname}` to generate dinamic messages using the reporting data. For example:

```
$reporting = (new Middlewares\ReportingLogger($logger))
    ->message('New error: "%{message}" in line %{lineNumber}, column %{colNumber}')
]);
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance48

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 81.1% 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.

###  Release Activity

Cadence

Every ~496 days

Recently: every ~605 days

Total

6

Last Release

412d ago

Major Versions

v1.1.0 → v2.0.02019-11-30

PHP version history (3 changes)v1.0.0PHP ^7.0

v2.0.0PHP ^7.2

v2.0.1PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e99df56b617f4af8cf0556a51a0ca20c7420104920c57d7e9eab093f92bb744f?d=identicon)[oscarotero](/maintainers/oscarotero)

![](https://www.gravatar.com/avatar/42e0d72f42eb7d84f67e20d28606da42e5a3248ca908b1eadb4366aafeae2561?d=identicon)[filisko](/maintainers/filisko)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (30 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (4 commits)")[![mimmi20](https://avatars.githubusercontent.com/u/1120192?v=4)](https://github.com/mimmi20 "mimmi20 (3 commits)")

---

Tags

csp-reporthttploggingmiddlewarepsr-15reportinghttppsr-7middlewareservererrorreportingpsr-15logger

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/middlewares-reporting-logger/health.svg)

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

###  Alternatives

[middlewares/whoops

Middleware to use Whoops as error handler

33205.4k25](/packages/middlewares-whoops)[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[middlewares/fast-route

Middleware to use FastRoute

96191.1k15](/packages/middlewares-fast-route)[middlewares/error-handler

Middleware to handle http errors

14104.2k13](/packages/middlewares-error-handler)[middlewares/negotiation

Middleware to implement content negotiation

47442.1k11](/packages/middlewares-negotiation)[middlewares/payload

Middleware to parse the body of the request with support for json, csv and url-encode

32466.8k17](/packages/middlewares-payload)

PHPackages © 2026

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