mafio69/fast-php-logger
Larablocks Analysis
mafio69/fast-php-logger works with any PHP project: the latest release (v1.1.0, Oct 25, 2026) doesn't depend on Laravel.
Recommendation checks
PromisingPromising: maintained and up to date, meets 1 of 3 checks; not yet widely used.
- Released in the last 12 months (Oct 25, 2026)
- 121 downloads a month (needs 10,000)
- 1 GitHub star (needs 100)
State
Actively maintained- Last stable release: Oct 25, 2026.
- 4 releases in the last 12 months.
- First released: May 2, 2026.
- Monthly downloads: 121.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Dec 4, 2026.
| Install | |
|---|---|
composer require mafio69/fast-php-logger |
|
| Latest Version: | v1.1.0 |
| PHP: | >=8.1 |
| License: | MIT |
| Last Updated: | Oct 25, 2026 |
| Links: | GitHub · Packagist |
mafio69/fast-php-logger
PSR-3 compliant dual logger for PHP 8.1+ with:
- Simultaneous dual logging (Console/STDERR + date-structured files)
- Date-based log file structure with configurable subdirectory pattern
- Automatic log rotation by file size with retention history
- Concurrency-safe file writes (
LOCK_EX) - Caller location in every log entry (
directory/file.php:line) - Automatic anonymization of sensitive fields (passwords, tokens, PESEL, cards)
- Safe serialization of objects, exceptions, and nested context data
- Configurable minimum log level for file output
- Configurable date format and timezone
- Out-of-the-box framework support: Laravel (auto-discovery) and Symfony (Bundle)
- Standalone zero-dependency single-file option available
Installation
composer require mafio69/fast-php-logger
Without Composer
No Composer? No problem. A pre-built single file is available on every GitHub Release. 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)
require_once 'fast-php-logger.php';
use Mariusz\Logger\DualLogger;
use Mariusz\Logger\Dto\LoggerConfigDto;
use Mariusz\Logger\LogFileManager;
use Psr\Log\LogLevel;
$logger = new DualLogger(
fileManager: 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/
),
config: new LoggerConfigDto(
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
$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\Dto\LoggerConfigDto;
use Mariusz\Logger\LogFileManager;
use Psr\Log\LogLevel;
$logger = new DualLogger(
fileManager: new LogFileManager('./logs', maxFileSize: 512000, maxFiles: 10),
config: new LoggerConfigDto(minLevel: LogLevel::DEBUG),
);
Configuration
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
| Value | Path |
|---|---|
'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 | filename |
|---|---|---|
'app-' |
'' |
app-2026-05-02.log |
'' |
'-prod' |
2026-05-02-prod.log |
'api-' |
'-v2' |
api-2026-05-02-v2.log |
DualLogger
new DualLogger(
fileManager: new LogFileManager('./logs'),
config: new LoggerConfigDto(
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 | Written 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 | Output |
|---|---|
'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 | Behaviour |
|---|---|---|
true (default) |
true (default) |
STDERR active, suppressed when APP_ENV=test |
true |
false |
STDERR always active, even in tests |
false |
(ignored) | STDERR disabled entirely |
LoggerConfigDto
DTO grouping all logger configuration parameters (except fileManager).
use Mariusz\Logger\Dto\LoggerConfigDto;
use Psr\Log\LogLevel;
$config = new LoggerConfigDto(
minLevel: LogLevel::WARNING, // minimum level written to file
dateFormat: 'Y-m-d H:i:s', // timestamp format
timezone: 'Europe/Warsaw', // timezone (empty = system default)
stderrEnabled: true, // write to STDERR
stderrSkipInTest: true, // suppress STDERR when APP_ENV=test
);
All parameters have default values, so you only need to pass the ones you want to change:
$config = new LoggerConfigDto(minLevel: LogLevel::DEBUG);
Accessing the configuration
$logger = new DualLogger(fileManager: $fm, config: $config);
// Get config
$cfg = $logger->getConfig();
echo $cfg->minLevel; // 'debug'
echo $cfg->dateFormat; // 'Y-m-d H:i:s'
echo $cfg->timezone; // '' (empty string = system default)
echo $cfg->stderrEnabled; // true
echo $cfg->stderrSkipInTest; // true
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
By default STDERR is suppressed when APP_ENV=test. Set in phpunit.xml:
<php>
<env name="APP_ENV" value="test" force="true"/>
</php>
To disable STDERR entirely (regardless of environment):
use Mariusz\Logger\Dto\LoggerConfigDto;
new DualLogger(config: new LoggerConfigDto(stderrEnabled: false));
To keep STDERR active even in tests:
use Mariusz\Logger\Dto\LoggerConfigDto;
new DualLogger(config: new LoggerConfigDto(stderrSkipInTest: false));
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('FAST_PHP_LOGGER_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
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) {}
}
Grafana & Loki Integration
Fast-php-logger entries have a predictable structure:
[<timestamp>] [<level>] [<caller>] <message> {<context_json>}
Parsing logs in Grafana Loki (LogQL)
You can easily query and filter logs in Grafana using the pattern parser:
{app="backend"} | pattern "[<timestamp>] [<level>] [<caller>] <message> <context>"
To automatically extract properties from the JSON context as queryable fields:
{app="backend"} | pattern "[<timestamp>] [<level>] [<caller>] <message> <context>" | json context
Now you can filter directly by context fields (e.g. order_id="42" or user_id="7") and build dashboards or alerting rules.
Testing & Code Quality
composer install
# Run PHPUnit test suite (66 tests)
composer test
# Run static analysis (PHPStan) and code style check (PHP-CS-Fixer)
composer run check:all
# Automatically fix code style according to PSR-12
composer run cs:fix
Alternatives to mafio69/fast-php-logger
Laravel package to report exceptions to a Telegram chat, group or channel.
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| v1.1.0 | >=8.1 | MIT | |
| v1.0.1 | >=8.1 | MIT | |
| v1.0.0 | >=8.1 | MIT | |
| v0.9.1 | >=8.1 | MIT |