package File::Log::Shortcut; use strict; use warnings; use POSIX qw(strftime); our $VERSION = "0.1"; use base qw(File::Log); sub new { my $proto = shift; my $class = ref($proto) || $proto; my %args = %{$_[0]}; %args = map { lc($_) => $args{$_} } keys %args ; my $self = $class->SUPER::new(@_); my %defaults = ( appname => ($main::0 =~ /(?:^|[\/\\])([^\/\\]+)$/)[-1], appversion => $main::VERSION || "", authorname => "", _startedepoc => time, versionfrom => strftime( "%Y%m%d-%X", localtime( (stat($main::0))[9] ) ) , startedat => strftime( "%Y%m%d-%X", localtime() ), ); for ( keys %defaults ) { $self->{$_} = defined $args{$_} ? $args{$_} : $defaults{$_}; } return $self; } sub pProgramHeader { my $self = shift; $self->msg(shift, $self->programHeader); } sub programHeader { my $self = shift; my $msg = ""; $msg .= $self->{appname}; $msg .= " Version $self->{appversion}" if $self->{appversion}; $msg .= " from $self->{versionfrom}" if $self->{versionfrom}; $msg .= "\n"; $msg .= "Author: $self->{authorname}\n" if $self->{authorname}; $msg .= "Started at $self->{startedat}\n" if $self->{startedat}; return $msg; } sub pProgramFooter { my $self = shift; my $debug = shift; $self->msg($debug, $self->programFooter); } sub programFooter { my $self = shift; return "Ended at " . strftime( "%Y%m%d-%X", localtime() ) . " after " . (time-$self->{_startedepoc}) . "\n"; } sub pFileInfo { my $self = shift; my $debug = shift; my $file = shift; my $msg = shift || ""; $self->msg($debug, $self->fileInfo ($file, $msg)); } sub fileInfo { my $self = shift; my $file = shift; my $msg = shift || ""; return $msg . strftime( "%Y%m%d-%X", localtime( (stat($file))[9] ) ) . "\n"; } 1; __END__ =head1 NAME File::Log::Shortcut =head1 SYNOPSIS my $log = File::Log::Shortcut->new ( { # the author of the program, defaults to "" authorName => "Holli", # date of release, defaults to "last changed" of the script-file versionFrom => "someday", # the scripts version, defaults to $main::VERSION or "" appVersion => "0.1", } ); $log->pProgramHeader(2); sleep(2); open OUT , ">", "testout"; close OUT; sleep(2); $log->pFileInfo(2, "testout","File created: "); $log->pProgramFooter(2); $log->close(); =head1 DESCRIPTION This is a subclass of File::Log, that offers some convenience. So everything in the File::Log-documentation is true for File::Log::Shortcut =head2 methods =over 6 =item pProgramHeader ($debug); calls msg() of the parent class with $debug and a string like the following: test.pl Version 0.1 from someday Author: Holli Started at 20050206-04:57:49 =item programHeader returns the input for pProgramHeader() =item pProgramFooter ($debug); calls msg() of the parent class with $debug and a string like the following: Ended at 20050206-04:57:53 after 4 =item programFooter returns the input for pProgramFooter() =item pFileInfo ($debug, $filename, $message); calls msg() of the parent class with $debug and a string like the following: File created: 20050205-21:47:16 =item fileInfo ($filename, $message) returns the input for pFileInfo =back So, $log->pFileInfo (2, "file", "message"); is equivalent to $log->msg(2, $log->fileInfo ("file", "message")); =head1 AUTHOR holli