sub new {
my $class_name = shift;
my $self = {};
$output_file = shift;
$append = shift;
$file_handle = undef ;
bless ($self,$class_name);
bless ($self);
return $self;
}
# opens log file for writing
# (no argument) will be called from first call to &message if not called from outside
sub start{
my $now = &get_timestamp;
print "opening $output_file\n";
if (uc($append)eq'APPEND') {
open ($file_handle,">>$output_file") || open ($file_handle,">$output_file") || die "Can't open $output_file $!";
}else{
open ($file_handle,">$output_file") || die "Can't open $output_file $!";
}
print $file_handle "Started logging at $now\n";
print $file_handle "Logging to $output_file\n";
print $file_handle "\n";
}
#log a message
# argument ,
sub message{
#run start subprocedure if file not already open
&start if (!$file_handle);
my $status = $_[1];
my $text = $_[2];
print $file_handle "$status : $text\n" ;
#$message_number++;
}
#close log
# (no argument)
sub finish{
#run start subprocedure if file not already open
if (!$file_handle){
&start;
}else{
my $now = &get_timestamp;
print $file_handle "\n";
print $file_handle "Finished logging at $now\n";
print $file_handle "-------------------------------------\n";
#close ($file_handle);
}
}