NAME
IOToolkit
ABSTRACT
IOToolkit - Perl extension to create logfiles
IMPORTANT NOTICE
The name of this module changed! All future versions will use the name IO::Toolkit
http://search.cpan.org/search%3fmodule=IO::Toolkit
PREREQUISITS
This module needs Crypt::RC6 for its encryption/decryption routine. Digest::MD5 and DirHandle used for checksum routines.
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] <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 --------------------------------------------------
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::logme("M","Message")
The first parameter specifies the severity of the message. The message is only logged, if $getopt_loglevel contains that severity.
Because IOToolkit::logme is exported, you can just use logme("M","message") in your scripts.
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.
IOToolkit::pid("exclusive|overwrite|remove","/tmp/filename.pid");
Create or delete PID file. If set to exclusive, the program dies if the file already exists.
my $md5 = IOToolkit::get_md5_checksum("IOToolkit.pm");
Create a MD5 checksum for the filename provided.
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
MAILING LIST
You can join the IOToolkit mailing list by sending an email to:
iotoolkit-l-subscribe-request@listserv.it-projects.com
Known Bugs
Please report bugs at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=iotoolkit
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.