File Coverage

blib/lib/Goo/Logger.pm
Criterion Covered Total %
statement 3 12 25.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 1 2 50.0
pod 1 1 100.0
total 5 22 22.7


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package Goo::Logger;
4              
5             ###############################################################################
6             # Nigel Hamilton
7             #
8             # Copyright Nigel Hamilton 2003
9             # All Rights Reserved
10             #
11             # Author: Nigel Hamilton
12             # Filename: Goo::Logger.pm
13             # Description: Keep a simple text-based logger for the Trawler
14             # Now used as a general purpose error logger.
15             #
16             # Date Change
17             # -----------------------------------------------------------------------------
18             # 20/02/2003 Needed much better logging to see what was going on in the Trawler
19             # especially for Collections
20             # 01/05/2003 Write to a text log
21             # 01/07/2004 Small change for logging searches, and form submission
22             # used in development to see what's going on
23             # 21/08/2005 Added a proper die - if logfile could not be opened
24             # 23/08/2005 N.B. The error log file must have permissions set so that all
25             # users can append to it!
26             #
27             ###############################################################################
28              
29 1     1   7 use strict;
  1         3  
  1         215  
30              
31             my $default_location = "/tmp/default.error.log";
32              
33              
34             ###############################################################################
35             #
36             # write - write a timestamped entry to the log
37             #
38             ###############################################################################
39              
40             sub write {
41              
42 0     0 1   my ($message, $filename) = @_;
43              
44             # unless message ends with a newline add a newline
45 0 0         unless ($message =~ /\n$/) { $message .= "\n"; }
  0            
46              
47             # remember the time
48 0           my $timestamp = localtime();
49              
50             # use the default log file if not specified
51 0   0       my $log_file = $filename || $default_location;
52              
53 0           my ($package, $calling_filename, $line) = caller();
54              
55             # append to the log file
56 0 0         open(LOG, ">> $log_file")
57             or die("Can't append to $log_file: $@");
58 0           print LOG "[$timestamp] $calling_filename ($line) - $message";
59 0           close(LOG);
60              
61             }
62              
63              
64             1;
65              
66              
67             __END__
68              
69             =head1 NAME
70              
71             Goo::Logger - Write a message to the log
72              
73             =head1 SYNOPSIS
74              
75             use Goo::Logger;
76              
77             =head1 DESCRIPTION
78              
79             =head1 METHODS
80              
81             =over
82              
83             =item write
84              
85             write a timestamped entry to the log
86              
87             =back
88              
89             =head1 AUTHOR
90              
91             Nigel Hamilton <nigel@trexy.com>
92              
93             =head1 SEE ALSO
94