slam / laminas-log-extensions
Slam extensions for laminas/laminas-log
Fund package maintenance!
Slamdunk
paypal.me/filippotessarotto
Installs: 14 358
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: ~8.1.0 || ~8.2.0
- laminas/laminas-log: ^2.16.1
Requires (Dev)
- phpstan/phpstan: ^1.10.1
- phpstan/phpstan-phpunit: ^1.3.7
- phpunit/phpunit: ^10.0.11
- slam/php-cs-fixer-extensions: ^3.4.0
- slam/php-debug-r: ^1.7.0
- slam/phpstan-extensions: ^6
- thecodingmachine/phpstan-strict-rules: ^1
This package is auto-updated.
Last update: 2023-10-19 08:59:49 UTC
README
Extensions for Laminas\Log
Installation
Execute:
composer require slam/laminas-log-extensions
Usage
The main functionality of this package is the RotateStream writer. PHP cannot handle files larger than 2 GB, so if you log a lot you can end up losing some if you reach this limit.
Slam\Laminas\Log\Writer\RotateStream
rotates the write when it reaches ~1.5 GB.
use Slam\Laminas\Log\Writer\RotateStream; use Laminas\Log\Formatter\Simple; use Laminas\Log\Logger; $writer = new RotateStream(__DIR__ . '/log.txt'); $writer->setFormatter(new Simple()); // Do the check everytime, defaults to once every 100000 log entries $writer->setCheckProbability(1); // 10 bytes max file size, defaults to ~1.5 GB $writer->setMaxFileSize(10); $logger = new Logger(); $logger->addWriter($writer); for ($i = 0; $i < 10; ++$i) { $logger->info($i); sleep(1); }
This is what you'll find in the directory:
$ ls log.txt*
log.txt log.txt.1 log.txt.2 log.txt.3 log.txt.4 log.txt.5 log.txt.6 log.txt.7 log.txt.8 log.txt.9
$ cat log.txt.9
2017-09-05T11:08:46+02:00 INFO (6): 8
2017-09-05T11:08:47+02:00 NOTICE (5): LOG ROTATE
$ cat log.txt
2017-09-05T11:08:47+02:00 INFO (6): 9