Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: naming conventions for logs

by {NULE} (Hermit)
on Aug 05, 2002 at 18:45 UTC ( [id://187773]=note: print w/replies, xml ) Need Help??


in reply to naming conventions for logs

Hey aufrank,

If you don't mind a wee bit of overhead you can try running your logfile names through stftime. You can give your logfiles names like myprogram-%Y-%m-%d.log and as long as you perform your open-append each time when you go to write, and your files will be nicely broken into days for you.

use POSIX qw/strftime/; # Main routine... my $logfile = "program-%Y-%m-%d.log"; &do_log($logfile, "This is the message I want to log"); sub do_log { my $logfile = shift; my $message = shift; open LOG, ">>".strftime($logfile, localtime); print LOG stftime("%H:%M:%S ", localtime); print LOG $message,"\n"; close LOG; }
This will give you logfiles with names like program-2002-08-05.log (which will sort correctly) and each line will be prefixed by a HH:MM:SS timestamp. Then you could delete last month's logs with a rm *-2002-08-??.log or the like.

Of course you may wish to make your logging routine a bit more sophisticated than this. (Some error checking would be nice, of course.)

Good luck,
{NULE}
--
http://www.nule.org

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://187773]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found