solophp / logger
PSR-3 logger with coordinated file rotation and line, JSON or logfmt output
v2.0.0
2026-11-01 13:01 UTC
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13
Suggests
None
Provides
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-01 13:01:55 UTC
README
PSR-3 logger for PHP: coordinated file rotation, standard error for containers, bounded context, and one line per record in line, JSON or logfmt format.
Features
- PSR-3 and PSR-20 — the eight standard levels, a minimum level,
isHandling(), channels, and any PSR-20 clock for deterministic timestamps - Files and Streams — rotation by size, interval or calendar, with retention, safe for many processes appending to one file; standard error for containers and workers
- Three Formats — line, NDJSON and logfmt; every record is one physical line with a fixed shape and microsecond times
- Bounded Context — exceptions, dates, enums and Stringables are converted safely; depth, entries and string length are capped; the keys you name are redacted
- Safe Output — control characters are escaped, invalid UTF-8 is replaced, symlinked log files are refused, file modes can be restricted
- Composable — decorators send records to several destinations, keep output failures away from requests and add shared context
- Fails Loudly — bad configuration throws on construction; a failed write throws
WriteException, and a failed rotation keeps the record
Installation
composer require solophp/logger
Quick Example
use Psr\Log\LogLevel; use Solo\Logger\Formatter\JsonFormatter; use Solo\Logger\Logger; use Solo\Logger\Rotation\RotationOptions; use Solo\Logger\Rotation\Schedule; $logger = Logger::file( path: '/var/log/app/app.log', minLevel: LogLevel::INFO, formatter: new JsonFormatter(), rotation: new RotationOptions(maxBytes: 10 * 1024 * 1024, schedule: Schedule::Daily, maxFiles: 14), ); $logger->info('User {id} signed in', ['id' => 42]); // {"time":"2026-11-01T09:30:00.123456+00:00","level":"info","message":"User 42 signed in","context":{"id":42}} $logger->error('Payment failed', ['order_id' => 1001, 'exception' => $exception]);
Documentation
Upgrading from 1.x? See UPGRADE.md. Changes are listed in CHANGELOG.md.
Development
composer install composer check # PSR-12, PHPStan at max level, PHPUnit composer test-coverage # HTML report in coverage/, needs PCOV or Xdebug
Permission tests need a non-root POSIX user; the multi-process tests need proc_open. CI runs PHP 8.3, 8.4 and 8.5 on Linux, and the tests on Windows.
Requirements
- PHP 8.3+
License
MIT License. See LICENSE for details.