lifeonscreen/laravel-log-keeper
Composer 安装命令:
composer require lifeonscreen/laravel-log-keeper
包简介
Laravel Log Keeper helps rotating you logs while storing them anywhere you want with custom local/remote retention policies
README 文档
README
Laravel Log Keeper helps rotating your logs while storing them anywhere you want with custom local/remote retention policies.
A typical usage of Laravel Log Keeper would be to set a cron job to run daily and store local logs in a S3 bucket, (s)ftp, Dropbox or any other FileSystem driver
You can define a local and/or a remote retention and/or upload after remote days, which by default is 7, 30 and 1 day subsequently.
- Files older than 1 day will be compressed and uploaded to remote disk.
- Local files older than 7 days removed from local disk.
- Remote files older than 31 (remote days+upload after days) days will be permanently deleted from the remote disk.
Highlights
- Have full control of where/when/how you archive your logs
- Prevent your server from running out of space
- Custom retention policies for Local and Remote archiving
Installation
Laravel Log Keeper is available via Composer:
{
"require": {
"lifeonscreen/laravel-log-keeper": "1.*"
}
}
Setup
Laravel
Register Service Provider
// config/app.php 'providers' => [ ... LifeOnScreen\LaravelLogKeeper\Providers\LaravelServiceProvider::class, ... ],
Register the cron job
// app/Console/Kernel.php protected $commands = [ ... \LifeOnScreen\LaravelLogKeeper\Commands\LogKeeper::class ... ]; ... protected function schedule(Schedule $schedule) { ... $schedule->command('laravel-log-keeper')->daily(); ... }
Log Format
To use Laravel Log Keeper your log files have to be in the daily format, which is defined in your config/app.php
... 'log' => 'daily', ...
Environment
You can override the following variables placing them in your .env
Example:
# .env
...
LARAVEL_LOG_KEEPER_REMOTE_DISK = "s3"
LARAVEL_LOG_KEEPER_LOCAL_RETENTION_DAYS = 3
LARAVEL_LOG_KEEPER_REMOTE_RETENTION_DAYS = 15
LARAVEL_LOG_KEEPER_REMOTE_PATH = "myproject1-prod-01"
...
Can publish config with this command:
php artisan vendor:publish --provider=LifeOnScreen\LaravelLogKeeper\Providers\LaravelServiceProvider
Config file:
// ---------------------------------------------------------------------------- // Enable or Disable the Laravel Log Keeper. // If it is set to false, no operations will be performed and it will be logged // if the logs are enabled // ---------------------------------------------------------------------------- 'enabled' => env('LARAVEL_LOG_KEEPER_ENABLED', true), // ---------------------------------------------------------------------------- // Enable or Disable the Laravel Log Keeper for remote operations. // if it is set to false, the local files older than the local retention will be // delete without being uploaded to the remote disk // ---------------------------------------------------------------------------- 'enabled_remote' => env('LARAVEL_LOG_KEEPER_ENABLED_REMOTE', true), // ---------------------------------------------------------------------------- // Where in the remote location it will be stored. You can leave it blank // or specify a custom folder like proj1-prod or proj1-integ so that you could // use the same s3 bucket for storing the logs in different environments // ---------------------------------------------------------------------------- 'remote_path' => rtrim(env('LARAVEL_LOG_KEEPER_REMOTE_PATH'), '/'), // ---------------------------------------------------------------------------- // How many days a file will be kept on the local disk before // being uploaded to the remote disk. // Default is 7 days. // Local files with more than 7 days will be compressed using bzip2 and uploaded // to the remote disk. They will also be deleted from the local disk after being // uploaded // If value is set to 0 logs will be kept forever. // ---------------------------------------------------------------------------- 'local_retention_days' => env('LARAVEL_LOG_KEEPER_LOCAL_RETENTION_DAYS', 7), // ---------------------------------------------------------------------------- // When file be uploaded to remote location. // Default is 1 day. // ---------------------------------------------------------------------------- 'upload_to_remote_after_days' => env('LARAVEL_LOG_KEEPER_UPLOAD_TO_REMOTE_DAYS', 1), // ---------------------------------------------------------------------------- // How many days a file will be kept on the remote for. // The days here means days after the upload on server. So 30 would actually // 30 + 1 = 31 // Only files older than 31 days would be deleted from the remote disk // If value is set to 0 logs will be kept forever. // ---------------------------------------------------------------------------- 'remote_retention_days' => env('LARAVEL_LOG_KEEPER_REMOTE_RETENTION_DAYS', 30), 'remote_retention_days_calculated' => env('LARAVEL_LOG_KEEPER_REMOTE_RETENTION_DAYS', 30) + env('LARAVEL_LOG_KEEPER_UPLOAD_TO_REMOTE_DAYS', 1), // ---------------------------------------------------------------------------- // Which config/filesystems.php disk will be used for remote disk. // This would be typically a AWS S3 Disk, (s)ftp, Dropbox or any other configured // disk that will store the old logs // ---------------------------------------------------------------------------- 'remote_disk' => env('LARAVEL_LOG_KEEPER_REMOTE_DISK'), // ---------------------------------------------------------------------------- // Define whether Laravel Log Keeper will log actions or not. // The log will be stored in the logs folders with name // laravel-log-keeper-{yyyy-mm-dd}.log // ---------------------------------------------------------------------------- 'log' => env('LARAVEL_LOG_KEEPER_LOG', true)
Security
If you discover any security related issues, please constant us directly.
Credits
lifeonscreen/laravel-log-keeper 适用场景与选型建议
lifeonscreen/laravel-log-keeper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.92k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「s3」 「remote」 「sftp」 「ftp」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lifeonscreen/laravel-log-keeper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lifeonscreen/laravel-log-keeper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lifeonscreen/laravel-log-keeper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Allow packages to be installed from a repository or tarball bundle that have multiple packages in the sub-folders
PHP library that allows linking queries from diferent physical databases using mysql pdo database connections
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
A simple database backup manager for Symfony2 with support for S3, Rackspace, Dropbox, FTP, SFTP.
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
统计信息
- 总下载量: 2.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-06-21