> Hi
> 
> I need a GL::Logger wich implements Class::Singleton
> to be a singleton and Log::Log4perl to can log amy
> message into a file. Here is the module source:
> -------------------------------------------------------------------------
> package GL::Logger;
> 
> use Class::Singleton;
> use vars qw( $ERROR );
> @ISA = qw(Class::Singleton);
> use Log::Log4perl;
> my $ERROR = '';
> my $logger;
> 
> sub instance(){
>       my $class = shift;
>       my $self  = bless { }, $class;
>       Log::Log4perl::init('c:/log4perl/log4perl.conf');
>       unless (defined ($self->{ $logger } =
Log::Log4perl->get_logger('...'))) {


In the above line you are trying to use $logger (which is unassigned) as
a hash key. I suspect maybe you want $logger instead of $self->{$logger}
but I can't really tell.

>               $ERROR = "Cannot get configuration file (log4perl.conf)\n";
>               return undef;
>       }
>       $self;
> }
> 
> sub log(){

$logger has never been assigned, see above comment.  Just so you are
aware wrapping Log4perl like this breaks a lot of its nice features and
in the long run will reduce the flexibility that it offers, which is
disappointing since it is incredibly flexible/powerful. Log4perl already
implements a singleton 'logger' anyways, why not use it?

http://danconia.org

>       my($level, $msg) = @_;
>       if($level eq 'DEBUG'){
>               $logger->debug($msg);
>       }
>       if($level eq 'INFO'){
>               $logger->info($msg);
>       }
>       if($level eq 'WARN'){
>               $logger->warn($msg);
>       }
>       if($level eq 'ERROR'){
>               $logger->error($msg);
>       }
>       if($level eq 'FATAL'){
>               $logger->fatal($msg);
>       }
>       return 0;
> }
> 1;
> -------------------------------------------------------------------------
> 
> And this is the way how I want to use it:
> 
> -------------------------------------------------------------------------
> #!perl -w
> use GL::Logger;
> my $logger = GL::Logger->instance();
> $logger->log("ERROR", "blablabla");
> -------------------------------------------------------------------------
> 
> It retunr the following error message:
> 
> Use of uninitialized value in hash element at
c:/Perl/site/lib/GL/Logger.pm line 14.
> 
> What is wrong ?
> --------------------------------------------
> Laszlo Graf
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to