PHPackages                             philiprehberger/php-structured-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. philiprehberger/php-structured-logger

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

philiprehberger/php-structured-logger
=====================================

PSR-3 compatible logger that outputs structured JSON log lines

v1.0.2(1mo ago)11[1 PRs](https://github.com/philiprehberger/php-structured-logger/pulls)MITPHPPHP ^8.2CI passing

Since Mar 13Pushed 1mo agoCompare

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

READMEChangelogDependencies (4)Versions (3)Used By (0)

PHP Structured Logger
=====================

[](#php-structured-logger)

[![Tests](https://github.com/philiprehberger/php-structured-logger/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-structured-logger/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/4b5c0b749921755f1790a06d6b0cd2ae6b0eb255b90109e1ab4aa142ae275e61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d737472756374757265642d6c6f676765722e737667)](https://packagist.org/packages/philiprehberger/php-structured-logger)[![License](https://camo.githubusercontent.com/aab0f9a02c568d60a2ce197968a6c125f22676997e652ce15f533664941b5df0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d737472756374757265642d6c6f67676572)](LICENSE)

PSR-3 compatible logger that outputs structured JSON log lines.

Requirements
------------

[](#requirements)

- PHP 8.2+
- psr/log ^3.0

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

[](#installation)

```
composer require philiprehberger/php-structured-logger
```

Usage
-----

[](#usage)

### Basic logging

[](#basic-logging)

```
use PhilipRehberger\StructuredLogger\JsonLogger;

// Log to stdout (default)
$logger = new JsonLogger();
$logger->info('Application started');

// Log to a file
$logger = new JsonLogger(output: '/var/log/app.log');
$logger->info('User logged in', ['user_id' => 42]);
```

### Logging with context

[](#logging-with-context)

```
$logger = new JsonLogger(output: 'php://stderr');

$logger->error('Payment failed', [
    'order_id' => 'ORD-123',
    'amount' => 49.99,
    'currency' => 'USD',
]);
```

Output:

```
{"timestamp":"2026-03-13T10:00:00+00:00","level":"error","message":"Payment failed","channel":"app","context":{"order_id":"ORD-123","amount":49.99,"currency":"USD"}}
```

### Sensitive data redaction

[](#sensitive-data-redaction)

By default, the following context keys are automatically redacted: `password`, `token`, `secret`, `api_key`, `authorization`, `credit_card`. Redaction applies recursively to nested arrays.

```
$logger = new JsonLogger();

$logger->info('Auth attempt', [
    'username' => 'alice',
    'password' => 's3cret',
    'token' => 'abc123',
]);
// password and token values replaced with "[REDACTED]"
```

You can provide a custom list of keys to redact:

```
$logger = new JsonLogger(
    redactKeys: ['password', 'ssn', 'credit_card'],
);
```

### Custom channel

[](#custom-channel)

Use the channel parameter to identify different services or application components:

```
$logger = new JsonLogger(
    output: '/var/log/payments.log',
    channel: 'payments',
);

$logger->info('Payment processed');
// {"timestamp":"...","level":"info","message":"Payment processed","channel":"payments"}
```

### Output Format

[](#output-format)

Each log line is a single JSON object with the following fields:

FieldTypeDescription`timestamp`stringISO 8601 timestamp`level`stringPSR-3 log level`message`stringLog message`channel`stringApplication/service name (default: `app`)`context`objectAdditional data (omitted when empty)API
---

[](#api)

### `JsonLogger`

[](#jsonlogger)

ParameterTypeDefaultDescription`output``string``'php://stdout'`File path or PHP stream wrapper`channel``string``'app'`Application/service identifier`redactKeys``string[]``['password', 'token', 'secret', 'api_key', 'authorization', 'credit_card']`Context keys to redactAll PSR-3 log methods are available: `emergency()`, `alert()`, `critical()`, `error()`, `warning()`, `notice()`, `info()`, `debug()`, `log()`.

### `LogEntry`

[](#logentry)

Immutable value object representing a single log entry. Implements `JsonSerializable`.

MethodReturnsDescription`toArray()``array`Entry as associative array`toJson()``string`Entry as JSON string`jsonSerialize()``array`For `json_encode()` supportDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 87% of packages

Maintenance96

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

2

Last Release

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (10 commits)")

---

Tags

logpsr-3jsonloggerstructured

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-structured-logger/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-php-structured-logger/health.svg)](https://phpackages.com/packages/philiprehberger-php-structured-logger)
```

###  Alternatives

[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k6](/packages/inpsyde-wonolog)[apix/log

Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.

511.0M18](/packages/apix-log)[markrogoyski/simplelog-php

Powerful PSR-3 logging. So easy, it's simple.

2818.1k4](/packages/markrogoyski-simplelog-php)[wa72/simplelogger

Wa72SimpleLogger is a collection of very simple loggers implementing \\Psr\\Log\\LoggerInterface (PSR-3)

13246.6k13](/packages/wa72-simplelogger)

PHPackages © 2026

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