mathiasgrimm / laravel-log-keeper
此包的最新版本(v1.0.6)没有可用的许可信息。
Laravel Log Keeper 帮助您在任意位置存储日志的同时,通过自定义本地/远程保留策略进行日志轮转。
v1.0.6
2016-03-24 16:05 UTC
README
Laravel Log Keeper 帮助您在任意位置存储日志的同时,通过自定义本地/远程保留策略进行日志轮转。
Laravel Log Keeper 的典型用法是设置一个每日运行的cron作业,将本地日志存储在S3桶、(s)ftp、Dropbox或任何其他FileSystem驱动器中。
您可以定义本地和/或远程保留策略,默认为7天和30天。
- 超过7天的本地文件将使用bzip2进行压缩并上传到远程磁盘。
- 超过30天的远程文件将永久从远程磁盘删除。
亮点
- 完全控制您存储日志的位置、时间和方式
- 防止服务器空间不足
- 本地和远程存档的自定义保留策略
安装
Laravel Log Keeper 通过Composer提供。
{ "require": { "mathiasgrimm/laravel-log-keeper": "1.*" } }
设置
Laravel
注册服务提供者
// config/app.php 'providers' => [ ... MathiasGrimm\LaravelLogKeeper\Providers\LaravelServiceProvider::class, ... ],
注册cron作业
// app/Console/Kernel.php protected $commands = [ ... \MathiasGrimm\LaravelLogKeeper\Commands\LogKeeper::class ... ]; ... protected function schedule(Schedule $schedule) { ... $schedule->command('laravel-log-keeper')->daily(); ... }
日志格式
要使用Laravel Log Keeper,您的日志文件必须采用每日格式,该格式在您的 config/app.php
中定义。
... 'log' => 'daily', ...
环境
您可以通过在 .env 中放置以下变量来覆盖以下变量。
示例
# .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"
...
// laravel-log-keeper.php // ---------------------------------------------------------------------------- // 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 // ---------------------------------------------------------------------------- 'localRetentionDays' => env('LARAVEL_LOG_KEEPER_LOCAL_RETENTION_DAYS', 7), // ---------------------------------------------------------------------------- // How many days a file will be kept on the remote for. // The days here means days after the local retention. So 30 would actually // 30 + 7 = 37 // Only files older than 37 days would be deleted from the remote disk // ---------------------------------------------------------------------------- 'remoteRetentionDays' => env('LARAVEL_LOG_KEEPER_REMOTE_RETENTION_DAYS', 30), 'remoteRetentionDaysCalculated' => env('LARAVEL_LOG_KEEPER_REMOTE_RETENTION_DAYS', 30) + env('LARAVEL_LOG_KEEPER_LOCAL_RETENTION_DAYS', 7), // ---------------------------------------------------------------------------- // 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) ];
安全性
如果您发现任何与安全相关的问题,请通过电子邮件 mathiasgrimm@gmail.com 联系,而不是使用问题跟踪器。