Re: Rotating Log-Container
| From: | Stephan Wentz | Date: | Thu, 03 Feb 2005 15:22:16 +0000 |
| Subject: | Re: Rotating Log-Container | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-35921@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
bertrand Gugger wrote:
| Hi Stephan:
|
|> Unlimited amount of
|> logfiles? Would this make sense?
|
|
| That could mean let the system do it when it needs place, if you have.
| But it's certlainly dangerous.
Yea, it is, and I wouldn't recommend it, but people might need _all_
logfiles due to legal means...
Hmm but thinking about this, one can download old file via ftp or
something, so I'll skip this. I'll set $maxFiles to 1 when 0 is given,
so ONE rotated logfile will be created.
| Anyway, if you use only filesize, you need only to change method open()
| and have the attributes $maxSize, $maxFiles :)
And $maxAge, to rotate on a daily basis, for example.
I have uploaded a fixed version, with $maxLines-code removed.
| Now, one big problem subsists,
| you *will* have once 2 processes liking to rotate the same time.
| so they will concurently rename the files and result is unexpected,
| as a process can rename again a file just renamed by the other process :(
|
| One solution could be to rename only the current file to
| "xxxx.(timestamp/unique ID)"
| Then the only risk is to get a quite empty file (1 logging) in case of
| such concurence.
| But you will need extra listing and count of existing log files
| to remove the oldest if too much of them eventually.
Hmm yea, this would solve this.
But is it really necessary?
Having $maxFiles=4 would do this on a rotate:
logfile.3 -> logfile.4
logfile.2 -> logfile.3
logfile.1 -> logfile.2
logfile -> logfile.1
If another process interferes with this it would try to move a
non-existing file, which will lead to a supressed error.
The only race condition would be if 2 processes would interfere in line
128 and 131, one opens a new log, the other moves it away. But like you
said, this would just lead to a very small logfile, because the first
process would write to the moved logfile...
So I don't think this is a big problem.
Or are my thoughts wrong?
| BTW: why don't you do that from a cron job, just checking log file size,
| rename it if necessary and remove oldest log file that are too much ?
| as the system do :)
| It would be transparent for the PHP scripts and you don't need extra
| archive class.
Because I can't. Project is hosted on a managed server, I don't have any
access to the machine!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCAkGo8qQ9XV7tBNQRApr2AKDVUf2tgC1WebMrWXX6LrSahxy4HwCfcrf3
Cxh96hHGxColnGIYZhYtxIo=
=7S0U
-----END PGP SIGNATURE-----