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

log file rotates twice in Windows if rotateByCopy ==true #3321

Closed
jjdunn opened this issue Apr 4, 2014 · 2 comments
Closed

log file rotates twice in Windows if rotateByCopy ==true #3321

jjdunn opened this issue Apr 4, 2014 · 2 comments

Comments

@jjdunn
Copy link

jjdunn commented Apr 4, 2014

Win7Home; PHP 5.5.10; Apache 2.4.7; Yii 1.1.14

Under Windows, logs are not rotating properly when they exceed maxFileSize. The file is locked (by the same process). see http://www.php.net/manual/en/function.rename.php, comment by "Martin Pelletier" which says "rename() is working on Linux/UNIX but not working on Windows on a directory containing a file formerly opened within the same script. The problem persists even after properly closing the file and flushing the buffer."

To work around this problem, I started using rotateByCopy=true. However now it's rotating the file TWICE.

  • start with only application.log (no .1, .2, etc.)
  • run the app, cause something to be written to the log
  • first pass thru processLogs() renames application.log => application.log.1
  • after log is rotated, collectLogs() is called again to handle the current log entry
  • when it gets to if(@filesize($logFile)>$this->getMaxFileSize()*1024), the filesize is CACHED, which causes rotateFiles() to be called a 2nd time, moving the .1 file to .2

To fix this problem, I added the following statement in CFileLogRoute.rotateFiles() at the very bottom of if(is_file($file)) {... @clearstatcache(); }

this fixes the problem. see next comment for patch

@jjdunn jjdunn closed this as completed Apr 4, 2014
@jjdunn jjdunn reopened this Apr 4, 2014
@jjdunn
Copy link
Author

jjdunn commented Apr 4, 2014

umm....no way to attach files in github, so here's the patch:

Index: CFileLogRoute.php

--- CFileLogRoute.php   (revision 6778)
+++ CFileLogRoute.php   (working copy)
@@ -198,6 +198,8 @@
            }
            else
                @rename($file,$file.'.1');
+                        
+                        @clearstatcache(); // JJD 4/3/14 reset file-size info so it's not rotated twice        
        }
    }
 }

@cebe cebe added this to the 1.1.15 milestone Apr 5, 2014
@resurtm resurtm self-assigned this Apr 8, 2014
@cebe cebe closed this as completed in 8a3ea82 Jun 25, 2014
@cebe
Copy link
Member

cebe commented Jun 25, 2014

Fixed. Thanks for detailed bug report and the patch!

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

No branches or pull requests

4 participants