O wise ones,

I have a very simple debugging methodology for now, I just rolled my own logMessage function and stuck it in a module. logMessage outputs the message to the dos window ongoingly (winxp/ASPN) and also writes it to a log file. I messed around with the perl debugger, but I just wound up liking this way better.

This was working fine, until I started using Carp.

Problem is if, from inside a module, I do something like

wipeLog(); logMessage("testing"); logMessage( Carp::cluck("Cluck at "));
I wind up with
testing 1
in my log.txt file. The messages get output to stdout, but I guess cluck is returning 1 instead of the debugging message to my logMessage() function. How do I get the actual message out of cluck so I can pass it to another function?

Here is the complete code for testcarp.pl, testcarp.pm, logger.pm, which all sit together in their own directory and work fine, other than the output to log.txt.

#testcarp.pl # custom module use TestCarp('test_carp'); test_carp();
#testcarp.pm package TestCarp; use strict; use Logger('logMessage','wipeLog'); use base 'Exporter'; our @EXPORT_OK = ('test_carp'); sub test_carp { wipeLog(); logMessage("testing"); logMessage( Carp::cluck("Cluck at ")); } 1;
#logger.pm use strict; package Logger; use base 'Exporter'; our @EXPORT_OK = ('logMessage','wipeLog'); sub logMessage { my $message = shift; print $message; # maybe could turn this on and off with command li +ne option. do later? my $logFileName = "log.txt"; open F, ">> $logFileName" or die "Cannot open log file: $logFileNa +me"; print F $message,"\n"; close F; } sub wipeLog { my $logFileName = "log.txt"; open F, "> $logFileName" or die "Cannot open log file: $logFileNam +e"; close F; } 1;
I know there are other frameworks for dealing with logging and debugging, and if anybody would care to comment on how I could be doing this better, fire away.

Thank you, o monks!

thomas.


In reply to How do I get Cluck output into a log file? by tphyahoo

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.