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


In reply to Re: naming conventions for logs by {NULE}
in thread naming conventions for logs by aufrank

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.