473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Log rotation

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
Mar 5 '08 #1
6 3849
el*********@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.
js*******@attglobal.net
==================

Mar 5 '08 #2
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?
Mar 5 '08 #3
el*********@gmail.com wrote:
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.
js*******@attglobal.net
==================

Mar 5 '08 #4
On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
elrondru...@gmail.com wrote:
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
Mar 5 '08 #5
el*********@gmail.com wrote:
On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>elrondru...@gmail.com wrote:
>>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.
js*******@attglobal.net
==================

Mar 5 '08 #6
el*********@gmail.com wrote:
On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>elrondru...@gmail.com wrote:
>>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
Mar 5 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: M. Clift | last post by:
Hi All, Could someone help me out with this? items = ('a', 'b', 'c', 'd') items + 1 = ( 'b', 'c', 'd', 'a') items + 2 = ( 'c', 'd', 'a', 'b') items + 3 = ( 'd', 'a', 'b', 'c') trans = 1
3
by: news | last post by:
Hi Guys, Sorry if this is an obvious question but Im trying to rotate a bitmap and then save it. So far Ive only found how to rotates a Graphic but I can't find how to save it. I also want to...
5
by: Russell Warren | last post by:
Does anyone have an easier/faster/better way of popping from the middle of a deque than this? class mydeque(deque): def popmiddle(self, pos): self.rotate(-pos) ret = self.popleft()...
2
by: the other john | last post by:
I am looking for ideas on how to create a rollover that triggers an image rotation in another location. I know how to create a function for basic rollovers, image swapping sort of thing, but I...
0
by: VorTechS | last post by:
I'm having a problem with an inherited label, applying text rotation to aligned text. If text rotation is applied to the aligned text, the alignment goes 'nuts'. I can find no logic to what is...
2
by: Roger Li | last post by:
I got a problem about the mean rotation calculation. I have a group of rotation matrics in my program and I want to calculate the mean rotation on the basis of these rotation matrics. I think it...
6
by: Ramtin Kazemi | last post by:
Hi How can i perform bitwise rotation in C#?
3
by: kimiraikkonen | last post by:
Hi, Here is a very interesting issue, Assume i have picturebox and loaded a image into picturebox, however whenever i want to rotate image using: 'For example 90 degree...
8
by: infoseekar | last post by:
Image Resize & Rotation Hi I have 2 scripts, one for Image rotation and other image resize and they both are working. Image resize scripts load the picture and resize it and Image rotation...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.