PHPackages                             tiny-blocks/logger - 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. tiny-blocks/logger

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

tiny-blocks/logger
==================

Emits PSR-3 structured logs for PHP, with correlation tracking and configurable sensitive data redaction.

2.0.0(1mo ago)2267↓85.7%1MITPHPPHP ^8.5CI passing

Since Feb 21Pushed 1w agoCompare

[ Source](https://github.com/tiny-blocks/logger)[ Packagist](https://packagist.org/packages/tiny-blocks/logger)[ Docs](https://github.com/tiny-blocks/logger)[ RSS](/packages/tiny-blocks-logger/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (9)Dependencies (26)Versions (12)Used By (1)

Logger
======

[](#logger)

[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://github.com/tiny-blocks/logger/blob/main/LICENSE)

- [Overview](#overview)
- [Installation](#installation)
- [How to use](#how-to-use)
    - [Basic logging](#basic-logging)
    - [Correlation tracking](#correlation-tracking)
        - [At creation time](#at-creation-time)
        - [Derived from an existing logger](#derived-from-an-existing-logger)
    - [Minimum log level](#minimum-log-level)
    - [Sensitive data redaction](#sensitive-data-redaction)
        - [Strategy catalog](#strategy-catalog)
        - [Choosing a mask](#choosing-a-mask)
        - [Field name patterns](#field-name-patterns)
        - [Document redaction](#document-redaction)
        - [Email redaction](#email-redaction)
        - [Phone redaction](#phone-redaction)
        - [Password redaction](#password-redaction)
        - [Name redaction](#name-redaction)
        - [Visible edges redaction](#visible-edges-redaction)
        - [Wordwise redaction](#wordwise-redaction)
        - [Full mask redaction](#full-mask-redaction)
        - [Scoped redaction](#scoped-redaction)
        - [Allowed fields redaction](#allowed-fields-redaction)
        - [Removed fields redaction](#removed-fields-redaction)
        - [Pattern redaction](#pattern-redaction)
        - [Composing multiple redactions](#composing-multiple-redactions)
        - [Custom redaction](#custom-redaction)
    - [Custom log template](#custom-log-template)
    - [Testing with the in-memory logger](#testing-with-the-in-memory-logger)
- [FAQ](#faq)
- [License](#license)
- [Contributing](#contributing)

Overview
--------

[](#overview)

Emits PSR-3 structured logs for PHP, with each entry carrying timestamp, component, correlation id, level, and a structured data payload. Supports pluggable redactions for sensitive fields such as passwords, emails, phone numbers, and identity documents, plus a severity threshold that drops quieter entries before they are rendered. Built for consumption by log aggregators and SIEM pipelines in production environments.

Redaction is composable and split in two. The `Redactions` namespace holds strategies named after the kind of data they protect, ready to use. Nested under it, `Redactions\Rules` holds the general ones, named after the rule they apply: how much of a value stays visible, which branch of the payload a redaction reaches, which fields survive at all, and which patterns are masked wherever they appear.

Installation
------------

[](#installation)

```
composer require tiny-blocks/logger
```

How to use
----------

[](#how-to-use)

### Basic logging

[](#basic-logging)

Create a logger with `StructuredLogger::create()` and use the fluent builder to configure it. All PSR-3 log levels are supported: `debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert`, and `emergency`.

```
