PHPackages                             marlonpcg/test-request-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. marlonpcg/test-request-logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

marlonpcg/test-request-logger
=============================

TestRequestLogger is a lightweight, pluggable error logging system for PHP applications. It captures PHP errors during web requests and logs them in structured JSON format. Ideal for testing and debugging, especially in automated test suites.

v1.0.0(1y ago)02MITPHPPHP &gt;=7.4

Since Apr 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/marlonpcg/test-request-logger)[ Packagist](https://packagist.org/packages/marlonpcg/test-request-logger)[ RSS](/packages/marlonpcg-test-request-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

TestRequestLogger
=================

[](#testrequestlogger)

**TestRequestLogger** is a lightweight, pluggable error logging system for PHP applications. It captures PHP errors (including fatal, warning, notice, and custom errors) during web requests and logs them in structured JSON format. Ideal for testing and debugging, especially in automated test suites.

---

🧠 Motivation
------------

[](#-motivation)

This tool was created to support **projects that are still under construction**, where the codebase is frequently changing and errors may occur unpredictably. It is especially useful for projects that **have not yet reached the maturity level required for final QA testing**.

In these early stages of development, where multiple developers are actively working and contributing code, unnoticed PHP errors such as warnings, notices, or fatals may be generated during web **requests**.

**TestRequestLogger** provides an automatic and structured way to detect these errors early by logging them per request and grouping them by test ID. It helps teams quickly identify and review problems before formal QA begins.

> It was built to help answer a simple question:
>
> 🔍 *“Did this request execute cleanly, without any PHP errors?”*

---

🚀 Features
----------

[](#-features)

- 🔍 Captures all major PHP error types:
    - `Fatal`, `Warning`, `Notice`, `Strict`, `Deprecated`, `User-defined`
- 🧠 Grouped by **TestRequestLoggerId** (from header, GET or POST)
- 🗂 One structured JSON log **per request**
- 📁 Output directory organized by test ID and timestamp
- 🧩 Fully extensible:
    - Plug your own writers (e.g., file, database, remote API)
- ✅ Option to log all errors or only specific types (e.g., only `fatal`)
- 💡 Automatically appends metadata:
    - `timestamp`, `IP`, `method`, `error_code`, `error_type`, etc.
- 💾 Generates **valid JSON arrays**, ready for parsing or integration

---

📦 Installation
--------------

[](#-installation)

### ✅ Option 1: Install via Composer (Recommended)

[](#-option-1-install-via-composer-recommended)

```
composer require marlonpcg/test-request-logger
```

### ✅ Option 2: Clone from GitHub (for development or testing)

[](#-option-2-clone-from-github-for-development-or-testing)

```
git clone https://github.com/marlonpcg/test-request-logger.git
cd test-request-logger
composer install
```

---

🧩 Usage
-------

[](#-usage)

### ▶️ Standard usage with Composer

[](#️-standard-usage-with-composer)

```
require_once __DIR__ . '/vendor/autoload.php';

use TestRequestLogger\TestRequestLoggerInit;

// Log all error types (default)
TestRequestLoggerInit::init();

// Or log only specific types
TestRequestLoggerInit::init(acceptedErrorTypes: 'fatal');
TestRequestLoggerInit::init(acceptedErrorTypes: ['warning', 'fatal']);
```

### 👷 Local development usage (without Composer)

[](#-local-development-usage-without-composer)

```
require_once __DIR__ . '/test-request-logger/src/TestRequestLoggerInit.php';

use TestRequestLogger\TestRequestLoggerInit;

TestRequestLoggerInit::init();
```

---

▶️ How to test via URL
----------------------

[](#️-how-to-test-via-url)

You can test the logger by running a script (like `demo.php`) via browser, curl, or Postman and providing a test ID:

### Example 1: Browser / Curl

[](#example-1-browser--curl)

```
http://localhost/test-request-logger/demo.php?TestRequestLoggerId=1
```

This will generate a JSON file in the folder:

```
/output/1/demo_YYYYMMDD_HHMMSS.json

```

### Example 2: Using custom headers (e.g. Postman)

[](#example-2-using-custom-headers-eg-postman)

**Header:**

```
TestRequestLoggerId: 2

```

**Request URL:**

```
http://localhost/test-request-logger/demo.php

```

This allows automated tools to test multiple pages and track logs by test ID.

---

📝 Log Output
------------

[](#-log-output)

Each request creates a JSON file under:

```
/output/{TestRequestLoggerId}/{script-name}_{timestamp}.json

```

The file contains an array of JSON objects:

```
[
  {
    "TestRequestLoggerId": "123",
    "request": "/demo.php",
    "timestamp": "2025-04-03 14:21:01",
    "method": "GET",
    "type": "error",
    "error": "8 - Undefined variable $x in demo.php:12",
    "error_type": "Notice",
    "error_code": 8
  },
  ...
]
```

---

🧪 Demo
------

[](#-demo)

Use the provided `demo.php` script:

```
// Configuration
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Check if TestRequestLoggerId was provided
$hasLoggerId =
    isset($_GET['TestRequestLoggerId']) ||
    isset($_POST['TestRequestLoggerId']) ||
    isset(getallheaders()['TestRequestLoggerId']);

if (!$hasLoggerId) {
    echo "
        ⚠️ Warning: Logging will not work. You must provide a TestRequestLoggerId via GET, POST or Header.
    ";
}

// Logger Integration
require_once 'test-request-logger/src/TestRequestLoggerInit.php';
use TestRequestLogger\TestRequestLoggerInit;
TestRequestLoggerInit::init(acceptedErrorTypes: 'all');

// Trigger test errors
session_start();
session_start();
fopen('not_found.txt', 'r');

try {
    throw new Exception("Test exception");
} catch (Exception $e) {
    trigger_error("Caught exception: " . $e->getMessage(), E_USER_WARNING);
}

trigger_error("Simulated fatal error", E_USER_ERROR);
```

---

🙋 Who is this for?
------------------

[](#-who-is-this-for)

- Teams building PHP applications that are still under construction or early development stages
- Projects that haven't yet reached QA maturity but require a way to monitor runtime stability
- Developers working in a collaborative environment where code changes are frequent
- Test engineers and automation tools that need to track PHP errors across multiple requests
- Anyone who wants to ensure that every request executes without hidden PHP warnings, notices, or fatals

---

📄 License
---------

[](#-license)

MIT License

**Author**: Marlon Pinheiro Claro Gomes ()

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance49

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

400d ago

### Community

Maintainers

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

---

Top Contributors

[![marlonpcg](https://avatars.githubusercontent.com/u/4926168?v=4)](https://github.com/marlonpcg "marlonpcg (2 commits)")

### Embed Badge

![Health badge](/badges/marlonpcg-test-request-logger/health.svg)

```
[![Health](https://phpackages.com/badges/marlonpcg-test-request-logger/health.svg)](https://phpackages.com/packages/marlonpcg-test-request-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.1k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M93](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M136](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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