Hi It will be easy if you will follow to Log::Log4perl module which cpan provides
you can call the log method like Log->info($message)
Create a module Log.pm with using Log::Log4perl
BEGIN {
require Exporter;
push @ISA, qw(Exporter);
@EXPORT = ( @Data::Dumper::EXPORT, @Carp::EXPORT, qw($log get_logger);
$conf_file="path to log4perl.conf";
eval {
Log::Log4perl->init($conf_file);
}
if ($@) {
die "Cann't open the file" if ($@ =~ m/Permission/gi);
}
Log::Log4perl->get_logger("My::MegaPackage");
}
sub new {
my $class = shift;
return bless {}, $class;
}
sub info {
my ($self, $message) = @_;
my ($package, $filename, $line) = caller;
my $_log = Log::Log4perl->get_logger($packa
+ge);
$log->info($message) if ($log->is_info());
}
sub error {
my ($self, $message) = @_;
my ($package, $filename, $line) = caller;
my $_log = Log::Log4perl->get_logger($packa
+ge);
$log->error( longmess($message) ) if ($log->is_error());
}
sub debug {
my ($self, $message) = @_;
my ($package, $filename, $line) = caller;
my $_log = Log::Log4perl->get_logger($packa
+ge);
$log->debug($message) if ($log->is_debug());
}
and by using this module and calling get_logger() method your job will be easy
Please let me know if you are unclear on this and I will suggest to follow Log::Log4perl for better logging messages |