NAME IOToolkit VERSION $Revision: 1.28 $ ABSTRACT IOToolkit - Perl extension to create logfiles PREREQUISITS This module needs Crypt::RC6 for its encryption/decryption routine. SYNOPSIS Sample Script: use strict; use warnings; use Getopt::Long; # processing command-line parameters use IOToolkit; package main; use vars qw($getopt_loglevel $program $programname); my $program = $0; # Script Name with path $program =~ m/\/(.+)/i; # Only the scriptname $programname = $1; $program =~ m/(.+)\.pl/i; # Without the extension $program = $1; my $logfilename = $program.".log"; my $VERSION = "1.00"; my $description = "Description goes here"; 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"); # uses a default filename scriptname.log in the same dir 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 which lets the program die"); logme("D","$programname V$VERSION ended --------------------------------------------------"); logme("close"); This displays and creates a logfile like this: 2004-09-09 10:23:57 [logging.pl] logging.pl V1.00 started -------------------------------------------------- 2004-09-09 10:23:57 [logging.pl] This is a MESSAGE 2004-09-09 10:23:57 [logging.pl] This is a DEBUG-MESSAGE 2004-09-09 10:23:57 [logging.pl] This is an ERROR-MESSAGE 2004-09-09 10:23:57 [logging.pl] This is a SQL-QUERY-MESSAGE 2004-09-09 10:23:57 [logging.pl] This is a CONFIGURATION-MESSAGE 2004-09-09 10:23:57 [logging.pl] FATAL- and SYSTEM-MESSAGES (F/S) are always logged. 2004-09-09 10:23:57 [logging.pl] If the loglevel parameter contains - no messages are displayed. 2004-09-09 10:23:57 [logging.pl] logging.pl V1.00 ended -------------------------------------------------- DESCRIPTION Provides a human-readable logfile and is ment to replace "print" and "die" in your programs. This module was written to provide an easy way to log messages. It checks for an option --loglevel=EMCDQ- where each character stands for a certain level. e.g. E = Error S = System M = Message D = Debug - = Silent all = All messages You can use all characters you would like to use. These are just examples. 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. The function gettimestamp returns the current time in the format used for the logfile. If you specifiy the format &gettimestamp("filename") it returns something like this: 20041009131500 IOToolkit::moduleinfo prints a list of loaded modules. IOToolkit::trim trims a variable. IOToolkit::hash2sql creates SQL code to insert a hash into a table. Example: use IOToolkit; my %hash=( firstname=>"Markus", lastname=>"Linke", ); print IOToolkit::hash2sqlinsert("tablename",%hash)."\n"; Result: insert into tablename (firstname,lastname) values ("Markus","Linke") IOToolkit::sql2data executes SQL statement and creates a array of hashs use IOToolkit; use Data::Dumper; print Dumper(IOToolkit::sql2data($dbh,"select * from environments")); IOToolkit::encrypt and IOToolkit::decrypt needs two strings as parameters (e.g. seed and password) and returns an encrypted/decrypted value. EXPORT logme and gettimestamp are exported. SEE ALSO http://www.linke.de for my personal homepage http://www.nmsalert.com for website monitoring solutions http://www.trackalizer.com for website visitor tracking and clickpath analysis AUTHOR Markus Linke, markus.linke@linke.de COPYRIGHT AND LICENSE Copyright 2003-2004 by Markus Linke This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AMENDMENT HISTORY $Log: /hfx/var/pvcs/Murex/archives/Tonys/IOToolkit.pm-arc $ # # Rev 1.28 29 Oct 2004 13:34:40 ml7tre # bugfix # # Rev 1.27 29 Oct 2004 13:33:00 ml7tre # gettimestamp updated (now uses POSIX) # # Rev 1.26 29 Oct 2004 12:33:58 ml7tre # minor changes # # Rev 1.25 29 Oct 2004 12:21:20 ml7tre # perltidy # # Rev 1.24 29 Oct 2004 12:00:06 ml7tre # decryption added # # Rev 1.23 29 Oct 2004 11:25:58 ml7tre # encryption added # # Rev 1.22 29 Oct 2004 09:34:58 ml7tre # sql2data fixed # # Rev 1.21 29 Oct 2004 08:01:14 ml7tre # pvcs change # # Rev 1.20 29 Oct 2004 07:59:30 ml7tre # Debugging Lines removed # # Rev 1.19 29 Oct 2004 07:52:28 ml7tre # version control changes