PHPackages                             leocavalcante/redact-sensitive - 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. leocavalcante/redact-sensitive

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

leocavalcante/redact-sensitive
==============================

Monolog processor to protect sensitive information from logging

v0.4.1(1y ago)3439.3k↑32.6%6[2 issues](https://github.com/leocavalcante/redact-sensitive/issues)[1 PRs](https://github.com/leocavalcante/redact-sensitive/pulls)1MITPHPPHP &gt;=8.1

Since Jun 17Pushed 1y ago2 watchersCompare

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

READMEChangelog (6)Dependencies (2)Versions (7)Used By (1)

Redact Sensitive [![CI](https://github.com/leocavalcante/redact-sensitive/actions/workflows/ci.yml/badge.svg)](https://github.com/leocavalcante/redact-sensitive/actions/workflows/ci.yml)
==========================================================================================================================================================================================

[](#redact-sensitive-)

🙈 A Monolog processor that protects sensitive data from miss logging.

Avoids logging something like `{"api_key":"mysupersecretapikey"}` by masking partially or completely sensitive data:

```
Readme.INFO: Hello, World! {"api_key":"mysu***************"} []

```

Install
-------

[](#install)

```
composer require leocavalcante/redact-sensitive
```

Usage
-----

[](#usage)

### 1. Prepare your sensitive keys

[](#1-prepare-your-sensitive-keys)

It is a map of key names and how much of it can be displayed, for example:

```
$sensitive_keys = [
    'api_key' => 4,
];
```

Shows the first 4 characters of the `api_key`.

#### If you want to display the last chars, you can use negative values like `['api_key' => -4]`, then it will display the last 4 characters.

[](#if-you-want-to-display-the-last-chars-you-can-use-negative-values-like-api_key---4-then-it-will-display-the-last-4-characters)

### 2. Create a Processor using the keys

[](#2-create-a-processor-using-the-keys)

You can now create a new Processor with the given keys:

```
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['api_key' => 4];

$processor = new RedactSensitiveProcessor($sensitive_keys);
```

### 3. Set the Processor to a Monolog\\Logger

[](#3-set-the-processor-to-a-monologlogger)

```
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['api_key' => 4];

$processor = new RedactSensitiveProcessor($sensitive_keys);

$logger = new \Monolog\Logger('Readme');
$logger->pushProcessor($processor);
```

Examples
--------

[](#examples)

```
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['api_key' => 4];

$processor = new RedactSensitiveProcessor($sensitive_keys);

$logger = new \Monolog\Logger('Readme', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);

$logger->info('Hello, World!', ['api_key' => 'mysupersecretapikey']);
```

```
Readme.INFO: Hello, World! {"api_key":"mysu***************"} []

```

### Completely hidden

[](#completely-hidden)

You can hide it completely by passing `0` to the key.

```
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['you_know_nothing' => 0];

$processor = new RedactSensitiveProcessor($sensitive_keys);

$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);

$logger->info('Completely hidden', ['you_know_nothing' => 'John Snow']);
```

```
Example.INFO: Completely hidden {"you_know_nothing":"*********"} []

```

### Custom format

[](#custom-format)

Feel free to customize a replacement character `*` and/or provide your own template.

```
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['secret' => 2];

$processor = new RedactSensitiveProcessor($sensitive_keys, template: '%s(redacted)');

$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);

$logger->info('Sensitive', ['secret' => 'my_secret_value']);
```

```
Example.INFO: Sensitive {"secret":"my*************(redacted)"} []

```

Custom template allows to discard the masked characters altogether:

```
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['secret' => 2];

$processor = new RedactSensitiveProcessor($sensitive_keys, template: '...');

$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);

$logger->info('Sensitive', ['secret' => 'my_secret_value']);
```

```
Example.INFO: Sensitive {"secret":"my..."} []

```

### Length limit

[](#length-limit)

Use `lengthLimit` to truncate redacted sensitive information, such as lengthy tokens.

```
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['access_token' => 0];

$processor = new RedactSensitiveProcessor($sensitive_keys, lengthLimit: 5);

$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);

$logger->info('Truncated secret', ['access_token' => 'Very long JWT ...']);
```

```
Example.INFO: Truncated secret {"access_token":"*****"} []

```

### Right to left

[](#right-to-left)

And, as said before, you can mask the value from right to left using negative values.

```
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = ['credit_card' => -4];

$processor = new RedactSensitiveProcessor($sensitive_keys);

$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);

$logger->info('You are not storing credit cards, right?', ['credit_card' => '4111111145551142']);
```

```
Example.INFO: You are not storing credit cards, right? {"credit_card":"************1142"} []

```

### Nested values

[](#nested-values)

It should work with nested objects and arrays as well.

```
use Monolog\Handler\StreamHandler;
use RedactSensitive\RedactSensitiveProcessor;

$sensitive_keys = [
    'nested' => [
        'arr' => [
            'value' => 3,
            'or_obj' => ['secret' => -3],
        ],
    ]
];

$processor = new RedactSensitiveProcessor($sensitive_keys);

$logger = new \Monolog\Logger('Example', [new StreamHandler(STDOUT)]);
$logger->pushProcessor($processor);

$nested_obj = new stdClass();
$nested_obj->secret = 'donttellanyone';

$logger->info('Nested', [
    'nested' => [
        'arr' => [
            'value' => 'abcdfg',
            'or_obj' => $nested_obj,
        ],
    ],
]);
```

```
Example.INFO: Nested {"nested":{"arr":{"value":"abc***","or_obj":{"stdClass":{"secret":"***********one"}}}}} []

```

Thanks
------

[](#thanks)

Feel free to open any issues or PRs.

---

MIT © 2021

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65.2% 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 ~240 days

Recently: every ~135 days

Total

6

Last Release

594d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.4|&gt;=8.0

v0.2.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/940717934113da7abe00589e87cfde6f34496f039bcd3fc6ce4a33f5f415d4ac?d=identicon)[leocavalcante](/maintainers/leocavalcante)

---

Top Contributors

[![leocavalcante](https://avatars.githubusercontent.com/u/183722?v=4)](https://github.com/leocavalcante "leocavalcante (15 commits)")[![deoomen](https://avatars.githubusercontent.com/u/6989706?v=4)](https://github.com/deoomen "deoomen (2 commits)")[![dnsbty](https://avatars.githubusercontent.com/u/3421625?v=4)](https://github.com/dnsbty "dnsbty (2 commits)")[![sshymko-promenade](https://avatars.githubusercontent.com/u/95300875?v=4)](https://github.com/sshymko-promenade "sshymko-promenade (2 commits)")[![aymanrb](https://avatars.githubusercontent.com/u/4629433?v=4)](https://github.com/aymanrb "aymanrb (1 commits)")[![thomashmolina](https://avatars.githubusercontent.com/u/8107651?v=4)](https://github.com/thomashmolina "thomashmolina (1 commits)")

---

Tags

grpdlgpdloggingmonologmonolog-processorsenstive-logging

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/leocavalcante-redact-sensitive/health.svg)

```
[![Health](https://phpackages.com/badges/leocavalcante-redact-sensitive/health.svg)](https://phpackages.com/packages/leocavalcante-redact-sensitive)
```

###  Alternatives

[symfony/monolog-bridge

Provides integration for Monolog with various Symfony components

2.6k189.7M258](/packages/symfony-monolog-bridge)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[illuminate/log

The Illuminate Log package.

6224.3M518](/packages/illuminate-log)[honeybadger-io/honeybadger-php

Honeybadger PHP library

381.5M4](/packages/honeybadger-io-honeybadger-php)[graycore/magento2-stdlogging

A Magento 2 module that changes all logging handlers to stdout

2382.6k](/packages/graycore-magento2-stdlogging)

PHPackages © 2026

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