The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Log4Perl::ImportHandle - Imports a Log4Perl handle with category

SYNOPSIS

 # Imports function LOG() to access category 'area1'
 use Log4Perl::ImportHandle LOG => 'area1'

 # Imports also function LOG2() to access category 'area2'
 Log4Perl::ImportHandle LOG => 'area1',LOG2 => 'area2

 # Imports function logger() to access category '' (default)
 use Log4Perl::ImportHandle logger

 # Imports function LOG() to access category '' (default)
 # LOG is the default function name.
 use Log4Perl::ImportHandle

 LOG->debug('hello');

DESCRIPTION

This class imports an easy to use Log4Perl handle to the current class. Instead of the not recommended way to use direct functions like DEBUG(), here you can define a category.

REQUIRES

Log::Log4perl

HOWTO

As the SYNOPSIS examples above, just 'use' the class and add maybe some parameters.

What is called a handler here, is just a function, that returns the same as get_logger() from Log4Perl.

no parameters - Sets the default handle 'LOG'.

one parameter - Sets the handle (function) name.

two parameters or pairs - first is the handlename and the second the category name. You can define many pairs.

WHY

Please have a look at the normal way to handle with Log4Perl:

 my $log = Log::Log4perl->get_logger('area1');
 $log->debug('hello');

For classes with some methods, that is not very nice to read and maintain. You will also need that lines in every method again.

With Log4Perl::ImportHandle it gets a bit smoother:

 use Log4Perl::ImportHandle

 LOG->debug('hello');

Once you called it in the header via 'use', you can easily access it with the default function 'LOG' or any other you defined.

AUTHOR

Andreas Hernitscheck ahernit(AT)cpan.org

LICENSE

You can redistribute it and/or modify it under the conditions of LGPL.