andybeak/monolog-redact-sensitive

Monolog processors that will redact potentially sensitive information

v1.0.0 2019-12-03 21:25 UTC

This package is auto-updated.

Last update: 2024-03-29 03:59:03 UTC


README

Build Status Maintainability Test Coverage

These Monolog processors will identify and strip out emails and credit cards respectively.

WARNING: These processors will json serialise your $context. This may cause some undesired side-effects.

Installation

Install the latest version with

composer require andybeak/monolog-redact-sensitive

Usage

Here is example usage:

<?php
require('vendor/autoload.php');
use AndyBeak\Monolog\Redact\Processor\RedactCreditCardProcessor;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$generalLogger = new Logger('general');
$streamHandler = new StreamHandler(__DIR__ . DIRECTORY_SEPARATOR . 'example.log', Logger::DEBUG);
$generalLogger->pushHandler($streamHandler);

$processor = new RedactCreditCardProcessor();
$generalLogger->pushProcessor($processor);

$generalLogger->debug('Visa test: 4111111111111111 is a test card number');

The credit card number will be removed in the file

Credit card stripper

The code looks for potential credit cards by using regex to identify strings of numbers that are the right length. These numbers may contain spaces or dashes between them.

The regex is not perfect

The numbers are validated and if they are valid credit card numbers they are redacted.

Email stripper

Identifying email addresses with regex is tricky.

By default the processor uses a good regex pattern, but you might find that it is too expensive to use.

You can call the setRegex function to replace the regex with something less complicated if you find your performance slipping.

The signature of this function is:

public function setRegex(string $regex): RedactEmailProcessor