Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Logging Singleton

by manorhce (Beadle)
on Feb 18, 2013 at 18:56 UTC ( #1019384=note: print w/replies, xml ) Need Help??

in reply to Logging Singleton

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

Replies are listed 'Best First'.
Re^2: Logging Singleton
by Anonymous Monk on Feb 18, 2013 at 19:23 UTC
    Thanks. I would have used log4perl but unfortunately working with older version of Perl.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019384]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2018-01-21 05:23 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.