IOToolkit - Perl extension to create logfiles
Sample Script:
use strict; use warnings; use Getopt::Long; # processing command-line parameters use IOToolkit;
package main; use vars qw($getopt_loglevel $program $programname);
$program="logging"; $programname = $program.".pl"; my $logfilename = $program.".log"; my $version = "1.00"; my $description = "Logging-Sample";
GetOptions("loglevel=s" => \$getopt_loglevel);
if (not(defined($getopt_loglevel))) { print "$description ($programname)\n"; print "Usage: \n$programname\n --loglevel=EMCDQ\n\n"; die "You did not provide any parameters. The program ended here.\n\n"; }
logme("open",$logfilename); logme("D","$programname V$version started --------------------------------------------------"); logme("M","This is a MESSAGE"); logme("D","This is a DEBUG-MESSAGE"); logme("E","This is an ERROR-MESSAGE"); logme("Q","This is a SQL-QUERY-MESSAGE"); logme("C","This is a CONFIGURATION-MESSAGE"); logme("M","FATAL- and SYSTEM-MESSAGES (F/S) are always logged."); logme("M","If the loglevel parameter contains - no messages are displayed."); #logme("F","This is a FATAL-MESSAGE"); logme("D","$programname V$version ended --------------------------------------------------"); logme("close");
This displays and creates a logfile like this:
2004-09-09 10:23:57 [logging.pl] <D> logging.pl V1.00 started -------------------------------------------------- 2004-09-09 10:23:57 [logging.pl] <M> This is a MESSAGE 2004-09-09 10:23:57 [logging.pl] <D> This is a DEBUG-MESSAGE 2004-09-09 10:23:57 [logging.pl] <E> This is an ERROR-MESSAGE 2004-09-09 10:23:57 [logging.pl] <Q> This is a SQL-QUERY-MESSAGE 2004-09-09 10:23:57 [logging.pl] <C> This is a CONFIGURATION-MESSAGE 2004-09-09 10:23:57 [logging.pl] <M> FATAL- and SYSTEM-MESSAGES (F/S) are always logged. 2004-09-09 10:23:57 [logging.pl] <M> If the loglevel parameter contains - no messages are displayed. 2004-09-09 10:23:57 [logging.pl] <D> logging.pl V1.00 ended --------------------------------------------------
This module was written to provide an easy way to log messages. It checks for an option --loglevel=EMCDEQ- where each character stands for a certain level. e.g.
E=Error S=System M=Message D=Debug -=Silent
the minus (``-'') has a special meaning: supresses output to the screen and ONLY logs them to the file. Please see the sample script for more details.
logme and gettimestamp are exported.
Markus Linke, markus.linke@linke.de
Copyright 2004 by Markus Linke
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.