Logger-Simple-2.0/0000755000202100020170000000000010442414553014300 5ustar tstanleytstanleyLogger-Simple-2.0/t/0000755000202100020170000000000010442414553014543 5ustar tstanleytstanleyLogger-Simple-2.0/t/02readwrite.t0000644000202100020170000000107110442406331017052 0ustar tstanleytstanleyuse Test::More tests=>4; use Logger::Simple; my $logfile="t/logfile2"; my $log=Logger::Simple->new(LOG=>$logfile); $log->write("Test"); ok(-s $logfile,'Writing to logfile'); my $MSG=$log->retrieve_history; ok($MSG eq "Test"); $log->write("Test2"); $log->write("Test3"); my @Msg=$log->retrieve_history; ok(scalar @Msg == 3); $log->clear_history; my @Msg2=$log->retrieve_history; ok(scalar @Msg2 == 0); undef $log; if($^O eq 'MSWin32'){ system "C:\\Windows\\System32\\cmd.exe \/c del t\\logfile2"; }else{ unlink $logfile; } Logger-Simple-2.0/t/01load.t0000644000202100020170000000073610442405420016007 0ustar tstanleytstanley# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl Logger2-Simple.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 1; BEGIN { use_ok('Logger::Simple') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. Logger-Simple-2.0/t/04pod.t0000644000202100020170000000022510442406430015650 0ustar tstanleytstanleyeval "use Test::Pod tests => 1"; if($@){ print"Test::Pod must be installed to test POD\n"; exit; } pod_file_ok("Simple.pm","POD looks good"); Logger-Simple-2.0/t/03lock.t0000644000202100020170000000100410442406340016011 0ustar tstanleytstanleyuse Test::More; use Logger::Simple; if($^O eq "MSWin32"){ plan( skip_all => 'File Locking not working on MS Windows' ); }else{ plan (tests => 2); $logfile="t/logfile3"; $logger=Logger::Simple->new(LOG=>$logfile); $logger->lock; ok(-e ".LS.lock",'Lock file created'); $logger->unlock; ok(!-e ".LS.lock",'Lock file destroyed'); undef $logger; if($^O eq 'MSWin32'){ system "C:\\Windows\\System32\\cmd.exe \/c del t\\logfile3"; }else{ unlink $logfile; } } Logger-Simple-2.0/README0000644000202100020170000000435710442414437015172 0ustar tstanleytstanleyNAME Logger::Simple - Implementation of the Simran-Log-Log and Simran-Error-Error modules SYNOPSIS use Logger::Simple; my $log=Logger::Simple->new(LOG=>"/tmp/program.log"); my $x=5;my $y=4; if($x>$y){ $log->write("\$x is greater than \$y"); } DESCRIPTION new "my $log=Logger::Simple->new(LOG=>"/tmp/logfile");" The new method creates the Logger::Simple object as an inside-out object. The Log parameter is a mandatory one that must be passed to the object at creation, or the object will fail. Upon creation, this method will also call the open_log method which opens the log file. write "$log->write("This is an error message");" This method will write a message to the logfile, and will update the internal HISTORY array. retrieve_history "my @history = $log->retrieve_history;" "my $msg = $log->retrieve_history;" When called in scalar context, it will return the last message written to the HISTORY array. When called in a list context, it will return the entire HISTORY array clear_history "$log->clear_history;" This method will clear the internal HISTORY array EXPORT None by default. ACKNOWLEDGEMENTS This module is based on the Simran::Log::Log and Simran::Error::Error modules. I liked the principle behind them, but felt that the interface could be a bit better. My thanks also goes out once again to Damian Conway for Object Oriented Perl, and also to Sam Tregar, for his book "Writing Perl Modules for CPAN". Both were invaluable references for me. I would also like to thank Jerry Heden for his Object::InsideOut module, which I used to create this module. AUTHOR Thomas Stanley Thomas_J_Stanley@msn.com I can also be found on http://www.perlmonks.org as TStanley. You can also direct any questions concerning this module there as well. COPYRIGHT Copyright (C) 2002-2006 Thomas Stanley. All rights reserved. This program is free software; you can distribute it and/or modify it under the same terms as Perl itself. SEE ALSO perl(1). Object::InsideOut Simran::Log::Log Simran::Error::Error Logger-Simple-2.0/Changes0000644000202100020170000000414710442407041015573 0ustar tstanleytstanleyRevision history for Perl extension Logger::Simple 1.00 Tue Nov 19 15:48:15 2002 - original version; created by h2xs 1.20 with options -AXn Logger::Simple - combined functions of Simran::Log::Log and Simran::Error::Error into one module. - Redesigned POD to reflect changes - Implemented object as a blessed hash - Added tests 1.01 Wed Nov 20 13:44:39 2002 - Completed the POD Documentation 1.02 Tue Dec 17 11:40:11 2002 - Changed the set method, so that upon setting an error message, it would also write it to the log file - Made changes in POD to reflect the change in the set method 1.03 Tue Feb 4 14:57:26 2003 - Implemented file locking on the logfile using the Fcntl module - Added the lock and unlock functions, which are called by the write() function 1.04 Tue Mar 11 11:19:35 2003 - Re-implemented the file locking on the log file - Added an internal variable for a semaphore flag file - Added the wait function, which will sleep for 1 second if the semaphore file is present - Added to the pod - Corrected a problem within the formatting, so that it will now format properly - Added a special HTML copyright section to display the copyright symbol 1.05 Tue Mar 11 14:46:02 2003 - Included the Time::HiRes module to provide for a more granular sleep in the wait function 1.06 Wed Oct 29 12:30:53 2003 - Re-implemented the tests using the Test::More module 1.07 Fri Mar 5 08:29:12 2004 - Added new method to get the name of the logfile 1.08 Fri Dec 10 10:40:02 2004 - Edited the lock,unlock, and write functions to work with MS-Win32. This was a reported bug from CPAN Testers 1.081 Mon Jan 10 09:43:13 2005 - Reaccomplished the tests using Test::Harness and added a test for the POD using Test::Pod 1.09 Sat Apr 1 17:26:19 2006 - Edited the lock & unlock functions to be ignored when operating on MS-Win32. Rewrote the tests so that they are skipped on Win32 systems. 1.091 Sun Apr 2 09:46:13 2006 - Added the README file 2.0 Fri Jun 9 20:09:55 2006 - Complete rewrite of module to include the use of the Object::InsideOut module Logger-Simple-2.0/Simple.pm0000644000202100020170000001202410442413711016061 0ustar tstanleytstanleypackage Logger::Simple; { use strict; use Carp; use FileHandle; use Fcntl qw(:flock); use Time::HiRes qw/usleep/; use vars qw /$VERSION $SEM $ms $SEMAPHORE $FILEHANDLE @HISTORY/; use Object::InsideOut; $ms=750_000; $VERSION='2.0'; $SEM = ".LS.lock"; $SEMAPHORE=new FileHandle; $FILEHANDLE=new FileHandle; @HISTORY=(); my @Log :Field('Standard'=>'Log','Type'=>'LIST'); my @FileHandle :Field('Standard'=>'FileHandle','Type'=>'SCALAR'); my @Semaphore :Field('Standard'=>'Semaphore','Type'=>'SCALAR'); my @Error :Field('Standard'=>'Error','Type'=>'LIST'); my %init_args :InitArgs=( 'Log'=>{ 'Regex' => qr/^Log$/i, 'Mandatory' => 1, }, ); sub _init :Init{ my($self,$args)= @_; if(exists($args->{'Log'})){ $self->set(\@Log,$args->{'Log'}); } $self->set(\@FileHandle,$FILEHANDLE); $self->set(\@Semaphore,$SEMAPHORE); $self->open_log; } sub open_log{ my $self=shift; my $FH=$self->get_FileHandle; my $Log=$self->get_Log; if(! open($FH,">>$Log")){ $self->write_error("Unable to open logfile\n"); return 0; } $FH->autoflush(1); return 1; } sub write{ my($self,$msg)=@_; my $FH=$self->get_FileHandle; my $format="$0 : [".scalar (localtime)."] $msg"; ## Fix to ignore locking on Win32 if($^O eq "MSWin32"){}else{ $self->lock(); } if(! print $FH "$format\n"){ croak "Unable to write to log file: $!\n"; } if($^O eq "MSWin32"){}else{ $self->unlock(); } $self->update_history($msg); } sub update_history{ my($self,$msg)=@_; push @HISTORY,$msg; } sub retrieve_history{ my $self=shift; if(wantarray){ return @HISTORY; }else{ my $message=$HISTORY[$#HISTORY]; return $message; } } sub lock{ my $self=shift; if($^O eq "MSWin32"){ return 1; } my $SM=$self->get_Semaphore; open $SM,">$SEM"||die"Can't create lock file: $!\n"; flock($SM,LOCK_EX) or die"Can't obtain file lock: $!\n"; } sub unlock{ my $self=shift; my $SM=$self->get_Semaphore; if(-e $SEM){ flock($SM,LOCK_UN); close $SM; $SM->autoflush(1); if($^O eq "MSWin32"){ system "C:\\Windows\\System32\\cmd.exe \/c del $SEM"; }else{ unlink $SEM; } } } sub wait{ while(-e $SEM){ usleep $ms; } } sub clear_history{ my $self=shift; @HISTORY=(); } } 1; __END__ =head1 NAME Logger::Simple - Implementation of the Simran-Log-Log and Simran-Error-Error modules =head1 SYNOPSIS use Logger::Simple; my $log=Logger::Simple->new(LOG=>"/tmp/program.log"); my $x=5;my $y=4; if($x>$y){ $log->write("\$x is greater than \$y"); } =head1 DESCRIPTION =over 5 =item new C<< my $log=Logger::Simple->new(LOG=>"/tmp/logfile"); >> The new method creates the Logger::Simple object as an inside-out object. The Log parameter is a mandatory one that must be passed to the object at creation, or the object will fail. Upon creation, this method will also call the open_log method which opens the log file. =item write C<< $log->write("This is an error message"); >> This method will write a message to the logfile, and will update the internal HISTORY array. =item retrieve_history C<< my @history = $log->retrieve_history; >> C<< my $msg = $log->retrieve_history; >> When called in scalar context, it will return the last message written to the HISTORY array. When called in a list context, it will return the entire HISTORY array =item clear_history C<< $log->clear_history; >> This method will clear the internal HISTORY array =back =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS This module is based on the Simran::Log::Log and Simran::Error::Error modules. I liked the principle behind them, but felt that the interface could be a bit better. My thanks also goes out once again to Damian Conway for Object Oriented Perl, and also to Sam Tregar, for his book "Writing Perl Modules for CPAN". Both were invaluable references for me. I would also like to thank Jerry Heden for his Object::InsideOut module, which I used to create this module. =head1 AUTHOR Thomas Stanley Thomas_J_Stanley@msn.com I can also be found on http://www.perlmonks.org as TStanley. You can also direct any questions concerning this module there as well. =head1 COPYRIGHT =begin text Copyright (C) 2002-2006 Thomas Stanley. All rights reserved. This program is free software; you can distribute it and/or modify it under the same terms as Perl itself. =end text =begin html Copyright E 2002-2006 Thomas Stanley. All rights reserved. This program is free software; you can distribute it and/or modify it under the same terms as Perl itself. =end html =head1 SEE ALSO perl(1). Object::InsideOut Simran::Log::Log Simran::Error::Error =cut Logger-Simple-2.0/Makefile.PL0000644000202100020170000000101510442405633016246 0ustar tstanleytstanleyuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Logger::Simple', 'VERSION_FROM' => 'Simple.pm', # finds $VERSION 'PREREQ_PM' => {Carp => 0, FileHandle => 0, Fcntl => 0, Time::HiRes => 0, Test::More => 0, Test::Harness => 0, Test::Pod => 0, Object::InsideOut => 0, }, # e.g., Module::Name => 1.1 ); Logger-Simple-2.0/META.yml0000644000202100020170000000112210442414553015545 0ustar tstanleytstanley# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Logger-Simple version: 2.0 version_from: Simple.pm installdirs: site requires: Carp: 0 Fcntl: 0 FileHandle: 0 Object::InsideOut: 0 Test::Harness: 0 Test::More: 0 Test::Pod: 0 Time::HiRes: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30 Logger-Simple-2.0/MANIFEST0000644000202100020170000000014710413752634015436 0ustar tstanleytstanleyMETA.yml Changes Simple.pm MANIFEST README Makefile.PL t/01load.t t/02readwrite.t t/03lock.t t/04pod.t