定制 cesargb/php-log-rotation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cesargb/php-log-rotation

最新稳定版本:2.7.1

Composer 安装命令:

composer require cesargb/php-log-rotation

包简介

PHP Class to rotate log files

README 文档

README

This PHP package allows you to rotate a log file and compress it.

tests phpstan Latest Version on Packagist Total Downloads

Installation

You can install this package via composer using:

composer require cesargb/php-log-rotation

Usage

use Cesargb\Log\Rotation;
use Cesargb\Log\Exceptions\RotationFailed;

$rotation = new Rotation();

$rotation
    ->compress() // Optional, compress the file after rotated. Accept level compression argument.
    ->files(30) // Optional, files are rotated 30 times before being removed. Default 366
    ->minSize(1024) // Optional, are rotated when they grow bigger than 1024 bytes. Default 0
    ->truncate() // Optional, truncate the original log file in place after creating a copy, instead of moving the old log file.
    ->then(function ($filenameTarget, $filenameRotated) {}) // Optional, to get filename target and original filename
    ->catch(function (RotationFailed $exception) {}) // Optional, to catch a exception in rotating
    ->finally(function ($message, $filenameTarget) {}) // Optional, this method will be called when the process has finished
    ->rotate('file.log');

Or you can define the options in the constructor

use Cesargb\Log\Rotation;
use Cesargb\Log\Exceptions\RotationFailed;

$rotation = new Rotation([
    'files' => 1,
    'compress' => true, // Set level compression or true to default level. Default false
    'min-size' => 10,
    'truncate' => false,
    'then' => function ($filename) {},
    'catch' => function (RotationFailed $exception) {},
    'finally' => function ($message, $filename) {},
]);

$rotation->rotate('file.log');

Example: Using with crontab

To automatically rotate your logs every day at 12:01 AM, add the following line to your crontab:

1 0 * * * /usr/bin/php /path/to/your/log-rotation-script.php

Test

Run test with:

composer test

Contributing

Any contributions are welcome.

统计信息

  • 总下载量: 260.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-15