tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:
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
I wind up withwipeLog(); logMessage("testing"); logMessage( Carp::cluck("Cluck at "));
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?testing 1
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;
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.#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;
Thank you, o monks!
thomas.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I get Cluck output into a log file?
by steves (Curate) on Dec 29, 2004 at 13:57 UTC | |
by tphyahoo (Vicar) on Dec 29, 2004 at 14:23 UTC | |
by steves (Curate) on Dec 29, 2004 at 16:03 UTC | |
by osunderdog (Deacon) on Dec 29, 2004 at 15:27 UTC |