The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.




IOToolkit - Perl extension to create logfiles


The name of this module changed! All future versions will use the name IO::Toolkit


This module needs Crypt::RC6 for its encryption/decryption routine. Digest::MD5 and DirHandle used for checksum routines.


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("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   --------------------------------------------------");

This displays and creates a logfile like this:

    2004-09-09 10:23:57 [] <D> V1.00 started --------------------------------------------------
    2004-09-09 10:23:57 [] <M> This is a MESSAGE
    2004-09-09 10:23:57 [] <D> This is a DEBUG-MESSAGE
    2004-09-09 10:23:57 [] <E> This is an ERROR-MESSAGE
    2004-09-09 10:23:57 [] <Q> This is a SQL-QUERY-MESSAGE
    2004-09-09 10:23:57 [] <C> This is a CONFIGURATION-MESSAGE
    2004-09-09 10:23:57 [] <M> FATAL- and SYSTEM-MESSAGES (F/S) are always logged.
    2004-09-09 10:23:57 [] <M> If the loglevel parameter contains - no messages are displayed.
    2004-09-09 10:23:57 [] <D> V1.00 ended   --------------------------------------------------


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


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.


prints a list of loaded modules.


trims a variable.


creates SQL code to insert a hash into a table.


   use IOToolkit;

   my %hash=(

   print IOToolkit::hash2sqlinsert("tablename",%hash)."\n";


   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.


Create or delete PID file. If set to exclusive, the program dies if the file already exists.

my $md5 = IOToolkit::get_md5_checksum("");

Create a MD5 checksum for the filename provided.


logme and gettimestamp are exported.

SEE ALSO for my personal homepage for website monitoring solutions for website visitor tracking and clickpath analysis


You can join the IOToolkit mailing list by sending an email to:   

Known Bugs

Please report bugs at


Markus Linke,


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.