Skip to content

Commit 5b76881

Browse files
committed
Initial
0 parents  commit 5b76881

11 files changed

+350
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
/build
3+
composer.lock
4+

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
3+
php:
4+
- 7.0
5+
- 7.1
6+
7+
env:
8+
matrix:
9+
- COMPOSER_FLAGS="--prefer-lowest"
10+
- COMPOSER_FLAGS=""
11+
12+
before_script:
13+
- travis_retry composer self-update
14+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
15+
16+
script:
17+
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Cesargb
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
3+
# Create link for authenticate in Laravel without password
4+
5+
This package permit create a link for authenticate without user or password.
6+
7+
## Instalation
8+
9+
This package can be used in Laravel 5.4 or higher.
10+
11+
You can install the package via composer:
12+
13+
```bash
14+
composer require cesargb/laravel-logs-rotate
15+
```
16+
17+
If you have Laravel 5.4, you must add the service provider in config/app.php file:
18+
19+
```php
20+
'providers' => [
21+
// ...
22+
Cesargb\Files\Rotate\RotateServiceProvider::class,
23+
];
24+
```
25+
26+
You can publish config file with:
27+
28+
```
29+
php artisan vendor:publish --provider="Cesargb\File\Rotate\RotateServiceProvider" --tag=config
30+
```
31+
This is the contents of the published config/magiclink.php config file:
32+
33+
```php
34+
return [
35+
'log_max_files' => config('app.log_max_files'),
36+
37+
'log_compress_files' => true,
38+
39+
'logs_rotate_schedule' => '0 0 * * *',
40+
];
41+
```
42+
43+
44+
## License
45+
46+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "cesargb/laravel-logs-rotate",
3+
"description": "Rotate files log with compression",
4+
"keywords": [
5+
"laravel",
6+
"logs",
7+
"rotate",
8+
"compression"
9+
],
10+
"homepage": "https://github.com/cesargb/laravel-logs-rotate",
11+
"authors": [
12+
{
13+
"name": "Cesar Garcia",
14+
"email": "[email protected]",
15+
"homepage": "https://github.com/cesargb",
16+
"role": "Developer"
17+
}
18+
],
19+
"license": "MIT",
20+
"require": {
21+
"php" : ">=7.0",
22+
"cesargb/file-rotate": "^1.0",
23+
"illuminate/config": "~5.4.0 || ~5.5.0",
24+
"illuminate/console": "~5.4.0 || ~5.5.0"
25+
},
26+
"require-dev": {
27+
"orchestra/testbench": "~3.4.2",
28+
"phpunit/phpunit": "^6.2",
29+
"illuminate/log": "~5.4.0 || ~5.5.0"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"Cesargb\\File\\Rotate\\": "src"
34+
}
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"Cesargb\\File\\Rotate\\Test\\": "tests"
39+
}
40+
},
41+
"scripts": {
42+
"test": "phpunit"
43+
},
44+
"extra": {
45+
"laravel": {
46+
"providers": [
47+
"Cesargb\\File\\Rotate\\RotateServiceProvider"
48+
]
49+
}
50+
}
51+
}

phpunit.xml.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="League Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
<logging>
23+
<log type="tap" target="build/report.tap"/>
24+
<log type="junit" target="build/report.junit.xml"/>
25+
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
26+
<log type="coverage-text" target="build/coverage.txt"/>
27+
<log type="coverage-clover" target="build/logs/clover.xml"/>
28+
</logging>
29+
</phpunit>

src/Commands/Rotate.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Cesargb\File\Rotate\Commands;
4+
5+
use Cesargb\File\Rotate as RotateFile;
6+
use Illuminate\Console\Command;
7+
8+
class Rotate extends Command
9+
{
10+
protected $signature = 'logs:rotate';
11+
12+
protected $description = 'Rotate logs';
13+
14+
public function handle()
15+
{
16+
if (config('app.log') == 'single') {
17+
$result = RotateFile::file(
18+
app()->storagePath().'/logs/laravel.log',
19+
config('rotate.log_max_files', config('app.log_max_files')),
20+
config('rotate.log_compress_files', true)
21+
);
22+
23+
if ($result) {
24+
$this->info('Logs was rotated');
25+
} else {
26+
$this->error('Logs rotate failed');
27+
}
28+
} else {
29+
$this->error('Laravel must be configure with single log. You can change this in app/config.php');
30+
}
31+
}
32+
}

src/RotateServiceProvider.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Cesargb\File\Rotate;
4+
5+
6+
use Illuminate\Console\Scheduling\Schedule;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class RotateServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Bootstrap the application services.
13+
*
14+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
$this->publishes([
19+
__DIR__.'/config/rotate.php' => config_path('rotate.php'),
20+
], 'config');
21+
22+
if ($this->app->runningInConsole()) {
23+
$this->commands([
24+
Commands\Rotate::class,
25+
]);
26+
}
27+
28+
$this->app->booted(function () {
29+
if (config('update.scheduler.check.enable', true)) {
30+
$schedule = $this->app->make(Schedule::class);
31+
$schedule->command('logs:rotate')->cron(config('rotate.logs_rotate_schedule', '0 0 * * *'));
32+
}
33+
});
34+
}
35+
36+
/**
37+
* Register the application services.
38+
*
39+
* @return void
40+
*/
41+
public function register()
42+
{
43+
//
44+
}
45+
}

src/config/rotate.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
return [
4+
'log_max_files' => config('app.log_max_files'),
5+
6+
'log_compress_files' => true,
7+
8+
'logs_rotate_schedule' => '0 0 * * *',
9+
];

tests/RotateTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Cesargb\File\Rotate\Test;
4+
5+
use Illuminate\Support\Facades\Artisan;
6+
use Illuminate\Support\Facades\Log;
7+
8+
class RotateTest extends TestCase
9+
{
10+
public function setUp()
11+
{
12+
parent::setUp();
13+
14+
$this->app['config']->set('app.log', 'single');
15+
$this->app['config']->set('rotate.log_compress_files', true);
16+
$this->app['config']->set('rotate.log_max_files', 5);
17+
18+
$filesOld = glob(app()->storagePath().'/logs/laravel*');
19+
20+
foreach ($filesOld as $f) {
21+
unlink($f);
22+
}
23+
}
24+
25+
/** @test **/
26+
public function it_can_rotate_logs()
27+
{
28+
29+
Log::info('test');
30+
31+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log');
32+
33+
$resultCode = Artisan::call('logs:rotate');
34+
35+
$this->assertEquals($resultCode, 0);
36+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log.1.gz');
37+
}
38+
39+
/** @test **/
40+
public function it_can_rotate_logs_withoutcompress()
41+
{
42+
Log::info('test');
43+
44+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log');
45+
46+
$this->app['config']->set('rotate.log_compress_files', false);
47+
48+
$resultCode = Artisan::call('logs:rotate');
49+
50+
$this->assertEquals($resultCode, 0);
51+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log.1');
52+
}
53+
54+
/** @test **/
55+
public function it_can_rotate_logs_with_maxfiles()
56+
{
57+
$this->app['config']->set('rotate.log_compress_files', true);
58+
59+
60+
for ($n = 0 ; $n<10; $n++) {
61+
file_put_contents(app()->storagePath().'/logs/laravel.log', 'test');
62+
Artisan::call('logs:rotate');
63+
}
64+
65+
$filesOld = glob(app()->storagePath().'/logs/laravel.log.*.gz');
66+
67+
68+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log.1.gz');
69+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log.2.gz');
70+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log.3.gz');
71+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log.4.gz');
72+
$this->assertFileExists(app()->storagePath().'/logs/laravel.log.5.gz');
73+
$this->assertFalse(file_exists(app()->storagePath().'/logs/laravel.log.6.gz'));
74+
}
75+
}

tests/TestCase.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Cesargb\File\Rotate\Test;
4+
5+
use Cesargb\File\Rotate\RotateServiceProvider;
6+
use Orchestra\Testbench\TestCase as Orchestra;
7+
8+
abstract class TestCase extends Orchestra
9+
{
10+
/**
11+
* @param \Illuminate\Foundation\Application $app
12+
*
13+
* @return array
14+
*/
15+
protected function getPackageProviders($app)
16+
{
17+
return [
18+
RotateServiceProvider::class,
19+
];
20+
}
21+
}

0 commit comments

Comments
 (0)