Skip to content

Commit c22522b

Browse files
authored
Merge pull request #18 from cesargb/v2
v2
2 parents 8713555 + ae9f981 commit c22522b

23 files changed

+245
-298
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
php: [7.4, 8.0]
16-
laravel: [8.*, 7.*, 6.*]
16+
laravel: [8.*, 6.*]
1717
dependency-version: [prefer-lowest, prefer-stable]
1818
include:
1919
- laravel: 8.*
2020
testbench: 6.*
21-
- laravel: 7.*
22-
testbench: 5.*
2321
- laravel: 6.*
2422
testbench: 4.*
2523

@@ -43,5 +41,6 @@ jobs:
4341
run: |
4442
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
4543
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
44+
4645
- name: Execute tests
4746
run: vendor/bin/phpunit

README.md

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
# Rotate Laravel logs files and compress
2+
13
![tests](https://github.com/cesargb/laravel-logs-rotate/workflows/tests/badge.svg)
24
[![StyleCI](https://styleci.io/repos/119604039/shield?branch=master)](https://styleci.io/repos/119604039)
35
[![Latest Stable Version](https://img.shields.io/packagist/v/cesargb/laravel-logs-rotate.svg)](https://packagist.org/packages/cesargb/laravel-logs-rotate)
46
[![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)
57

6-
# Rotate Laravel logs files and compress
7-
88
This package allows you to rotate the Laravel record file with compression. This method is useful if you use logger channel `single` (StreamHandler)
99

1010
## Installation
@@ -30,6 +30,7 @@ You can publish config file with:
3030
```bash
3131
php artisan vendor:publish --provider="Cesargb\File\Rotate\RotateServiceProvider" --tag=config
3232
```
33+
3334
This is the contents of the published config/rotate.php config file:
3435

3536
```php
@@ -46,17 +47,6 @@ return [
4647
*/
4748
'log_compress_files' => true,
4849

49-
/*
50-
|--------------------------------------------------------------------------
51-
| Archive Dir
52-
|--------------------------------------------------------------------------
53-
|
54-
| This value determines the folder where the files are saved.
55-
| Leave null to archive in the same folder of your logs.
56-
|
57-
*/
58-
'archive_dir' => null,
59-
6050
/*
6151
|--------------------------------------------------------------------------
6252
| Schedule Rotate
@@ -90,12 +80,12 @@ return [
9080
| Array the other foreing files
9181
|
9282
| Example:
93-
| 'foreing_files' => [
83+
| 'foreign_files' => [
9484
storage_path('/logs/worker.log')
9585
| ]
9686
|
9787
*/
98-
'foreing_files' => []
88+
'foreign_files' => []
9989
];
10090
```
10191

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

136-
### RotateIsNotNecessary
137-
138-
`Cesargb\File\Rotate\Events\RotateIsNotNecessary`
139-
140-
If file log does not exist or is empty this event will be fired.
141-
142-
It has two public properties:
143-
144-
* fileSource: the full path of file to rotate
145-
* message: Descriptive message of the reason
146-
147126
### RotateHasFailed
148127

149128
`Cesargb\File\Rotate\Handlers\RotativeHandler`
@@ -167,6 +146,10 @@ Run test with:
167146
composer test
168147
```
169148

149+
## Upgrading
150+
151+
Please see [UPGRADING](UPGRADING.md) for details.
152+
170153
## Knowledge Issues
171154

172155
* [#8](https://github.com/cesargb/laravel-logs-rotate/issues/8) While the file is being rotated, any record of another process may be lost.

UPGRADING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Upgrading
2+
3+
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.
4+
5+
## From [v1](https://github.com/cesargb/laravel-logs-rotate/tree/v1) to v2
6+
7+
- 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`
8+
- remove feat archive.
9+
- remove config params `archive_dir`

composer.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@
1818
],
1919
"license": "MIT",
2020
"require": {
21-
"php" : "^7.2 | ^8.0",
22-
"illuminate/config": "^6.10|^7.0|^8.0",
23-
"illuminate/console": "^6.10|^7.0|^8.0",
24-
"illuminate/log": "^6.10|^7.0|^8.0",
25-
"illuminate/support": "^6.10|^7.0|^8.0",
26-
"monolog/monolog": "^2.0"
21+
"php" : "^7.4 | ^8.0",
22+
"illuminate/config": "^6.20|^8.0",
23+
"illuminate/console": "^6.20|^8.0",
24+
"illuminate/log": "^6.20|^8.0",
25+
"illuminate/support": "^6.20|^8.0",
26+
"monolog/monolog": "^2.0",
27+
"cesargb/php-log-rotation": "^2.3"
2728
},
2829
"require-dev": {
29-
"orchestra/testbench": "^4.10|^5.0|^6.0",
30-
"phpunit/phpunit": "^7.0|^8.0|^9.0"
30+
"orchestra/testbench": "^4.18|^6.20",
31+
"phpunit/phpunit": "^9.4"
3132
},
3233
"autoload": {
3334
"psr-4": {
34-
"Cesargb\\File\\Rotate\\": "src"
35+
"Cesargb\\LaravelLog\\": "src"
3536
}
3637
},
3738
"autoload-dev": {
3839
"psr-4": {
39-
"Cesargb\\File\\Rotate\\Test\\": "tests"
40+
"Cesargb\\LaravelLog\\Test\\": "tests"
4041
}
4142
},
4243
"scripts": {
@@ -45,7 +46,7 @@
4546
"extra": {
4647
"laravel": {
4748
"providers": [
48-
"Cesargb\\File\\Rotate\\RotateServiceProvider"
49+
"Cesargb\\LaravelLog\\RotateServiceProvider"
4950
]
5051
}
5152
}

config/rotate.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111
*/
1212
'log_compress_files' => true,
1313

14-
/*
15-
|--------------------------------------------------------------------------
16-
| Archive Dir
17-
|--------------------------------------------------------------------------
18-
|
19-
| This value determines the folder where the files are saved.
20-
| Leave null to archive in the same folder of your logs.
21-
|
22-
*/
23-
'archive_dir' => null,
24-
2514
/*
2615
|--------------------------------------------------------------------------
2716
| Schedule Rotate
@@ -33,8 +22,8 @@
3322
|
3423
*/
3524
'schedule' => [
36-
'enable' => true,
37-
'cron' => '0 0 * * *',
25+
'enable' => true,
26+
'cron' => '0 0 * * *',
3827
],
3928

4029
/*
@@ -55,10 +44,10 @@
5544
| Array the other foreing files
5645
|
5746
| Example:
58-
| 'foreing_files' => [
47+
| 'foreign_files' => [
5948
storage_path('/logs/worker.log')
6049
| ]
6150
|
6251
*/
63-
'foreing_files' => [],
52+
'foreign_files' => [],
6453
];

src/Commands/Rotate.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/Commands/RotateCommand.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Cesargb\LaravelLog\Commands;
4+
5+
use Cesargb\LaravelLog\Helpers\Log as LogHelper;
6+
use Cesargb\LaravelLog\Rotate as LaravelLogRotate;
7+
use Illuminate\Console\Command;
8+
9+
class RotateCommand extends Command
10+
{
11+
protected $signature = 'rotate:logs';
12+
13+
protected $description = 'Rotate logs of Laravel';
14+
15+
public function handle()
16+
{
17+
$this->rotateLaravelLogs();
18+
19+
$this->rotareForeingFiles();
20+
}
21+
22+
protected function rotateLaravelLogs()
23+
{
24+
foreach (LogHelper::getLaravelLogFiles() as $file) {
25+
$this->line('Rotate file: '.$file);
26+
27+
$this->rotateFile($file);
28+
}
29+
}
30+
31+
protected function rotareForeingFiles()
32+
{
33+
foreach (config('rotate.foreign_files', []) as $file) {
34+
$this->line('Rotate file: '.$file);
35+
36+
$this->rotateFile($file);
37+
}
38+
}
39+
40+
protected function rotateFile(string $filename)
41+
{
42+
$rotation = new LaravelLogRotate();
43+
44+
$rotation->file($filename);
45+
}
46+
}

src/Commands/RotateFile.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Commands/RotateFileCommand.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Cesargb\LaravelLog\Commands;
4+
5+
use Cesargb\LaravelLog\Rotate;
6+
use Illuminate\Console\Command;
7+
8+
class RotateFileCommand extends Command
9+
{
10+
protected $signature = 'rotate:files
11+
{--f|file=* : Files to rotate}
12+
{--c|compress=true : Compress the file rotated}
13+
{--m|max-files=5 : Max files rotated}
14+
{--d|dir= : Dir where archive the file rotated}';
15+
16+
protected $description = 'Rotate files';
17+
18+
public function handle()
19+
{
20+
foreach ($this->option('file') as $filename) {
21+
$this->line('Rotate file '.basename($filename).': ');
22+
23+
$rotate = new Rotate();
24+
25+
$rotate->file($filename, [
26+
'files' => config('rotate.log_max_files', 366),
27+
'compress' => config('rotate.log_compress_files', true),
28+
// 'then' => function () {
29+
// $this->line('<info>ok</>');
30+
// },
31+
// 'catch' => function ($error) {
32+
// $this->error('<comment>failed: '.$error->getMessage().'</>');
33+
// },
34+
]);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)