CGI-AppBuilder-Log

 view release on metacpan or  search on metacpan

Log.pm  view on Meta::CPAN


=head2 end_log($ar)

Input variables:

  $ar  - array ref returned from start_log. The elements can
         be populated in before end_log.

Variables used or routines called:

  strftime - time formater from POSIX
  disp_param - display parameters

How to use:

  use CGI::AppBuilder::Log qw(:log);
  my $self= bless {}, "main";
  my $ar = $self->start_log('details.log','brief.log');
  $self->end_log($ar);

Return: none.

=cut

sub end_log {
    my $s = shift;
    my ($ar) = @_;
    $s->echo_msg(" -- end logging ...",1);
    my %b   = %{${$ar}{fld}}; 
    # my $f   = "%a %b %e %H:%M:%S %Y"; 
    my $f   = "%Y%m%d.%H%M%S"; 
    my $fh1 = ${$ar}{fh_brf}; 
    my $fh2 = ${$ar}{fh_dtl}; 
    my $fn1 = $ar->{fn_brf}; 
    my $fn2 = $ar->{fn_dtl}; 
    my $cns = ${$ar}{cns}; 
    $s->{hf_brf} = $fh1;
    $s->{hf_dtl} = $fh2;
    $b{end_time}     = time;
    $b{elapsed_time} = $b{end_time} - $b{start_time};
    $b{start_time}   = strftime $f, localtime($b{start_time});
    $b{end_time}     = strftime $f, localtime($b{end_time});
    $b{result}       = 'OK'; 
  
    my ($txt) = ("");
    foreach my $k (split /,/, $cns) { $txt .= "$b{$k}|"; }
    my $fmt = "%s=%s\n";
    $txt =~ s/\|$//; 
    print $fh1 "$txt\n";  
    for my $k (sort keys %b) { 
        my $t = sprintf $fmt, $k, ((defined $b{$k}) ? $b{$k} : ""); 
        print $fh2 $t; 
    }
    for my $k (sort keys %$ar) { 
        my $t = sprintf $fmt, $k, $ar->{$k}; 
        print $fh2 $t; 
    }
    print $fh2 "# End at $b{end_time} $b{result}\n\n"; 
    undef $fh1;   # close breif  file hanlder
    undef $fh2;   # close detail file handler
    chmod 0777, $fn1, $fn2;
}

1;

=head1 CODING HISTORY

=over 4

=item * Version 0.10

Extract start_log and end_log from Debug::EchoMessage. 

=item * Version 0.11

=back

=head1 FUTURE IMPLEMENTATION

=over 4

=item * no plan yet 

=back

=head1 AUTHOR

Copyright (c) 2004 Hanming Tu.  All rights reserved.

This package is free software and is provided "as is" without express
or implied warranty.  It may be used, redistributed and/or modified
under the terms of the Perl Artistic License (see
http://www.perl.com/perl/misc/Artistic.html)

=cut



( run in 1.172 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )