I'm writing a web app that i want to log various actions with a homebrew logger.

My app is CGI::Applicaiton/HTML::Template and is failing when I make the call to my logger module. If I comment out the call to the logger module everything works ok.

Apache fails with the message:
Premature end of script headers: /var/www/cgi-bin/portal/addr/app_addr.pl

While i know what that message literally translates into (ie a web page without headers), I cant work out how i'm getting this message (or find the content that is creating this message).

I'm not sure if this is maybe a perm problem with apache, or if my logger is buggy.

Here is the code for my logger

package Logger; $VERSION = 1.00; use strict; use vars qw( $AUTOLOAD ); use Data::Dumper; use Carp; { #Encapsulated class data my %_log_attr = # DEFAULT ACCESSIBILITY ( _name => ['DEFAULT', 'read/write'], _handle => [undef, 'read'] ); #is a specirfied object attribute accessible in a given mode sub _accessible { my ($self, $attr, $mode) = @_; $_log_attr{$attr}[1] =~ /$mode/ } # Classwide default value for a specified object attributes sub _default_for { my ($self, $attr) = @_; $_log_attr{$attr}[2]; } # list of names of all specified object attributes sub _standard_keys { keys %_log_attr; } # return datestamp sub _date { my @date=localtime; ++$date[4]; if (length($date[3])eq 1 ) {$date[3]='0'.$date[3]}; if (length($date[4])eq 1 ) {$date[4]='0'.$date[4]}; $date[5]=$date[5]+1900; return($date[3].$date[4].$date[5],"$date[3]-$date[4]-$date[5]" +); } # return timestamp sub _time { my @time=localtime; ++$time[4]; if (length($time[2])eq 1 ) {$time[2]='0'.$time[2]}; if (length($time[1])eq 1 ) {$time[1]='0'.$time[1]}; return($time[2].$time[1].$time[0],"$time[2]:$time[1]:$time[0]" +); } } sub new { my ($caller, %arg) = @_; my $caller_is_obj = ref($caller); my $class = $caller_is_obj || $caller; my $self = bless {}, $class; foreach my $attrname ($self->_standard_keys() ) { my ($argname) = ($attrname =~ /^_(.*)/); if (exists $arg{$argname}) { $self->{$attrname} = $arg{$argname} ; } elsif ($caller_is_obj) { $self->{$attrname} = $caller->{$argname}; } else { $self->{$attrname} = $self->_default_for($attrname) } } $self->{_handle}=&prepare_file($self); return $self; } sub prepare_file { my $self = shift; if ($self->{_name}) { if ($self->{_name} =~ /^[\w\.]+$/) { my @ds = $self->_date(); my $name = '>>'.$self->{_name}.'.'.$ds[0].'.log'; local*LOGFILE; open(LOGFILE, $name) || carp "Unable to open file: $!"; return *LOGFILE; } else { carp "You may only use alphanumerics, dot <.> and undersco +re <_> in names.\n"; return undef; } } } sub log { my ($self, $location, $message) = @_; if ($self->{_handle}) { print {$self->{_handle}} $self->_date().' '.$self->_time().", $$ +, $location, $message\n"; } else { carp "Must call logger->new(name=>'<logfile>') before writing +log.\n"; } } 1

If anyone could shine a light on what could be going on here, i'd appreciate it.

Credits to Conway for the OO framework.


In reply to Web App logging by Ryszard

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.