[Patch] Log file handler: limit log size by number of lines

From: Date: Fri, 13 Oct 2006 23:30:42 +0000
Subject: [Patch] Log file handler: limit log size by number of lines
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-44509@lists.php.net to get a copy of this message
Hi, Long-time user, first-time contributor, so let me know if I'm violating any protocol. Attached is a patch for the Log package (only file.php is affected) that adds a new optional configuration parameter to the file handler: lineLimit. If lineLimit is a positive integer, then when the close() function is called, the log is rewritten with only the most recent n lines, where n is the value of lineLimit. (If it's desirable to reduce the log in this way before the file is closed, there is also a publicly accessible reduceLog() function.) Obviously rewriting the log file from scratch has a significant performance impact; it also means that the file can't be accessed via append mode in the first place (since the file pointer can't be fully rewound). But, for many non-performance-intensive applications, or those that only write to a log file occassionally, being able to limit the log file to something human-readable automatically is a handy thing. It's worked out nicely for one of my own projects, so far. Backward compatibility is retained, and I'm reasonably certain that the code is bug-free (though it does assume that the lineLimit parameter is a positive integer). Let me know what you guys think. Trevor Burnham

« previous php.pear.dev (#44509) next »