# ampersand/magento2-verbose-log-request

> Enable DB, debug log, and verbose logging for a specificly defined request.

`composer require ampersand/magento2-verbose-log-request`

Canonical URL: https://packagento.com/ampersand/magento2-verbose-log-request

## At a glance

- **Vendor**: ampersand (https://packagento.com/ampersand.md)
- **Latest version**: 1.3.0 — released 2026-04-20
- **Pricing**: Free
- **Package type**: Magento 2 component
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/ampersand/magento2-verbose-log-request and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require ampersand/magento2-verbose-log-request:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

Enable DB, debug log, and verbose logging for a specificly defined request.

## README

[![Build Status](https://travis-ci.com/AmpersandHQ/magento2-verbose-log-request.svg?token=4DzjEueYNQwZuk3ywXjG&branch=master)](https://app.travis-ci.com/AmpersandHQ/magento2-verbose-log-request)

### Summary

Dynamically change the [log level per request](https://devopedia.org/log-level-per-request) to `DEBUG`. This enables database, debug log, and verbose logging for a specifically defined request.

Pass in a `X-Verbose-Log` header and Magento will activate the kind of logging you usually only have in developer mode for that request. 

This means you can get verbose information when you are debugging something on production without having to switch on these settings forcefully. This is beneficial as on high traffic sites this can produce a lot of log data and narrowing in for what you are interested in can be difficult otherwise.

It is recommended that you also install [ampersand/magento2-log-correlation-id](https://github.com/AmpersandHQ/magento2-log-correlation-id/) to help correlate your log entries together.

Compatible with Magento 2.4.1 and higher.

### Features

- Database query (and stack trace) logging will be enabled and output to `./var/log/verbose_db.log`
  - https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/cli/enable-logging.html#database-logging
  - See `src/Logger/DB/LoggerProxy.php`
- Magento `debug` logging usually requires that you set a flag and flush a cache, we can pass the flag to activate it for your specific requests without these steps
  - https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/cli/enable-logging.html#debug-logging
  - See `src/Logger/Handler/Debug.php`
- Bundled in this module is a cache decorator which will add to the vanilla offering of logging `cache_invalidate` with `cache_load` and `cache_save` information.
  - This uses a virtual type `Ampersand\VerboseLogRequest\Logger\VerboseDebugLogger` which calls to `->debug()` on the `Psr\Log\LoggerInterface`.
  - See `src/CacheDecorator/VerboseLogger.php`
- Set redis session log level to debug mode (level 7)
  - Allows you to see redis lock acquisitions, lock waits, zombie processes, etc
  - https://github.com/colinmollenhour/Cm_RedisSession#configuration-example

### Example Usage

On the system you want to debug run the following command to get the current key

```
$ php bin/magento ampersand:verbose-log-request:get-key
The current key is:               d07c0ee76154d48c2974516ef22c1ec0
The current key will expire at:   2022-10-25 09:00:00
```

Make a request to your desired page with an `X-Verbose-Log` header set to that value

```bash
curl -H "X-Verbose-Log: d07c0ee76154d48c2974516ef22c1ec0" https://example.com/your-page/
```

or 

```
X_VERBOSE_LOG=d07c0ee76154d48c2974516ef22c1ec0 php bin/magento some:command:here
```

See all your verbose log files
```shell
 12M var/log/debug.log
3.1M var/log/verbose_db.log
4.0K var/log/system.log
4.0K var/log/support_report.log
```

If you want to do more complex interactions you could use something like [modheader](https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj?hl=en) to set this value for a series of requests, be aware that will output a LOT of debug data. 

### Installation

Composer require the module.

```
composer require ampersand/magento2-verbose-log-request
```

Run module installation, this will generate your `ampersand/verbose_log_request/key` in `app/etc/config.php`, commit this change.
```
php bin/magento setup:upgrade
```

Update your `.gitignore` to ignore 

```
app/etc/di.xml_ampersand_magento2_verbose_log_request/di.xml
```

If you want to give certain admin users permissions to get the key via the `Admin Panel -> Account Settings -> Get Verbose Log Key` create `app/etc/di.xml_ampersand_magento2_verbose_log_request/allowed_emails_di.xml` and define the allowed emails/domains. 

```xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Ampersand\VerboseLogRequest\Service\Adminhtml\AllowedEmails">
        <arguments>
            <!-- It is recommended to allow specific emails -->
            <argument name="allowedEmails" xsi:type="array">
                <item name="1" xsi:type="string">example@firstexample.com</item>
            </argument>
            <!-- There is support for whitelisting a whole domain, but this is less strict than the above -->
            <argument name="allowedDomains" xsi:type="array">
                <item name="1" xsi:type="string">secondexample.com</item>
            </argument>
        </arguments>
    </type>
</config>
```

### Security considerations

As all we are doing is writing to the log files the biggest "risk" is to your disk space. 

However as you need to know the key to trigger the logging it can be locked down to your developers and won't be accessible to the outside world unless they already have access to your file system.

### A log level below "debug", the VerboseDebugLogger

By default magento has `debug` level logging enabled on `developer` mode and it may even be activated on some production environments. As we want to log `cache_load` and `cache_save` information this would rapidly fill up your log files on either your developer machine, or those production enivornments with lots of unnecessary data. 

To ensure we only trigger these _extra verbose_ debug level logging when the `X-Verbose-Log` request is flagged, we have a virtual type that you can inject into your classes. 

`Ampersand\VerboseLogRequest\Logger\VerboseDebugLogger` will write to the `./var/log/debug.log` file the same as the standard calls to `->debug()`, but they will only write when flagged to in the request.

_(README truncated for .md surface. Full README on https://packagento.com/ampersand/magento2-verbose-log-request.)_

## Recent Versions

| Version | Released |
|---|---|
| 1.3.0 | 2026-04-20 |
| 1.2.1 | 2026-03-09 |
| 1.2.0 | 2023-11-21 |
| 1.1.0 | 2022-12-04 |
| 1.0.2 | 2022-10-25 |
| 1.0.1 | 2022-10-25 |
| 1.0.0 | 2022-10-20 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/framework | >=103.0.1 |
| magento/magento-composer-installer | * |
| magento/module-developer | * |
| php | ^7.4\|\|^8.1 |

### Require (dev)

| Package | Constraint |
|---|---|
| ampersand/magento-docker-test-instance | ^0.1 |
| bitexpert/phpstan-magento | ^0.11 |
| friendsofphp/php-cs-fixer | ^3.4 |
| magento/magento-coding-standard | ^15 |
| magento/magento2-base | * |
| phpstan/phpstan | ^1.5 |
| phpunit/phpunit | ^9.5 |

### Suggest

| Package | Constraint |
|---|---|
| ampersand/magento2-log-correlation-id | A way to correlate log entries to a request |

## Quality

Latest release (1.3.0) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 1 | 1 | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | Pass |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 23 | 8 errors, 15 warnings (ruleset: Magento2) — 2 auto-fixable with phpcbf |
| PHPMD | Warning | 3 | 3 rule violations (UnusedFormalParameter:3) |
| Cpd | Pass | 0 |  |
| Composer validate | Info | 4 | valid; 4 advisory notes (composer validate --strict) |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 1 | 1 | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | Pass |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | N/A | 0 | no resolvable dependency tree to audit — Your requirements could not be resolved to an installable set of packages. Problem 1 |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["ampersand/magento2-verbose-log-request"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

ampersand is a Magento 2 vendor on Packagento. See https://packagento.com/ampersand.md for their full catalogue.

