@@ -31,11 +31,12 @@ public function addProcessor(AbstractProcessor ...$processors): self
3131 * Rotate file
3232 *
3333 * @param string $file
34+ * @param string $maxFileSize
3435 * @return string|null
3536 */
36- public function rotate (string $ file ): ?string
37+ public function rotate (string $ file, int $ maxFileSize = 0 ): ?string
3738 {
38- if (!$ this ->canRotate ($ file )) {
39+ if (!$ this ->canRotate ($ file, $ maxFileSize )) {
3940 return null ;
4041 }
4142
@@ -70,10 +71,11 @@ private function runProcessors(string $originalFile, ?string $fileRotated): ?str
7071 * check if file need rotate
7172 *
7273 * @param string $file
74+ * @param int $maxFileSize
7375 * @return boolean
7476 * @throws LogicException
7577 */
76- private function canRotate (string $ file ): bool
78+ private function canRotate (string $ file, int $ maxFileSize = 0 ): bool
7779 {
7880 if (count ($ this ->processors ) == 0 ) {
7981 throw new LogicException ('You need at least one processor to logs rotate ' , 1 );
@@ -82,8 +84,13 @@ private function canRotate(string $file): bool
8284 if (! $ this ->fileIsValid ($ file )) {
8385 throw new LogicException (sprintf ('the file %s not is valid. ' , $ file ), 2 );
8486 }
87+
88+ if ($ maxFileSize > 0 ) {
89+ // convert MB to bytes
90+ $ maxFileSize = $ maxFileSize * pow (1024 , 2 );
91+ }
8592
86- return filesize ($ file ) > 0 ;
93+ return filesize ($ file ) > ( $ maxFileSize > 0 ? $ maxFileSize : 0 ) ;
8794 }
8895
8996 /**
0 commit comments