Skip to content

Commit c1cb47a

Browse files
authoredDec 27, 2021
Merge pull request #20 from cesargb/fix-issue-8
fix issue #8
2 parents c22522b + e9091a5 commit c1cb47a

10 files changed

+20
-326
lines changed
 

‎README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,24 @@ Every time a file is rotated one of these events occurs:
114114

115115
### RotateWasSuccessful
116116

117-
`Cesargb\File\Rotate\Events\RotateWasSuccessful`
117+
`Cesargb\LaravelLog\Events\RotateWasSuccessful`
118118

119119
This event will be fired when rotated was successful.
120120

121121
It has two public properties:
122122

123-
* fileSource: the full path of file to rotate
124-
* fileRotated: the full path of file rotated
123+
* filename: the full path of file to rotate
124+
* filenameTarget: the full path of file rotated
125125

126126
### RotateHasFailed
127127

128-
`Cesargb\File\Rotate\Handlers\RotativeHandler`
128+
`Cesargb\LaravelLog\Events\RotativeHandler`
129129

130130
This event will be fired when an error occurs while rotated
131131

132132
It has two public properties:
133133

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

137137
## About
@@ -150,10 +150,6 @@ composer test
150150

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

153-
## Knowledge Issues
154-
155-
* [#8](https://github.com/cesargb/laravel-logs-rotate/issues/8) While the file is being rotated, any record of another process may be lost.
156-
157153
## Contributing
158154

159155
Any contributions are welcome.

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"illuminate/log": "^6.20|^8.0",
2525
"illuminate/support": "^6.20|^8.0",
2626
"monolog/monolog": "^2.0",
27-
"cesargb/php-log-rotation": "^2.3"
27+
"cesargb/php-log-rotation": "^2.4"
2828
},
2929
"require-dev": {
3030
"orchestra/testbench": "^4.18|^6.20",

‎src/Handlers/AbstractHandler.php

-134
This file was deleted.

‎src/Handlers/HandlerInterface.php

-8
This file was deleted.

‎src/Handlers/RotativeHandler.php

-109
This file was deleted.

‎src/Rotate.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Cesargb\LaravelLog\Events\RotateHasFailed;
66
use Cesargb\LaravelLog\Events\RotateWasSuccessful;
7+
use Cesargb\LaravelLog\Helpers\Log;
78
use Cesargb\Log\Rotation;
89

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

1819
public function file(string $filename, array $options = []): bool
1920
{
20-
return $this->buildRotateDefault($options)->rotate($filename);
21+
$result = $this->buildRotateDefault($options)->rotate($filename);
22+
23+
if ($result) {
24+
Log::closeHandlers();
25+
}
26+
27+
return $result;
2128
}
2229

2330
private function buildRotateDefault(array $options = []): Rotation

‎tests/Commands/RotateFileTest.php

-49
Original file line numberDiff line numberDiff line change
@@ -30,56 +30,7 @@ public function itCanRotateFile()
3030
Event::assertDispatched(RotateWasSuccessful::class, 2);
3131

3232
$this->assertEquals($resultCode, 0);
33-
$this->assertEquals(filesize($file1), 0);
3433
$this->assertFileExists($file1.'.1.gz');
35-
$this->assertEquals(filesize($file2), 0);
3634
$this->assertFileExists($file2.'.1.gz');
3735
}
38-
39-
// /** @test **/
40-
// public function itCanRotateFileArchive()
41-
// {
42-
// $file1 = $this->tmpDir.'/file1';
43-
// $file2 = $this->tmpDir.'/file2';
44-
45-
// $resultCode = Artisan::call('rotate:files', [
46-
// '--file' => [$file1, $file2],
47-
// '--dir' => $this->tmpDir.'/archive',
48-
// ]);
49-
50-
// Event::assertDispatched(RotateWasSuccessful::class, 2);
51-
52-
// $this->assertEquals($resultCode, 0);
53-
// $this->assertEquals(filesize($file1), 0);
54-
// $this->assertFileExists(dirname($file1).'/archive/'.basename($file1).'.1.gz');
55-
// $this->assertEquals(filesize($file2), 0);
56-
// $this->assertFileExists(dirname($file2).'/archive/'.basename($file2).'.1.gz');
57-
// }
58-
59-
// /** @test **/
60-
// public function itCanRotateFileMax()
61-
// {
62-
// $file = $this->tmpDir.'/file1';
63-
64-
// for ($n = 0; $n < 5; ++$n) {
65-
// file_put_contents($file, 'test');
66-
67-
// $resultCode = Artisan::call('rotate:files', [
68-
// '--file' => [$file],
69-
// '--max-files' => 3,
70-
// ]);
71-
72-
// $this->assertEquals($resultCode, 0);
73-
// }
74-
75-
// Event::assertDispatched(RotateWasSuccessful::class, 5);
76-
77-
// $this->assertEquals(filesize($file), 0);
78-
79-
// for ($n = 1; $n < 4; ++$n) {
80-
// $this->assertFileExists($file.'.'.$n.'.gz');
81-
// }
82-
83-
// $this->assertFileNotExists($file.basename($file).'.4.gz');
84-
// }
8536
}

0 commit comments

Comments
 (0)