Neuron-PHP

IFilter

Log filtering interface for the Neuron logging system.

This interface defines the contract for log filters, which provide conditional processing and transformation of log entries before they reach their final destination. Filters enable sophisticated log processing including:

  • Conditional logging based on level, content, or context
  • Log entry transformation and enrichment
  • Rate limiting and sampling
  • Sensitive data scrubbing and redaction
  • Log routing and conditional forwarding

Filter behavior:

  • Return the Data object (modified or unmodified) to continue processing
  • Return null to prevent the log entry from being written
  • Filters are applied in the order they were added to destinations
  • Each filter receives the output of the previous filter in the chain
Tags
example
class DebugOnlyFilter implements IFilter
{
    public function filter(Data $data): Data|null
    {
        // Only allow debug level logs
        return $data->getLevel()->isDebug() ? $data : null;
    }
}

class SensitiveDataFilter implements IFilter
{
    public function filter(Data $data): Data|null
    {
        $message = $data->getMessage();
        $message = preg_replace('/password=\w+/', 'password=***', $message);
        return $data->withMessage($message);
    }
}

Table of Contents

Methods

filter()  : Data|null

Methods

filter()

public filter(Data $data) : Data|null
Parameters
$data : Data
Return values
Data|null

Return null if no logging should be performed.


        
On this page

Search results