Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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


Comment on Re: Logging Singleton
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019384]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-10-01 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (29 votes), past polls