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

Rotation fails on files that already end in .1 #10

Open
kkjdroid opened this issue Jan 18, 2022 · 7 comments
Open

Rotation fails on files that already end in .1 #10

kkjdroid opened this issue Jan 18, 2022 · 7 comments

Comments

@kkjdroid
Copy link

Trying to rotate error.log.1 will sometimes result in an error.log.1.1, but if error.log.1.1 exists then trying to rotate error.log.1 will produce no new file and will not call either the then() or the catch() callback.

@cesargb
Copy link
Owner

cesargb commented Jan 18, 2022

I've tried to replicate the problem but I can't. I have published a PR #11 with a test for this issue, but the tests pass and calls to the then method occur correctly.

Could you tell me what version you have installed and what platform does it run on?

@cesargb cesargb linked a pull request Jan 18, 2022 that will close this issue
@kkjdroid
Copy link
Author

Odd. I'm on PHP 7.4.3 and Ubuntu 20.04.3 and it happens very consistently.

@cesargb
Copy link
Owner

cesargb commented Jan 20, 2022

@kkjdroid , Could you tell me what version of the package you have installed?

@kkjdroid
Copy link
Author

2.4.0

@cesargb cesargb removed a link to a pull request Jan 25, 2022
@cesargb
Copy link
Owner

cesargb commented Jan 25, 2022

I just published version 2.5.0, where you have a new method finally, this method is always called when the process ends. One possible case is when the source file does not exist, in which case no exception is thrown and no rotation occurs.

Please, update the package and test with:

$rotation = new Rotation();

$rotation->finally(function($message) {
   echo $message. PHP_EOL;
})->rotate('error.log.1');

@kkjdroid
Copy link
Author

kkjdroid commented Jan 26, 2022 via email

@kkjdroid
Copy link
Author

kkjdroid commented Jan 26, 2022

It's now very inconsistent. I got debug.log.1.1 to rotate to debug.log.1.1.1 and then debug.log.1.1.2, but now it won't create debug.log.1.1.3.

Here is my code:

debug_log('test');
$new_path = (new Rotation)
    ->compress(false)
    ->files(366)
    ->minSize(0)
    ->then(function($new_path, $old_path)
    {
        debug_log($new_path);
        debug_log($old_path);
        file_put_contents($old_path, '');
        return $new_path;
    })
    ->catch(function($e)
    {
        debug_log('then');
        debug_log($e);
    })
    ->finally(function($message)
    {
        debug_log('finally');
        debug_log($message);
    })
    ->rotate($path);

And the log output that it creates:

'test'

2022-01-26T10:39:25-05:00
'test'

2022-01-26T10:39:42-05:00
'test'

2022-01-26T10:41:04-05:00
'test'

2022-01-26T10:41:56-05:00
'test'

2022-01-26T10:41:56-05:00
'finally'

2022-01-26T10:41:56-05:00
'sucessfull'

2022-01-26T10:41:56-05:00
'debug.log.1.1'

2022-01-26T10:41:56-05:00
'debug.log.1'

2022-01-26T10:42:24-05:00
'test'

2022-01-26T10:42:24-05:00
'finally'

2022-01-26T10:42:24-05:00
'sucessfull'

2022-01-26T10:42:24-05:00
'debug.log.1.1.1'

2022-01-26T10:42:24-05:00
'debug.log.1.1'

2022-01-26T10:42:40-05:00
'test'

2022-01-26T10:43:02-05:00
'test'

2022-01-26T10:43:15-05:00
'test'

2022-01-26T10:43:31-05:00
'test'

2022-01-26T10:43:57-05:00
'test'

2022-01-26T10:43:57-05:00
'finally'

2022-01-26T10:43:57-05:00
'sucessfull'

2022-01-26T10:43:57-05:00
'error.log.1'

2022-01-26T10:43:57-05:00
'error.log'

2022-01-26T10:44:18-05:00
'test'```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants