PHPackages                             mafio69/fast-php-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. mafio69/fast-php-logger

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

mafio69/fast-php-logger
=======================

PSR-3 dual logger with file rotation, date-based structure and automatic anonymization of sensitive fields

v1.0.0(1mo ago)021↓100%MITPHPPHP &gt;=8.1

Since May 2Pushed 1mo agoCompare

[ Source](https://github.com/mafio69/php-logger)[ Packagist](https://packagist.org/packages/mafio69/fast-php-logger)[ Docs](https://github.com/mafio69/fast-php-logger)[ RSS](/packages/mafio69-fast-php-logger/feed)WikiDiscussions master Synced 1w ago

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

mafio69/fast-php-logger
=======================

[](#mafio69fast-php-logger)

PSR-3 compliant dual logger for PHP 8.1+ with:

- date-based log file structure with configurable subdirectory pattern
- automatic log rotation by file size
- caller location in every log entry (`directory/file.php:line`)
- automatic anonymization of sensitive fields
- configurable minimum log level for file output
- configurable date format and timezone

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

[](#installation)

```
composer require mafio69/fast-php-logger
```

Without Composer
----------------

[](#without-composer)

> **No Composer? No problem.**A pre-built single file is available on every [GitHub Release](https://github.com/mafio69/php-logger/releases). Download `fast-php-logger.php`, drop it anywhere in your project, and you're done.

```
require_once 'fast-php-logger.php';

$logger = \Mariusz\Logger\DualLogger::create('./logs');
$logger->info('Hello');
```

- Zero dependencies — PSR-3 interfaces are bundled inside
- Works with PHP 8.1+
- Identical API to the Composer version

**Building the file yourself:**

```
git clone https://github.com/mafio69/php-logger.git
cd php-logger
composer install   # only needed once, to fetch psr/log sources
php bin/build.php  # generates dist/fast-php-logger.php
```

### Full configuration (no Composer)

[](#full-configuration-no-composer)

```
require_once 'fast-php-logger.php';

use Mariusz\Logger\DualLogger;
use Mariusz\Logger\LogFileManager;
use Psr\Log\LogLevel;

$logger = new DualLogger(
    new LogFileManager(
        logDir:        './logs',
        maxFileSize:   1048576,       // 1MB before rotation
        maxFiles:      5,             // keep 5 archives
        prefix:        'app-',        // → app-2026-05-02.log
        suffix:        '',
        dateStructure: 'Y/m',         // → logs/2026/05/
    ),
    minLevel:         LogLevel::WARNING,    // only warning and above go to file
    dateFormat:       'Y-m-d H:i:s',
    timezone:         'Europe/Warsaw',
    stderrEnabled:    true,                 // set false to disable STDERR entirely
    stderrSkipInTest: true,                 // suppress STDERR when APP_ENV=test
);
```

Quick start
-----------

[](#quick-start)

```
$logger->info('Server started');
```

\[2026-05-02 01:54:00\] \[INFO\] \[Bootstrap/App.php:12\] Server started

```
$logger->warning('Login failed', ['email' => 'jan@example.com', 'token' => 'abc123xyz']);
```

\[2026-05-02 01:54:00\] \[WARNING\] \[Auth/Service.php:88\] Login failed {"email":"jan**com","token":"a**yz"}

```
$logger->error('Order failed', [
    'order' => ['id' => 42, 'items' => 3],          // nested array — serialized as-is
    'user'  => new User(id: 7, name: 'Jan'),         // object — public properties dumped
]);
```

```
[2026-05-02 01:54:00] [ERROR]   [Shop/Service.php:55]  Order failed {"order":{"id":42,"items":3},"user":{"class":"User","id":7,"name":"Jan"}}

```

```
$logger->critical('Unexpected error', ['exception' => $e]); // Exception → class, message, file:line, previous
```

```
[2026-05-02 01:54:00] [CRITICAL] [App/Handler.php:33] Unexpected error {"exception":{"class":"RuntimeException","message":"Connection refused","code":0,"file":"DB/Connection.php:42"}}

```

**Just pass your data — the logger does the rest:**

- 📍 caller location added automatically (`Auth/Service.php:88`)
- 🔒 sensitive fields masked automatically — no extra code needed
- 📁 written to a dated file (`logs/2026/05/2026-05-02.log`) and STDERR at the same time

Need more control? Use the full constructor — but you probably won't need to:

```
use Mariusz\Logger\DualLogger;
use Mariusz\Logger\LogFileManager;
use Psr\Log\LogLevel;

$logger = new DualLogger(
    new LogFileManager('./logs', maxFileSize: 512000, maxFiles: 10),
    minLevel: LogLevel::DEBUG,
);
```

---

Configuration
-------------

[](#configuration)

### LogFileManager

[](#logfilemanager)

```
new LogFileManager(
    logDir:        './logs',      // base log directory
    maxFileSize:   1048576,       // max file size in bytes before rotation (default: 1MB)
    maxFiles:      5,             // max number of rotated archives to keep (default: 5)
    prefix:        'app-',        // filename prefix  → app-2026-05-02.log
    suffix:        '-prod',       // filename suffix  → 2026-05-02-prod.log
    dateStructure: 'Y/m',         // subdirectory pattern (default: year/month)
)
```

#### dateStructure examples

[](#datestructure-examples)

ValuePath`'Y/m'` (default)`logs/2026/05/2026-05-02.log``'Y'``logs/2026/2026-05-02.log``'Y/m/d'``logs/2026/05/02/2026-05-02.log``''``logs/2026-05-02.log` (flat)#### prefix + suffix examples

[](#prefix--suffix-examples)

prefixsuffixfilename`'app-'``''``app-2026-05-02.log``''``'-prod'``2026-05-02-prod.log``'api-'``'-v2'``api-2026-05-02-v2.log`---

### DualLogger

[](#duallogger)

```
new DualLogger(
    fileManager:      new LogFileManager('./logs'),
    minLevel:         LogLevel::WARNING,   // minimum level written to file (default: warning)
    dateFormat:       'Y-m-d H:i:s',      // timestamp format (default: ISO-like)
    timezone:         'Europe/Warsaw',     // timezone (default: system timezone)
    stderrEnabled:    true,               // write to STDERR at all (default: true)
    stderrSkipInTest: true,               // suppress STDERR when APP_ENV=test (default: true)
)
```

#### minLevel examples

[](#minlevel-examples)

minLevelWritten to file`LogLevel::DEBUG`everything`LogLevel::INFO`info and above`LogLevel::WARNING` (default)warning, error, critical, alert, emergency`LogLevel::ERROR`error and above only#### dateFormat examples

[](#dateformat-examples)

dateFormatOutput`'Y-m-d H:i:s'` (default)`2026-05-02 01:54:00``'d.m.Y H:i'``02.05.2026 01:54``'c'``2026-05-02T01:54:00+02:00`#### stderrEnabled / stderrSkipInTest

[](#stderrenabled--stderrskipintest)

stderrEnabledstderrSkipInTestBehaviour`true` (default)`true` (default)STDERR active, suppressed when `APP_ENV=test``true``false`STDERR always active, even in tests`false`*(ignored)*STDERR disabled entirely---

Anonymization
-------------

[](#anonymization)

Sensitive fields in log context are automatically masked — the middle portion is replaced with `****`, keeping ~25% visible at each end so developers can identify values without exposing full data.

```
$logger->warning('Login failed', [
    'email'    => 'jan.kowalski@gmail.com',  // → jan.****@gmail.com
    'token'    => 'supersecret123',           // → supe****t123
    'pesel'    => '12345678901',              // → 123****901
    'password' => 'ab',                       // → ****  (too short)
]);
```

Masked fields: `pesel`, `nip`, `ssn`, `passport`, `email`, `phone`, `telefon`, `password`, `token`, `api_key`, `secret`, `session`, `card`, `iban`, `cvv`, `konto`, `adres`, `street` and more.

---

STDERR suppression in tests
---------------------------

[](#stderr-suppression-in-tests)

By default STDERR is suppressed when `APP_ENV=test`. Set in `phpunit.xml`:

```

```

To disable STDERR entirely (regardless of environment):

```
new DualLogger(stderrEnabled: false);
```

To keep STDERR active even in tests:

```
new DualLogger(stderrSkipInTest: false);
```

---

Laravel
-------

[](#laravel)

Auto-discovered via `extra.laravel.providers`. No manual registration needed.

Publish config:

```
php artisan vendor:publish --tag=fast-php-logger-config
```

`config/php-logger.php`:

```
return [
    'log_dir'    => storage_path('logs'),
    'min_level'  => env('LOG_LEVEL', 'warning'),
    'date_format' => 'Y-m-d H:i:s',
    'timezone'   => env('APP_TIMEZONE', ''),
    'file' => [
        'max_file_size'  => 1048576,
        'max_files'      => 5,
        'prefix'         => '',
        'suffix'         => '',
        'date_structure' => 'Y/m',
    ],
    'stderr' => [
        'enabled'      => env('PHP_LOGGER_STDERR', true),
        'skip_in_test' => true,
    ],
];
```

Resolve from container:

```
$logger = app(\Mariusz\Logger\DualLogger::class);
```

---

Symfony
-------

[](#symfony)

Register the bundle in `config/bundles.php`:

```
return [
    Mariusz\Logger\Symfony\PhpLoggerBundle::class => ['all' => true],
];
```

Optional config in `config/packages/php_logger.yaml`:

```
php_logger:
    log_dir:     '%kernel.logs_dir%'
    min_level:   warning
    date_format: 'Y-m-d H:i:s'
    timezone:    ''
    file:
        max_file_size:  1048576
        max_files:      5
        prefix:         ''
        suffix:         ''
        date_structure: 'Y/m'
    stderr:
        enabled:      true
        skip_in_test: true
```

Inject via autowiring:

```
use Mariusz\Logger\DualLogger;

class MyService
{
    public function __construct(private DualLogger $logger) {}
}
```

---

Testing
-------

[](#testing)

```
composer install
composer test
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance92

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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 ~0 days

Total

2

Last Release

38d ago

### Community

Maintainers

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

---

Top Contributors

[![mafio1969](https://avatars.githubusercontent.com/u/79914309?v=4)](https://github.com/mafio1969 "mafio1969 (12 commits)")

---

Tags

logpsr-3symfonylaravelloggeranonymizationfile-rotation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mafio69-fast-php-logger/health.svg)

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

###  Alternatives

[markrogoyski/simplelog-php

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

2819.1k4](/packages/markrogoyski-simplelog-php)[devthis/console-logg

Effortless artisan console output with your usual Laravel logger

1113.6k](/packages/devthis-console-logg)

PHPackages © 2026

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