Connecting Tech Pros Worldwide Forums | Help | Site Map

Log rotation

elrondrules@gmail.com
Guest
 
Posts: n/a
#1: Mar 5 '08
I want to create a simple log rotation for the following scenario:

I have a script that when executed will write debug and error messages
to a specific file (say script.log).
I want to create log rotation such a way that if the file size of
script.log exceeds say 500KB, I want to rename script.log as
script<day>1.log and the latest logs to be written to script.log.

Essentially script.log should have the recent 500KB of logs.

Is there any such inbuilt mechanism, else can you give some pointers
to do this.

Thanks

Jerry Stuckle
Guest
 
Posts: n/a
#2: Mar 5 '08

re: Log rotation


elrondrules@gmail.com wrote:
Quote:
I want to create a simple log rotation for the following scenario:
>
I have a script that when executed will write debug and error messages
to a specific file (say script.log).
I want to create log rotation such a way that if the file size of
script.log exceeds say 500KB, I want to rename script.log as
script<day>1.log and the latest logs to be written to script.log.
>
Essentially script.log should have the recent 500KB of logs.
>
Is there any such inbuilt mechanism, else can you give some pointers
to do this.
>
Thanks
>
Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
PHP. Like logrotate.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

elrondrules@gmail.com
Guest
 
Posts: n/a
#3: Mar 5 '08

re: Log rotation


On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
elrondru...@gmail.com wrote:
Quote:
I want to create a simple log rotation for the following scenario:
>
Quote:
I have a script that when executed will write debug and error messages
to a specific file (say script.log).
I want to create log rotation such a way that if the file size of
script.log exceeds say 500KB, I want to rename script.log as
script<day>1.log and the latest logs to be written to script.log.
>
Quote:
Essentially script.log should have the recent 500KB of logs.
>
Quote:
Is there any such inbuilt mechanism, else can you give some pointers
to do this.
>
Quote:
Thanks
>
Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
PHP. Like logrotate.
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
thanks for the response..

is there a sample that I can look at so that I can do a similar one in
PHP?
Jerry Stuckle
Guest
 
Posts: n/a
#4: Mar 5 '08

re: Log rotation


elrondrules@gmail.com wrote:
Quote:
On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
>elrondru...@gmail.com wrote:
Quote:
>>I want to create a simple log rotation for the following scenario:
>>I have a script that when executed will write debug and error messages
>>to a specific file (say script.log).
>>I want to create log rotation such a way that if the file size of
>>script.log exceeds say 500KB, I want to rename script.log as
>>script<day>1.log and the latest logs to be written to script.log.
>>Essentially script.log should have the recent 500KB of logs.
>>Is there any such inbuilt mechanism, else can you give some pointers
>>to do this.
>>Thanks
>Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
>PHP. Like logrotate.
>>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attglobal.net
>==================
>
thanks for the response..
>
is there a sample that I can look at so that I can do a similar one in
PHP?
>
Don't know of one, but I haven't looked. Have you searched for log
rotation scripts? There are several around, and most are very flexible.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

elrondrules@gmail.com
Guest
 
Posts: n/a
#5: Mar 5 '08

re: Log rotation


On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
elrondru...@gmail.com wrote:
Quote:
On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
elrondru...@gmail.com wrote:
>I want to create a simple log rotation for the following scenario:
>I have a script that when executed will write debug and error messages
>to a specific file (say script.log).
>I want to create log rotation such a way that if the file size of
>script.log exceeds say 500KB, I want to rename script.log as
>script<day>1.log and the latest logs to be written to script.log.
>Essentially script.log should have the recent 500KB of logs.
>Is there any such inbuilt mechanism, else can you give some pointers
>to do this.
>Thanks
Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
PHP. Like logrotate.
>
Quote:
Quote:
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
>
Quote:
thanks for the response..
>
Quote:
is there a sample that I can look at so that I can do a similar one in
PHP?
>
Don't know of one, but I haven't looked. Have you searched for log
rotation scripts? There are several around, and most are very flexible.
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I did search for log rotation scripts but couldnt find any. Let me
keep looking.. though would be great if u can point to if you come
across any
Jerry Stuckle
Guest
 
Posts: n/a
#6: Mar 5 '08

re: Log rotation


elrondrules@gmail.com wrote:
Quote:
On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
>elrondru...@gmail.com wrote:
Quote:
>>On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>>elrondru...@gmail.com wrote:
>>>>I want to create a simple log rotation for the following scenario:
>>>>I have a script that when executed will write debug and error messages
>>>>to a specific file (say script.log).
>>>>I want to create log rotation such a way that if the file size of
>>>>script.log exceeds say 500KB, I want to rename script.log as
>>>>script<day>1.log and the latest logs to be written to script.log.
>>>>Essentially script.log should have the recent 500KB of logs.
>>>>Is there any such inbuilt mechanism, else can you give some pointers
>>>>to do this.
>>>>Thanks
>>>Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
>>>PHP. Like logrotate.
>>>--
>>>==================
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstuck...@attglobal.net
>>>==================
>>thanks for the response..
>>is there a sample that I can look at so that I can do a similar one in
>>PHP?
>Don't know of one, but I haven't looked. Have you searched for log
>rotation scripts? There are several around, and most are very flexible.
>>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attglobal.net
>==================
>
I did search for log rotation scripts but couldnt find any. Let me
keep looking.. though would be great if u can point to if you come
across any
>
As I said - I wouldn't do that in PHP - I'd use C or C++. And on my
Linux systems, I just use logrotate.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Norman Peelman
Guest
 
Posts: n/a
#7: Mar 5 '08

re: Log rotation


elrondrules@gmail.com wrote:
Quote:
On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
>elrondru...@gmail.com wrote:
Quote:
>>On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>>elrondru...@gmail.com wrote:
>>>>I want to create a simple log rotation for the following scenario:
>>>>I have a script that when executed will write debug and error messages
>>>>to a specific file (say script.log).
>>>>I want to create log rotation such a way that if the file size of
>>>>script.log exceeds say 500KB, I want to rename script.log as
>>>>script<day>1.log and the latest logs to be written to script.log.
>>>>Essentially script.log should have the recent 500KB of logs.
>>>>Is there any such inbuilt mechanism, else can you give some pointers
>>>>to do this.
>>>>Thanks
>>>Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
>>>PHP. Like logrotate.
>>>--
>>>==================
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstuck...@attglobal.net
>>>==================
>>thanks for the response..
>>is there a sample that I can look at so that I can do a similar one in
>>PHP?
>Don't know of one, but I haven't looked. Have you searched for log
>rotation scripts? There are several around, and most are very flexible.
>>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attglobal.net
>==================
>
I did search for log rotation scripts but couldnt find any. Let me
keep looking.. though would be great if u can point to if you come
across any

This is ugly, but it's what I used before i started logging to a db.
Doesn't do filesize but will automatically change every day.

LOGFILE is DEFINED() true or false to turn on/off logging.
LOGNAME is DEFINED() as your log name.


$u_id = uniqid('uid');
$cr = chr(13);
function logfile($txt)
{
if (LOGFILE)
{
$txt = date("G:i:s - ")."{$u-id} - {$txt}{$cr}";
$lf = LOGNAME.date(' D M j - Y').'.log';
$fp = fopen($lf,'a');
if (flock($fp, LOCK_EX))
{
fwrite($fp,$txt,1024);
flock($fp, LOCK_UN);
}
fclose($fp);
}
}


This was for multiple script calls logging to the same file, $u_id
made it easy to group the entries. The date() made it easy to sort the
entries. May help, may not. But like I said, I now log to a db.

--
Norman
Registered Linux user #461062
Closed Thread