Toolkit.pm

- NAME
- ABSTRACT
- PREREQUISITS
- SYNOPSIS
- IMPORTANT NOTICE
- DESCRIPTION

- IO::Toolkit::logme(``M'',``Message'')
- IO::Toolkit::moduleinfo
- IO::Toolkit::trim
- IO::Toolkit::hash2sql
- IO::Toolkit::encrypt and IO::Toolkit::decrypt
- IO::Toolkit::pid(``exclusive|overwrite|remove'',``/tmp/filename.pid'');
- my $md5 = IO::Toolkit::get_md5_checksum(``Toolkit.pm'');

- EXPORT
- SEE ALSO
- COPYRIGHT AND LICENSE

# NAME

IO::Toolkit

# ABSTRACT

IO::Toolkit - Perl extension to create logfiles

# PREREQUISITS

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

# SYNOPSIS

Sample 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 NOTICE

If you are looking for a better logging-module, please check Log4Perl instead.

# 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

## 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::moduleinfo

prints a list of loaded modules.

## IO::Toolkit::trim

trims a variable.

## IO::Toolkit::hash2sql

creates 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::decrypt

needs 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.

# EXPORT

logme and gettimestamp are exported.

# SEE ALSO

       http://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

    =head1 AUTHOR

Markus Linke, markus.linke@linke.de

# COPYRIGHT AND LICENSE

Copyright 2003-2006 by Markus Linke

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.