IOToolkit.pm

- NAME
- ABSTRACT
- PREREQUISITS
- SYNOPSIS
- DESCRIPTION

- IOToolkit::logme(``M'',``Message'')
- IOToolkit::moduleinfo
- IOToolkit::trim
- IOToolkit::hash2sql
- IOToolkit::encrypt and IOToolkit::decrypt

- EXPORT
- SEE ALSO
- AUTHOR
- COPYRIGHT AND LICENSE
- AMENDMENT HISTORY

# NAME

IOToolkit

# 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] <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.

# 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