PHPackages                             assimtech/dislog - 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. assimtech/dislog

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

assimtech/dislog
================

API call logger

3.1.1(1mo ago)13.1k↓50%1MITPHPPHP ^7.2.5|^8

Since Jul 27Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/assimtech/dislog)[ Packagist](https://packagist.org/packages/assimtech/dislog)[ Docs](https://github.com/assimtech/dislog)[ RSS](/packages/assimtech-dislog/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (22)Versions (26)Used By (1)

Dislog
======

[](#dislog)

[![Latest Stable Version](https://camo.githubusercontent.com/8f744acc6dd27fff1c4ad4826574afe461eb4b3fb89e77120574d48f72c776c4/68747470733a2f2f706f7365722e707567782e6f72672f617373696d746563682f6469736c6f672f762f737461626c65)](https://packagist.org/packages/assimtech/dislog)[![Total Downloads](https://camo.githubusercontent.com/c56a2d57e2f60864f95b0eb0b32f621c779319642de4fc3b50cc78d6d771f2dd/68747470733a2f2f706f7365722e707567782e6f72672f617373696d746563682f6469736c6f672f646f776e6c6f616473)](https://packagist.org/packages/assimtech/dislog)[![Latest Unstable Version](https://camo.githubusercontent.com/6f554aa324c07ecc392da59dcc8e79eebea03954ff021844df510248bc9e8990/68747470733a2f2f706f7365722e707567782e6f72672f617373696d746563682f6469736c6f672f762f756e737461626c65)](https://packagist.org/packages/assimtech/dislog)[![License](https://camo.githubusercontent.com/e2055c18d3149681b23f6691c256491bcc3819c5dd56407a1f61c06bec17d558/68747470733a2f2f706f7365722e707567782e6f72672f617373696d746563682f6469736c6f672f6c6963656e7365)](https://packagist.org/packages/assimtech/dislog)

Dislog is an API call logger. API calls differ from normal log events because they compose of a request and a response which happen at different times however should be logged together as they are related.

Framework integration
---------------------

[](#framework-integration)

[Symfony - DislogBundle](https://github.com/assimtech/dislog-bundle)

Usage
-----

[](#usage)

### LoggingHttpClientInterface

[](#logginghttpclientinterface)

A PSR-18 compatible `LoggingHttpClient` is provided if recording HTTP requests from a `Psr\Http\Client\ClientInterface`.

Note: if using `Assimtech\Dislog\LoggingHttpClient` you **MUST** install the following dependancies into your project:

- `guzzlehttp/psr7` This is only used to translate Psr\\Http\\Message{RequestInterface,ResponseInterface} into strings
- `psr/http-client`
- `psr/http-message`

```
/**
 * @var Psr\Http\Client\ClientInterface $httpClient
 * @var Assimtech\Dislog\ApiCallLoggerInterface $apiCallLogger
 */
$loggingHttpClient = new Assimtech\Dislog\LoggingHttpClient(
    $httpClient,
    $apiCallLogger
);

/**
 * @var Psr\Http\Message\ResponseInterface $response
 */
$response = $loggingHttpClient->sendRequest(
    /* Psr\Http\Message\RequestInterface */ $request,
    /* ?string */ $appMethod = null, // The method in the application that triggered this API call, setting to null will disable API logging
    /* ?string */ $reference = null, // The reference for this specific call (e.g. id or key if available), helps with searching API logs
    /* callable[]|callable|null */ $requestProcessors = null, // Processors to apply to $request, see Processors section below
    /* callable[]|callable|null */ $responseProcessors = null, // Processors to apply to $response, see Processors section below
    /* bool */ $omitPayload = false, // If set to true, request/response will not be logged however metadata will, useful for monitoring without logging full request or response
);
```

#### Payload omission

[](#payload-omission)

If you only want to log metadata (everything except for the raw request / response) on certain responses you can use `$omitPayload`. If you decide after making the API call you DO want to log the raw request / response you may force the payload to be logged.

```
$response = $loggingHttpClient->sendRequest(
    $request,
    $appMethod,
    $reference,
    $requestProcessors,
    $responseProcessors,
    true, // $omitPayload - Do not log raw request / response but still log all other metadata, this allows us to still monitor api calls
);
if (200 !== $response->getStatusCode()) {
    $loggingHttpClient->logLastPayload();
}
```

### ApiCallLogger

[](#apicalllogger)

The `ApiCallLogger` may be used to record requests and responses to both client and server side apis. Request and response payloads are both optional. If you are recording an FTP file upload, there may not be a response on successful upload. You would still invoke `logResponse` however to indicate the server accepted the file.

```
/**
 * @var Assimtech\Dislog\ApiCallLoggerInterface $apiCallLogger
 * @var Assimtech\Dislog\Model\ApiCallInterface $apiCall
 */
$apiCall = $apiCallLogger->logRequest(
    /* ?string */ $request,
    /* ?string */ $endpoint,
    /* ?string */ $appMethod,
    /* ?string */ $reference,
    /* callable[]|callable|null */ $processors
);

$response = $api->transmit($request);

$this->apiCallLogger->logResponse($apiCall, $response);
```

Here's an example of dislog in a fake Api:

```
use Assimtech\Dislog;

class Api
{
    protected $apiLogger;

    public function __construct(Dislog\ApiCallLoggerInterface $apiCallLogger)
    {
        $this->apiCallLogger = $apiCallLogger;
    }

    public function transmit($request)
    {
        return '';
    }

    public function doSomething()
    {
        $request = '';
        $endpoint = 'http://my.endpoint';
        $reference = time();

        $apiCall = $this->apiCallLogger->logRequest(
            $request,
            $endpoint,
            __METHOD__,
            $reference
        );

        $response = $this->transmit($request);

        $this->apiCallLogger->logResponse(
            $apiCall,
            $response
        );
    }
}

$stream = fopen('/tmp/my.log', 'a');
$uniqueIdentity = new Dislog\Identity\UniqueIdGenerator();
$stringSerializer = new Dislog\Serializer\StringSerializer();
$streamHandler = new Dislog\Handler\Stream($stream, $uniqueIdentity, $stringSerializer);
$apiCallFactory = new Dislog\Factory\ApiCallFactory();
$apiCallLogger = new Dislog\ApiCallLogger($apiCallFactory, $streamHandler);

$api = new Api($apiCallLogger);
$api->doSomething();
```

Old logs can be cleaned up by calling remove on supporting handlers:

```
$handler->remove(60 * 60 * 24 * 30); // keep 30 days worth of logs
```

Handlers
--------

[](#handlers)

### Stream

[](#stream)

This handler accepts a writable stream resource. You must also give it an identity generator and a serializer.

```
use Assimtech\Dislog;

$stream = fopen('/tmp/my.log', 'a');
$uniqueIdentity = new Dislog\Identity\UniqueIdGenerator();
$stringSerializer = new Dislog\Serializer\StringSerializer();

$streamHandler = new Dislog\Handler\Stream($stream, $uniqueIdentity, $stringSerializer);
```

### DoctrineDocumentManager

[](#doctrinedocumentmanager)

This handler accepts a `Doctrine\ODM\MongoDB\DocumentManager`.

**Note: You must setup any mapping to an `Assimtech\Dislog\Model\ApiCallInterface` in your document manager****WARNING: It is advisable to avoid using your application's default document manager as a `flush()` from dislog may interfere with your application**

```
$documentHandler = new Dislog\Handler\DoctrineDocumentManager($documentManager);
```

### DoctrineEntityManager

[](#doctrineentitymanager)

This handler accepts a `Doctrine\ORM\EntityManagerInterface`.

**Note: You must setup any mapping to an `Assimtech\Dislog\Model\ApiCallInterface` in your entity manager****WARNING: It is advisable to avoid using your application's default entity manager as a `flush()` from dislog may interfere with your application**

```
$entityHandler = new Dislog\Handler\DoctrineEntityManager($entityManager);
```

Processors
----------

[](#processors)

A processor is a callable which is executed on either the request or response payload. They can be used for modifying the request or response before the ApiCall is handled. An example might be to mask credit card numbers or obfuscate a password.

Processors are passed along with the `logRequest` and / or `logResponse` calls to process the appropriate payload.

**Note: Processors are not invoked on a null request / response.**

```
function getMaskedCard($card)
{
    $firstSix = substr($card, 0, 6);
    $lastFour = substr($card, -4);
    $middle = str_repeat('*', strlen($card) - 10);
    return $firstSix . $middle . $lastFour;
}

$endpoint = 'https://my.endpoint';
$appMethod = 'processPayment';
$reference = time();
$card = '4444333322221111';
$cvv = '123';
$request = json_encode([
    'amount' => 12.95,
    'card' => $card,
    'expiry' => '2021-04',
    'cvv' => $cvv,
]);

$maskCard = function ($request) use ($card) {
    $maskedCard = getMaskedCard($card);
    return str_replace($card, $maskedCard, $request);
};
$obfuscateCvv = function ($request) use ($cvv) {
    return str_replace($cvv, '***', $request);
};
$apiCallLogger->logRequest(
    $request,
    $endpoint,
    $appMethod,
    $reference,
    [
        $maskCard,
        $obfuscateCvv,
    )
);
```

### StringReplace

[](#stringreplace)

This processor is based on php's `str_replace`. It will replace a known string in a request / response.

```
$maskedCard = getMaskedCard($card);
$obfuscatedCvv = '***';
$stringReplace = new Assimtech\Dislog\Processor\StringReplace([
    $card,
    $cvv,
], [
    $maskedCard,
    $obfuscatedCvv,
]);
$apiCallLogger->logRequest(
    $request,
    $endpoint,
    $appMethod,
    $reference,
    $stringReplace
);
```

### RegexReplace

[](#regexreplace)

This processor is based on php's `preg_replace`. It will replace a regex in a request / response.

```
$response = '{social_security_number: "1234567890"}';
$regexReplace = new Assimtech\Dislog\Processor\RegexReplace(
    '/social_security_number: "(\d\d)\d+(\d\d)"/',
    'social_security_number: "$1***$2"'
);
$apiCallLogger->logResponse(
    $apiCall,
    $response,
    $regexReplace
);
```

Serializers
-----------

[](#serializers)

A Serializer is a callable which converts an `ApiCall` into something a handler can deal with. Not all handers need to be paired with a Serializer and can deal with a raw `ApiCall` (e.g. `DoctrineObjectManager`).

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance89

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity68

Established project with proven stability

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 ~162 days

Recently: every ~369 days

Total

25

Last Release

55d ago

Major Versions

1.0.2 → 2.0.02018-05-18

2.7.3 → 3.0.02022-08-02

PHP version history (5 changes)1.0.0PHP &gt;=5.3.3

1.0.2PHP &gt;=5.5.9

2.0.0PHP ^7.1.3

2.1.0PHP ^7.2.5

2.3.0PHP ^7.2.5|^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/44b37dfa4c70338da1f28fe48badad8d80cb0629e3dff8e7b758236ad942a27d?d=identicon)[kralos](/maintainers/kralos)

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/assimtech-dislog/health.svg)

```
[![Health](https://phpackages.com/badges/assimtech-dislog/health.svg)](https://phpackages.com/packages/assimtech-dislog)
```

###  Alternatives

[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[theorchard/monolog-cascade

Monolog extension to configure multiple loggers in the blink of an eye and access them from anywhere

1482.2M9](/packages/theorchard-monolog-cascade)[php-soap/ext-soap-engine

An ext-soap engine implementation

443.2M7](/packages/php-soap-ext-soap-engine)[codemix/yii2-streamlog

A Yii 2 log target for streams in URL format

531.4M6](/packages/codemix-yii2-streamlog)

PHPackages © 2026

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