|
NAMEIO::ToolkitABSTRACTIO::Toolkit - Perl extension to create logfilesPREREQUISITSThis module needs Crypt::RC6 for its encryption/decryption routine. Digest::MD5 and DirHandle used for checksum routines.SYNOPSISSample Script (please also have a look into the samples directory):use IO::Toolkit; use File::Basename; package main; use vars qw($getopt_loglevel $program $programname); my $program = basename($0); $programname = $program; $programname =~ s/\.pl//g; my $logfilename = $programname . ".log"; my $VERSION = sprintf "%d.%05d", '$Revision: 8 $' =~ /(\d+)/g; my $description = "Script"; my $extra; my @extra_options = ( { Spec => "extra=s", Variable => \$extra, Help => "--extra=whatever", Verbose => ["--extra=whatever", "whatever whenever...", ] }, ); IO::Toolkit::commandline(@extra_options); logme("open", $logfilename); logme("M","$programname V$VERSION started --------------------------------------------------"); logme("C", "Logfile $logfilename used."); logme("M","$programname V$VERSION ended --------------------------------------------------"); logme("close"); This displays and creates a logfile like this: 2004-11-14 13:07:48 [mytemplate] <M> mytemplate V1.00004 started -------------------------------------------------- 2004-11-14 13:07:48 [mytemplate] <C> Logfile mytemplate.log used. 2004-11-14 13:07:48 [mytemplate] <M> mytemplate V1.00004 ended -------------------------------------------------- IMPORTANT NOTICEIf you are looking for a better logging-module, please check Log4Perl instead.DESCRIPTIONProvides 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 IO::Toolkit::logme("M","Message")The first parameter specifies the severity of the message. The message is only logged, if $getopt_loglevel contains that severity.Because IO::Toolkit::logme is exported, you can just use logme("M","message") in your scripts. IO::Toolkit::moduleinfoprints a list of loaded modules.IO::Toolkit::trimtrims a variable.IO::Toolkit::hash2sqlcreates SQL code to insert a hash into a table.Example: use IO::Toolkit; my %hash=( firstname=>"Markus", lastname=>"Linke", ); print IO::Toolkit::hash2sqlinsert("tablename",%hash)."\n"; Result: insert into tablename (firstname,lastname) values ("Markus","Linke") IO::Toolkit::sql2data executes SQL statement and creates a array of hashs use IO::Toolkit; use Data::Dumper; print Dumper(IO::Toolkit::sql2data($dbh,"select * from environments")); IO::Toolkit::encrypt and IO::Toolkit::decryptneeds two strings as parameters (e.g. seed and password) and returns an encrypted/decrypted value.IO::Toolkit::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 = IO::Toolkit::get_md5_checksum("Toolkit.pm");Create a MD5 checksum for the filename provided.EXPORTlogme and gettimestamp are exported.SEE ALSOhttp://www.linke.de for my personal homepage and http://trac.it-projects.com/iotoolkit for the project TRAC pages Please submit bugs at http://bugzilla.it-projects.com Hosted Subversion Version Control provided by http://svn.it-projects.com Checkout the latest version at https://svn.it-projects.com/svn/iotoolkit AUTHORMarkus Linke, markus.linke@linke.deCOPYRIGHT AND LICENSECopyright 2003-2006 by Markus LinkeThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |