Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #8 #20

Merged
merged 5 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,24 @@ Every time a file is rotated one of these events occurs:

### RotateWasSuccessful

`Cesargb\File\Rotate\Events\RotateWasSuccessful`
`Cesargb\LaravelLog\Events\RotateWasSuccessful`

This event will be fired when rotated was successful.

It has two public properties:

* fileSource: the full path of file to rotate
* fileRotated: the full path of file rotated
* filename: the full path of file to rotate
* filenameTarget: the full path of file rotated

### RotateHasFailed

`Cesargb\File\Rotate\Handlers\RotativeHandler`
`Cesargb\LaravelLog\Events\RotativeHandler`

This event will be fired when an error occurs while rotated

It has two public properties:

* fileSource: the full path of file to rotate
* filename: the full path of file to rotate
* exception: an object that extends PHP's Exception class.

## About
Expand All @@ -150,10 +150,6 @@ composer test

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.

## Contributing

Any contributions are welcome.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"illuminate/log": "^6.20|^8.0",
"illuminate/support": "^6.20|^8.0",
"monolog/monolog": "^2.0",
"cesargb/php-log-rotation": "^2.3"
"cesargb/php-log-rotation": "^2.4"
},
"require-dev": {
"orchestra/testbench": "^4.18|^6.20",
Expand Down
134 changes: 0 additions & 134 deletions src/Handlers/AbstractHandler.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Handlers/HandlerInterface.php

This file was deleted.

109 changes: 0 additions & 109 deletions src/Handlers/RotativeHandler.php

This file was deleted.

9 changes: 8 additions & 1 deletion src/Rotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Cesargb\LaravelLog\Events\RotateHasFailed;
use Cesargb\LaravelLog\Events\RotateWasSuccessful;
use Cesargb\LaravelLog\Helpers\Log;
use Cesargb\Log\Rotation;

class Rotate
Expand All @@ -17,7 +18,13 @@ public function files(array $filenames)

public function file(string $filename, array $options = []): bool
{
return $this->buildRotateDefault($options)->rotate($filename);
$result = $this->buildRotateDefault($options)->rotate($filename);

if ($result) {
Log::closeHandlers();
}

return $result;
}

private function buildRotateDefault(array $options = []): Rotation
Expand Down
49 changes: 0 additions & 49 deletions tests/Commands/RotateFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,7 @@ public function itCanRotateFile()
Event::assertDispatched(RotateWasSuccessful::class, 2);

$this->assertEquals($resultCode, 0);
$this->assertEquals(filesize($file1), 0);
$this->assertFileExists($file1.'.1.gz');
$this->assertEquals(filesize($file2), 0);
$this->assertFileExists($file2.'.1.gz');
}

// /** @test **/
// public function itCanRotateFileArchive()
// {
// $file1 = $this->tmpDir.'/file1';
// $file2 = $this->tmpDir.'/file2';

// $resultCode = Artisan::call('rotate:files', [
// '--file' => [$file1, $file2],
// '--dir' => $this->tmpDir.'/archive',
// ]);

// Event::assertDispatched(RotateWasSuccessful::class, 2);

// $this->assertEquals($resultCode, 0);
// $this->assertEquals(filesize($file1), 0);
// $this->assertFileExists(dirname($file1).'/archive/'.basename($file1).'.1.gz');
// $this->assertEquals(filesize($file2), 0);
// $this->assertFileExists(dirname($file2).'/archive/'.basename($file2).'.1.gz');
// }

// /** @test **/
// public function itCanRotateFileMax()
// {
// $file = $this->tmpDir.'/file1';

// for ($n = 0; $n < 5; ++$n) {
// file_put_contents($file, 'test');

// $resultCode = Artisan::call('rotate:files', [
// '--file' => [$file],
// '--max-files' => 3,
// ]);

// $this->assertEquals($resultCode, 0);
// }

// Event::assertDispatched(RotateWasSuccessful::class, 5);

// $this->assertEquals(filesize($file), 0);

// for ($n = 1; $n < 4; ++$n) {
// $this->assertFileExists($file.'.'.$n.'.gz');
// }

// $this->assertFileNotExists($file.basename($file).'.4.gz');
// }
}
Loading