Write to my root/logs from Perl script?

software development


Well, since sendmail’d logs can take hours to arrive (see my previous post, topic=“sendmail Delays for Hours”), I was wondering if I could write to my root/logs, the way the perl compiler does when it encounters compile errors. I would like to log run-time variables so I can debug execution errors.

I found this in the list of perl modules supposedly installed on DreamHost:


Is that the tool I should use? If so, what is the correct incantation to log, say, “Hello, World!”?

I tried the various incantations suggested in that doc and none of them worked. From searching this forum it appears that I don’t have access to my httpd.conf. Also,

use Apache::LogFile ;

generated an error that it could not even find that module. What did I do wrong there?




You’re going about it the wrong way.


use CGI;

my $query = new CGI;

$query->header() .
$query->start_html() .
$query->h1(‘Error Test’) .

print STDERR “This is an error.”;

:cool: [color=#6600CC]Atropos[/color] | openvein.org


Thanks, I got it. “You just write to stderr, dummy”.

Surprisingly, this doesn’t stamp it with the process name or timestamp, so I wrote a little sub that does. It seems like this should be built in somewhere, but, oh, well…


use CGI ; # Scripts work on DreamHost without this

Set global logging level to a number from 0-5.

0 logs everything (debugging)

my $globalLoggingLevel = 2 ;

Print “OK” reply back to client

print “content-type: text/plain\n\n”;
print “OK, it worked!”, “\n” ;

printLog (0, “Emergency Message to system log”) ;
printLog (1, “Critical Message to system log”) ;
printLog (2, “Normal Message to system log”) ;
printLog (3, “Unimportant Message to system log”) ;
printLog (4, “Trivial Message to system log”) ;

exit ;

sub printLog {
my $loggingLevel = shift ;
if ($loggingLevel <= $globalLoggingLevel) {
my $rawMsg = shift ;

create $dateTime

= localtime(time) ;
my $dateTime
= sprintf(“ddd.d:d:d”,
$year+1900,$mon+1,$mday,$hour,$min,$sec) ;

my $scriptName = “scriptName” ;

my $scriptName = $ENV{‘SCRIPT_NAME’} ;

my $wrappedMsg = “$dateTime $scriptName: $rawMsg\n” ;
print stderr $wrappedMsg ;


Rather than reinventing the wheel, why not locally install something like: