承接 accentinteractive/laravel-logcleaner 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

accentinteractive/laravel-logcleaner

Composer 安装命令:

composer require accentinteractive/laravel-logcleaner

包简介

Keep your laravel logs small and tidy.

README 文档

README

Latest Version on Packagist Build Status Quality Score Total Downloads

Logs can get quite out of hand. This package helps save server space and keep your Laravel log files small.

  1. Trim your daily log to a given number of lines do it does not grow huge.
  2. Delete old daily logs, only keeping a given number of the latest log files.
  • Laravel 12 support as of 1.6.0.

  • Laravel 11 support as of 1.3.0.

  • Laravel 10 support as of 1.2.0.

  • Laravel 9 support as of 1.1.0.

  • Versions before that support Laravel 6, 7, 8.

  • Installation

  • Examples

  • Config settings

Installation

You can install the package via composer:

composer require accentinteractive/laravel-logcleaner

Optionally you can publish the config file with:

php artisan vendor:publish --provider="Accentinteractive\LaravelLogcleaner\LaravelLogcleanerServiceProvider" --tag="config"

Usage

You can use logcleaner:run from the command line or set it as a cron job.

Command line usage;

// Get info about the command and options
php artisan logcleaner:run --help

// Trim big log files and delete old log files
php artisan logcleaner:run

// Pass the number of lines to keep when trimming log files. Overrides the config setting.
// This overrides the default set in config
php artisan logcleaner:run --keeplines=10000

// Pass the number of files to keep when deleting old log files. Overrides the config setting.
// This overrides the default set in config
php artisan logcleaner:run --keepfiles=7

// Run without actually cleaning any logs
php artisan logcleaner:run --dry-run

Cron job usage, add this to App\Console\Kernel:

protected function schedule(Schedule $schedule)
{
    $schedule->command('logcleaner:run')->daily()->at('01:00');
}

Of course, you can also pass options when defining a cron job.

protected function schedule(Schedule $schedule)
{
    $schedule->command('logcleaner:run', ['--keeplines' => 5000, '--keepfiles' => 14])->daily()->at('01:00');
}

Subfolder handling

From version 1.4.0, files in subfolders are processed as well.

  • Trimming: all files in subfolder are trimmed.
  • Deleting: in each subfolder, all files except the N most recent ones are deleted. Where N equals config(logcleaner.log_files_to_keep).
  • Handling of subfolders is set to true by default, but can be overridden by env('LOGCLEANER_PROCESS_SUBFOLDERS')

ENV variables

You can set the following ENV variables in your .env file:

  • LOGCLEANER_LOG_PATH : The path to your logfile, relative from the root path of your application. If you do not supply LOGCLEANER_LOG_PATH, the default Laravel log path will be used. Example value: storage/custom_logs.
  • LOGCLEANER_TRIMMING_ENABLED : Whether to trim log files to a certain number of lines or not. Defaults to true if not set in .env.
  • LOGCLEANER_LOG_LINES_TO_KEEP : The number of lines to keep when trimming files. Defaults to 20000 if not set in .env.
  • LOGCLEANER_DELETING_ENABLED : Whether to delete older log files or not. Defaults to true if not set in .env.
  • LOGCLEANER_LOG_FILES_TO_KEEP : The number of files to keep when deleting older log files. Defaults to 30 if not set in .env.
  • LOGCLEANER_PROCESS_SUBFOLDERS : Whether or not to process files in subfolders from the log path. Defaults to true if not set in .env.

Config settings

You can pass config settings to modify the behaviour.

  • logcleaner.log_files_to_keep : the number of log files to keep when deleting old log files. This config setting is overridden by option --keepfiles
  • logcleaner.log_lines_to_keep : the number of lines to leave intact when trimming log files. This config setting is overridden by option --keeplines
  • logcleaner.exclude : an array of filenames to exclude from processing, using wildcards.
  • logcleaner.trimming_enabled : enables log file trimming. true by default.
  • logcleaner.deleting_enabled : enables old log file deletions. true by default.
  • logcleaner.process_subfolders : whether to include files in subfolders. true by default.

You can also pass options directly.

  • --keeplines=2000
  • --keepfiles=7
  • --dry-run

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email joost@accentinteractive.nl instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

accentinteractive/laravel-logcleaner 适用场景与选型建议

accentinteractive/laravel-logcleaner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 283.18k 次下载、GitHub Stars 达 82, 最近一次更新时间为 2021 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「accentinteractive」 「laravel-logcleaner」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 accentinteractive/laravel-logcleaner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 accentinteractive/laravel-logcleaner 我们能提供哪些服务?
定制开发 / 二次开发

基于 accentinteractive/laravel-logcleaner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 283.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 82
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 82
  • Watchers: 4
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-04