Skip to content

Commit

Permalink
Merge pull request #18 from cesargb/v2
Browse files Browse the repository at this point in the history
v2
  • Loading branch information
cesargb authored Dec 24, 2021
2 parents 8713555 + ae9f981 commit c22522b
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 298 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ jobs:
fail-fast: false
matrix:
php: [7.4, 8.0]
laravel: [8.*, 7.*, 6.*]
laravel: [8.*, 6.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*

Expand All @@ -43,5 +41,6 @@ jobs:
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
35 changes: 9 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Rotate Laravel logs files and compress

![tests](https://github.com/cesargb/laravel-logs-rotate/workflows/tests/badge.svg)
[![StyleCI](https://styleci.io/repos/119604039/shield?branch=master)](https://styleci.io/repos/119604039)
[![Latest Stable Version](https://img.shields.io/packagist/v/cesargb/laravel-logs-rotate.svg)](https://packagist.org/packages/cesargb/laravel-logs-rotate)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cesargb/laravel-logs-rotate/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/cesargb/laravel-logs-rotate/?branch=master)

# Rotate Laravel logs files and compress

This package allows you to rotate the Laravel record file with compression. This method is useful if you use logger channel `single` (StreamHandler)

## Installation
Expand All @@ -30,6 +30,7 @@ You can publish config file with:
```bash
php artisan vendor:publish --provider="Cesargb\File\Rotate\RotateServiceProvider" --tag=config
```

This is the contents of the published config/rotate.php config file:

```php
Expand All @@ -46,17 +47,6 @@ return [
*/
'log_compress_files' => true,

/*
|--------------------------------------------------------------------------
| Archive Dir
|--------------------------------------------------------------------------
|
| This value determines the folder where the files are saved.
| Leave null to archive in the same folder of your logs.
|
*/
'archive_dir' => null,

/*
|--------------------------------------------------------------------------
| Schedule Rotate
Expand Down Expand Up @@ -90,12 +80,12 @@ return [
| Array the other foreing files
|
| Example:
| 'foreing_files' => [
| 'foreign_files' => [
storage_path('/logs/worker.log')
| ]
|
*/
'foreing_files' => []
'foreign_files' => []
];
```

Expand Down Expand Up @@ -133,17 +123,6 @@ It has two public properties:
* fileSource: the full path of file to rotate
* fileRotated: the full path of file rotated

### RotateIsNotNecessary

`Cesargb\File\Rotate\Events\RotateIsNotNecessary`

If file log does not exist or is empty this event will be fired.

It has two public properties:

* fileSource: the full path of file to rotate
* message: Descriptive message of the reason

### RotateHasFailed

`Cesargb\File\Rotate\Handlers\RotativeHandler`
Expand All @@ -167,6 +146,10 @@ Run test with:
composer test
```

## Upgrading

Please see [UPGRADING](UPGRADING.md) for details.

## Knowledge Issues

* [#8](https://github.com/cesargb/laravel-logs-rotate/issues/8) While the file is being rotated, any record of another process may be lost.
Expand Down
9 changes: 9 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Upgrading

Because there are many breaking changes an upgrade is not that easy. There are many edge cases this guide does not cover. We accept PRs to improve this guide.

## From [v1](https://github.com/cesargb/laravel-logs-rotate/tree/v1) to v2

- rename config params from `foreing_files` to `foreign_files`, if you have a config file with the old name, rename it to `config/rotate.php`
- remove feat archive.
- remove config params `archive_dir`
23 changes: 12 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@
],
"license": "MIT",
"require": {
"php" : "^7.2 | ^8.0",
"illuminate/config": "^6.10|^7.0|^8.0",
"illuminate/console": "^6.10|^7.0|^8.0",
"illuminate/log": "^6.10|^7.0|^8.0",
"illuminate/support": "^6.10|^7.0|^8.0",
"monolog/monolog": "^2.0"
"php" : "^7.4 | ^8.0",
"illuminate/config": "^6.20|^8.0",
"illuminate/console": "^6.20|^8.0",
"illuminate/log": "^6.20|^8.0",
"illuminate/support": "^6.20|^8.0",
"monolog/monolog": "^2.0",
"cesargb/php-log-rotation": "^2.3"
},
"require-dev": {
"orchestra/testbench": "^4.10|^5.0|^6.0",
"phpunit/phpunit": "^7.0|^8.0|^9.0"
"orchestra/testbench": "^4.18|^6.20",
"phpunit/phpunit": "^9.4"
},
"autoload": {
"psr-4": {
"Cesargb\\File\\Rotate\\": "src"
"Cesargb\\LaravelLog\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Cesargb\\File\\Rotate\\Test\\": "tests"
"Cesargb\\LaravelLog\\Test\\": "tests"
}
},
"scripts": {
Expand All @@ -45,7 +46,7 @@
"extra": {
"laravel": {
"providers": [
"Cesargb\\File\\Rotate\\RotateServiceProvider"
"Cesargb\\LaravelLog\\RotateServiceProvider"
]
}
}
Expand Down
19 changes: 4 additions & 15 deletions config/rotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
*/
'log_compress_files' => true,

/*
|--------------------------------------------------------------------------
| Archive Dir
|--------------------------------------------------------------------------
|
| This value determines the folder where the files are saved.
| Leave null to archive in the same folder of your logs.
|
*/
'archive_dir' => null,

/*
|--------------------------------------------------------------------------
| Schedule Rotate
Expand All @@ -33,8 +22,8 @@
|
*/
'schedule' => [
'enable' => true,
'cron' => '0 0 * * *',
'enable' => true,
'cron' => '0 0 * * *',
],

/*
Expand All @@ -55,10 +44,10 @@
| Array the other foreing files
|
| Example:
| 'foreing_files' => [
| 'foreign_files' => [
storage_path('/logs/worker.log')
| ]
|
*/
'foreing_files' => [],
'foreign_files' => [],
];
55 changes: 0 additions & 55 deletions src/Commands/Rotate.php

This file was deleted.

46 changes: 46 additions & 0 deletions src/Commands/RotateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Cesargb\LaravelLog\Commands;

use Cesargb\LaravelLog\Helpers\Log as LogHelper;
use Cesargb\LaravelLog\Rotate as LaravelLogRotate;
use Illuminate\Console\Command;

class RotateCommand extends Command
{
protected $signature = 'rotate:logs';

protected $description = 'Rotate logs of Laravel';

public function handle()
{
$this->rotateLaravelLogs();

$this->rotareForeingFiles();
}

protected function rotateLaravelLogs()
{
foreach (LogHelper::getLaravelLogFiles() as $file) {
$this->line('Rotate file: '.$file);

$this->rotateFile($file);
}
}

protected function rotareForeingFiles()
{
foreach (config('rotate.foreign_files', []) as $file) {
$this->line('Rotate file: '.$file);

$this->rotateFile($file);
}
}

protected function rotateFile(string $filename)
{
$rotation = new LaravelLogRotate();

$rotation->file($filename);
}
}
37 changes: 0 additions & 37 deletions src/Commands/RotateFile.php

This file was deleted.

37 changes: 37 additions & 0 deletions src/Commands/RotateFileCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Cesargb\LaravelLog\Commands;

use Cesargb\LaravelLog\Rotate;
use Illuminate\Console\Command;

class RotateFileCommand extends Command
{
protected $signature = 'rotate:files
{--f|file=* : Files to rotate}
{--c|compress=true : Compress the file rotated}
{--m|max-files=5 : Max files rotated}
{--d|dir= : Dir where archive the file rotated}';

protected $description = 'Rotate files';

public function handle()
{
foreach ($this->option('file') as $filename) {
$this->line('Rotate file '.basename($filename).': ');

$rotate = new Rotate();

$rotate->file($filename, [
'files' => config('rotate.log_max_files', 366),
'compress' => config('rotate.log_compress_files', true),
// 'then' => function () {
// $this->line('<info>ok</>');
// },
// 'catch' => function ($error) {
// $this->error('<comment>failed: '.$error->getMessage().'</>');
// },
]);
}
}
}
Loading

0 comments on commit c22522b

Please sign in to comment.