I've found that my logging methods vary greatly depending on the type of application I'm writing and whether it is in the debugging or production phases.

I've never really considered adding to the system logs because they tend to fill up rapidly, get aged, and deleted. Many times system logs are also located on partitions that are relatively short on space, so I don't want to aggravate that problem either.

I prefer creating application specific log files that are human readable at all times, so I try to use messages that are visually distinctive for the various types of logged messages. As I'm debugging I comment out debug statements from areas as I complete them so the amount of information logged decreases greatly as I near the end of a project. The parts left are usually checkpoints that indicate success or failure of a given task.

When debugging some web applications sometimes I find it more helpful to bypass file logging and generate simple javascript alerts:

print "<script language='javascript'>alert('Exiting sub XXXXXXXXXX.')< +/script>";
For more extensive web debugging info I use a html sub that is passed a "Continue" value that can be used to halt execution if necessary:
sub Notify { my ($Text, $continue, $green) = @ARG; my $bgcolor = '#FC8C8C'; if ($green) { $bgcolor = '#BBFFBB'; } print <<"-100-"; <br><br><br><br> <table align=center BGCOLOR="$bgcolor" cellpadding=15 border=3> <tr><td align=center><font size=5 face=Arial> <b>$Text</b></font></td></tr> </table><br><br><br><br><br> -100- if (!$continue) { ## fatal message print <<"-200-"; <table border=0 width=100%> <tr><td align=center><font size=4 face=Arial color="blue"> <b>Contact Whomever Necessary at 999-9999 (Mon-Fri, 8am-5pm +) for questions regarding use of the this application.</b> </font></td></tr> </table> </center> </body> </html> -200- exit; } print <<"-300-"; </center> </body> </html> -300- }
Yes, I realize that I could take better advantage of CGI.pm, and I probably will rewrite this sub to do so when I undertake my next Web application (which may not be for several months).

--Jim


In reply to Re: How to write to log files? by jlongino
in thread How to write to log files? by ajt

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.