Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2015-07-05 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls